This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: a.out gives different results when compiled by g++ 3.1 and g++ 3.1 -O
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- To: Erick Alphonse <alphonse at lri dot fr>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jun 2002 19:10:27 +0200
- Subject: Re: a.out gives different results when compiled by g++ 3.1 and g++ 3.1 -O
- References: <87bsac6y2s.fsf@student.uni-tuebingen.de> <3D0CC9DD.70200@lri.fr>
Erick Alphonse <alphonse@lri.fr> writes:
> Falk Hueffner wrote:
>
> >> enum {N = 624, // length of state vector
> >> M = 397, // period parameter
> >> MAGIC = 0x9908B0DFU}; // magic constant
> >>
> >> ui32 state[N]; // internal state
> >>[...]
> >>*p++ = twist( p[M-N], p[0], p[1] );
> >>
> > You're accessing out of the array bounds here, so anything might
> > happen.
>
> I can't see the problem, the for-loop is entered N-1 times. Valgrind
> reported nothing wrong.
MAGIC = 0x9908B0DFU forces the enum to become unsigned, therefore M-N
is done with unsigned arithmetic and you're accessing p[4294967069].
--
Falk