PATCH: Bad signed int to long long conversion

Marc Glisse marc.glisse at inria.fr
Thu Dec 1 07:30:20 CET 2011


On Wed, 30 Nov 2011, H.J. Lu wrote:

> According to
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50066
>
> vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
>
> is undefined when val is LONG_MIN.  The enclosed patch
> fixes it.

(I don't think 4.3 is developed anymore, but that code hasn't changed)

I assume this code in gmpxx.h is wrong too? Is there any compiler flag 
that detects those?

     if (mpz_fits_slong_p(w))
       mpz_set_si(z, l / mpz_get_si(w));
     else
       {
         /* if w is bigger than a long then the quotient must be zero, 
unless
            l==LONG_MIN and w==-LONG_MIN in which case the quotient is -1 
*/
         mpz_set_si (z, (mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? -1 : 
0));
       }


-- 
Marc Glisse


More information about the gmp-bugs mailing list