Signedness in mpz_size
andreas.enge at inria.fr
Tue Aug 31 20:36:31 CEST 2010
when compiling a program using gmp-5.0.1 with the gcc warning flag '-Wconversion',
I obtain the following warning:
/usr/local/gmp-5.0.1/include/gmp.h: In function ‘__gmpz_size’:
/usr/local/gmp-5.0.1/include/gmp.h:1842: error: conversion to ‘size_t’ from ‘int’ may change the sign of the result
The problem is that the macro __GMP_ABS (__gmp_z->_mp_size) does not cast
the signed int of its argument into the unsigned result type, and the
compiler cannot know that the result is never negative.
I suggest to add an explicit cast (size_t) (__GMP_ABS (__gmp_z->_mp_size)),
which makes the warning disappear.
More information about the gmp-bugs