Skip to content

Signed integer overflow & underflow are undefined #328

@Midar

Description

@Midar

The spec says that QOI_OP_DIFF and QOI_OP_LUMA wrap around. However, the reference implementation seems to use signed char for this. But the C standard says that overflow and underflow of signed integers are undefined.

GCC has -fwrapv to allow signed integers overflow and underflow, however, that's not portable.

My own implementation solves this like this: https://git.nil.im/ObjFW/ObjFW/src/commit/b6ec6d21d4997e4aae1030533115103ca5c49466/src/OFQOIImageFormatHandler.m#L131-L175

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions