|
From: Jean-Marc V.
|
Hi,
I'm attaching a program that demonstrates the problem. When I compile
with -O0 or -O1, there's no problem, but with -O2 and above, I get:
% /opt/valgrind-2.2/bin/valgrind --tool=3Dmemcheck ./val
=3D=3D9257=3D=3D Memcheck, a memory error detector for x86-linux.
=3D=3D9257=3D=3D Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward=
et al.
=3D=3D9257=3D=3D Using valgrind-2.2.0, a program supervision framework fo=
r
x86-linux.
=3D=3D9257=3D=3D Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward=
et al.
=3D=3D9257=3D=3D For more details, rerun with: -v
=3D=3D9257=3D=3D
=3D=3D9257=3D=3D Use of uninitialised value of size 4
=3D=3D9257=3D=3D at 0x8048419: main (in /home/jm/val)
=3D=3D9257=3D=3D
=3D=3D9257=3D=3D Use of uninitialised value of size 4
=3D=3D9257=3D=3D at 0x8048490: main (in /home/jm/val)
0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000
8.000000 9.000000
=3D=3D9257=3D=3D
=3D=3D9257=3D=3D ERROR SUMMARY: 9 errors from 2 contexts (suppressed: 11 =
from 1)
=3D=3D9257=3D=3D malloc/free: in use at exit: 0 bytes in 0 blocks.
=3D=3D9257=3D=3D malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
=3D=3D9257=3D=3D For a detailed leak analysis, rerun with: --leak-check=3D=
yes
=3D=3D9257=3D=3D For counts of detected errors, rerun with: -v
Jean-Marc
P.S. I'm not on the list, so please CC to me.
Le jeudi 03 mars 2005 =E0 04:22 -0500, Jean-Marc Valin a =E9crit :
> Hi,
>=20
> I have the following code, for which valgrind reports an error, althoug=
h
> it is perfectly valid:
>=20
> used=3D0;
> if (i<N || dist<best_dist[N-1])
> {
> //Error reported=20
> for (k=3DN-1; (k >=3D 1) && (k > used || dist < best_dist[k-1]); k--=
)
> {
> best_dist[k]=3Dbest_dist[k-1];
> nbest[k] =3D nbest[k-1];
> }
> best_dist[k]=3Ddist;
> nbest[k]=3Di;
> used++;
> }
>=20
> what seems to be causing the problem is that best_dist is not
> initialized. However initialization should not be necessary because the
> part before the ||
>=20
> Jean-Marc
--=20
Jean-Marc Valin <Jean-Marc.Valin@USherbrooke.ca>
Universite de Sherbrooke
|