creachadair / imath

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

Fix undefined behaviour in case v==SMALL_MIN #15

Closed Meinersbur closed 7 years ago

Meinersbur commented 7 years ago

Negating a signed integer is undefined behaviour if it has the minimum value (as it cannot be represented in the integer of the that bit-size). Solution: Use unsigned negation.

See http://stackoverflow.com/questions/17313579/is-there-a-safe-way-to-get-the-unsigned-absolute-value-of-a-signed-integer-with

Meinersbur commented 7 years ago

Thank you.