Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some minor undefined behaviours #1810

Merged
merged 3 commits into from
Jul 18, 2024
Merged

Commits on Jul 18, 2024

  1. Remove undefined behavior in expression language.

    The bit-wise AND, OR and XOR logic works on the overloaded double
    (res->d), but casting this to int64_t for NAN is undefined behaviour.
    
    Infact the current cast doesn't even yield the correct bit-wise layout
    for NAN, as (long)d and *(long *)&d give different results for d==NAN.
    However the result wasn't used anyway as it's promptly cleared again
    in the subsequent `if (undef) hts_expr_val_undef(res)` code.  Hence
    undefined or otherwise, it made no difference.
    jkbonfield committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    f6bec84 View commit details
    Browse the repository at this point in the history
  2. Fix signed overflow for hts_parse_decimal.

    Obviously there can still be overflows if we attempt to parse numbers
    which are too big, but for the legally accepted range of this, parsing
    "-9,223,372,036,854,775,808" as tested in test/sam.c triggered a
    problem as the positive version doesn't fit in "long long".
    
    We parse as unsigned and only switch to signed via the implicit return
    type conversion (and probably exploiting twos-complement, but that's a
    fair assumption).
    jkbonfield committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    c19fed3 View commit details
    Browse the repository at this point in the history
  3. Fix an undefined addition to a NULL pointer in vcf_format.

    The pointer was never used, but the NULL+0 still triggers clang's ubsan.
    jkbonfield committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    63ad6c1 View commit details
    Browse the repository at this point in the history