creachadair / imath

Arbitrary precision integer and rational arithmetic library
Other
129 stars 20 forks source link

Fix undefined signed operations #18

Closed Meinersbur closed 7 years ago

Meinersbur commented 7 years ago

Some operations are defined only unsigned integers because they mess with the signed bit.

Found using undefined behavior sanitizer on Polly.

Reported by Matthias Krüger matthias.krueger@famsik.de https://bugs.llvm.org/show_bug.cgi?id=33197

Meinersbur commented 7 years ago

Thank you

matthiaskrgr commented 7 years ago

Thanks everyone :)

dcurrie commented 6 years ago

Re: patch fb8b597, converting from unsigned to signed is implementation defined behavior in the case this patch is trying to fix. See "6.3.1.3 Signed and unsigned integers" in the C99 standard. The only portable way to do this is to explicitly check for (mp_usmall )MP_SMALL_MIN.

dcurrie commented 6 years ago

Re: 8465147, it looks like d was dropped from while (1u << (mp_digit)(MP_DIGIT_BIT - 1))) -- how will this loop terminate? A better solution is while (d < ((mp_digit )1u << (MP_DIGIT_BIT - 1)))