Skip to content

Undefined behavior in PACKEDANCESTRYMAP hash code #113

@chrchang

Description

@chrchang

The hasharr and hashit functions in src/admutils.c, which are used to compute the .snp / .ind hash values stored in the PACKEDANCESTRYMAP header, use signed integers that usually overflow in the middle of the computation. While unsigned-integer overflow is defined to "wrap around" in C, signed-integer overflow is "undefined behavior": compilers are allowed to assume signed-integer overflow never happens, and generate code that is correct in the no-overflow case but does weird things on overflow.

I'm guessing no existing compiler has actually done anything weird here, but it would be good to eliminate the possibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions