Test whether unsigned number is < 0

Nicolas Roeser nicolas.roeser at uni-ulm.de
Sat Feb 23 17:24:30 CET 2013


Dear GMP hackers,

I found a problem in mpz/mul_i.h: at the end of the function:
  SIZ(prod) = ((sign_product < 0) ^ (small_mult < 0)) ? -size : size;

small_mult has been defined to an unsigned long int earlier in this file:
  MULTIPLICAND_UNSIGNED long int small_mult
(if the preprocessor macro OPERATION_mul_ui is defined).

The problem is that an unsigned number is always >=0, so the test
(small_mult < 0) always evaluates to 0. When compiling GMP with
gcc-4.7.2 and -Werror=type-limits, the build breaks there.

The code is present in all GMP versions that I checked, including 4.2.1,
5.1.1 and the current tip of the unstable ‘gmp’ repository[0].


[0] http://gmplib.org:8000/gmp/file/95b5c2d991c8/mpz/mul_i.h


Regards
-- 
Nico


More information about the gmp-bugs mailing list