|
From: Bill T. <Bil...@ny...> - 2007-05-24 16:06:15
|
It appears that valgrind does not detect uninitialised values in boolean expressions. I recently came across a problem with code similar to: int x; // uninit bool y =3D (x =3D=3D 0); // uninit value not flagged The value of "y" was correctly flagged as uninitialised at assignment time and its use detected later in the program, but the use of the uninitialised value of x was not. I assume that the reason the original expression did not raise a warning is that the compiler generated code to compute the boolean expression that did not use a condititional jump. Does this sound right? Are there other similar constructs that valgrind is unable to flag, or does it depend on the code generated by the compiler? Any workarounds? TIA. |
|
From: Tom H. <to...@co...> - 2007-05-24 16:19:34
|
In message <92A...@st...>
Bill Torpey <Bil...@ny...> wrote:
> It appears that valgrind does not detect uninitialised values in boolean
> expressions. I recently came across a problem with code similar to:
>
> int x; // uninit
> bool y = (x == 0); // uninit value not flagged
>
> The value of "y" was correctly flagged as uninitialised at assignment
> time and its use detected later in the program, but the use of the
> uninitialised value of x was not. I assume that the reason the original
> expression did not raise a warning is that the compiler generated code
> to compute the boolean expression that did not use a condititional jump.
> Does this sound right? Are there other similar constructs that valgrind
> is unable to flag, or does it depend on the code generated by the
> compiler? Any workarounds?
The point is that you haven't yet used an uninitialised value in a way
that will affect the execution of your program.
Valgrind will only complain when (a) you make a conditional jump based
on uninitialised data or (b) you try and dereference an uninitialised
pointer.
So when you try and use x (or y) in such a way you will get told about
it, but not just because you assigned an uninitialised value to a
variable.
Tom
--
Tom Hughes (to...@co...)
http://www.compton.nu/
|
|
From: Nicholas N. <nj...@cs...> - 2007-05-24 22:29:17
|
On Thu, 24 May 2007, Tom Hughes wrote: > Valgrind will only complain when (a) you make a conditional jump based > on uninitialised data or (b) you try and dereference an uninitialised > pointer. Or (c) if you pass an uninitialised value to a system call, or (d) make a jump with an uninitialised target value. Nick |