bug-gmp
[Top][All Lists]
Advanced

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

Re: Reading uninitialized memory


From: Andrew Vaught
Subject: Re: Reading uninitialized memory
Date: Fri, 25 Jan 2002 10:29:30 -0700 (MST)

On 25 Jan 2002, Torbjorn Granlund wrote:

> Andrew Vaught <address@hidden> writes:
> 
>      I'm guessing that zero is stored without limbs and that
>   mpz_get_si() always reads whatever passes for a non-limb.  The value
>   read from uninitialized memory is not used and doesn't affect the
>   value of zero, but you could get rid of a read and the spurious
>   error message from this and other bounds-checking programs.
> 
> Your analysis is correct.

   Here is a simple patch to avoid the problem:


*** get_si.c.orig       Fri Jan 25 17:53:26 2002
--- get_si.c    Fri Jan 25 17:54:49 2002
***************
*** 26,38 ****
  mpz_get_si (mpz_srcptr op)
  {
    mp_size_t size = op->_mp_size;
-   mp_limb_t low_limb = op->_mp_d[0];

    if (size > 0)
!     return (long) low_limb & LONG_MAX;
    else if (size < 0)
      /* This expression is necessary to properly handle 0x80000000 */
!     return ~(((long) low_limb - 1L) & LONG_MAX);
    else
      return 0;
  }
--- 26,37 ----
  mpz_get_si (mpz_srcptr op)
  {
    mp_size_t size = op->_mp_size;

    if (size > 0)
!     return (long) op->_mp_d[0] & LONG_MAX;
    else if (size < 0)
      /* This expression is necessary to properly handle 0x80000000 */
!     return ~(((long) op->_mp_d[0] - 1L) & LONG_MAX);
    else
      return 0;
  }


       Andy 

-----------------                        XOLD(K,IC,I)=
Andy Vaught               ....        DO ITERS=1, 10  XOLD(K,IC,I)
address@hidden     |  |   /CALLMSOLVE(A,B,X,I,ITERS,TOL)+(RANNYU(0)
Arizona State University  ======|WRITE(6,'(I5,2X,F12.6)')ITERS,TOL -HALF)
Tempe, Arizona USA        OOOOOO \ENDDORETURN PARAMETER(ZERO=1.D0)*TENTH*DELTA




reply via email to

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