bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Missing return in unsigned long mpz_get_ui ?


From: Kevin Ryde
Subject: Re: Missing return in unsigned long mpz_get_ui ?
Date: Sat, 13 Jul 2002 09:16:10 +1000
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.1 (i386-debian-linux-gnu)

"Krzysztof Kozminski" <address@hidden> writes:
>
> it appears that a random result may be returned whenever the 'if'
> condition is false.  Even if the condition is always true whenver
> GMP_NAIL_BITS == 0,

That's the case, ULONG_MAX > NUMB_MAX will only be when nails!=0.

> I see
> that you're trying to shut up compiler warnings, so perhaps adding extra
> #ifdef as below would be appropriate:

That might remove any doubt.  Separating nails==0 and nails!=0
entirely might make it clearer too.

> unsigned long
> mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW
> {
>   mp_ptr __gmp_p = __gmp_z->_mp_d;
>   mp_size_t __gmp_n = __gmp_z->_mp_size;
>   mp_limb_t __gmp_l = __gmp_p[0];
> #if GMP_NAIL_BITS != 0                      // <<<<<<<<<< ADDED BY KK
>   if (__GMP_ULONG_MAX <= GMP_NUMB_MASK)
> #endif                                      // <<<<<<<<<< ADDED BY KK
>     return __gmp_l & (-(mp_limb_t) (__gmp_n != 0));
> #if GMP_NAIL_BITS != 0  /* redundant #if, shuts up compiler warnings */
>   else                  /* happens for nails, but not if LONG_LONG_LIMB */
>     {                   /* assume two limbs are enough to fill an ulong */
>       __gmp_n = __GMP_ABS (__gmp_n);
>       if (__gmp_n <= 1)
>         return __gmp_l & (-(mp_limb_t) (__gmp_n != 0));
>       else
>         return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS);
>     }
> #endif
> }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]