Discussion:
[Valgrind-developers] confusing Memcheck message: Uninitialised value was created by a stack allocation
Konstantin Serebryany
2009-05-18 08:11:05 UTC
Permalink
Hello Memcheckers,

I've got a complain from a novice memcheck user about a confusing message:

% cat stack_uninit.c
int main() {
int unrelated[100];
// ...
int uninited[10];
return uninited[3] ? 1 : 0;
}
% ~/valgrind/trunk/Inst/bin/valgrind -q --track-origins=yes ./a.out
==25539== Syscall param exit_group(status) contains uninitialised byte(s)
...
==25539== Uninitialised value was created by a stack allocation
==25539== at 0x4004B0: main (stack_uninit.c:1)

The stack 'main (stack_uninit.c:1)' points to the beginning of the
function's code .
Is it possible to get the exact line where the uninitialized stack
object was created (line 4 instead of line 1)?

If this is hard or impossible, could you change the message text to
make it less confusing?
Something like: 'Uninitialised value was created by a stack allocation
at or after this point:'.

Thanks,

--kcc
Nicholas Nethercote
2009-05-18 22:29:34 UTC
Permalink
On Mon, May 18, 2009 at 6:11 PM, Konstantin Serebryany
Post by Konstantin Serebryany
Hello Memcheckers,
% cat  stack_uninit.c
int main() {
 int unrelated[100];
 // ...
 int uninited[10];
 return uninited[3] ? 1 : 0;
}
% ~/valgrind/trunk/Inst/bin/valgrind -q --track-origins=yes  ./a.out
==25539== Syscall param exit_group(status) contains uninitialised byte(s)
...
==25539==  Uninitialised value was created by a stack allocation
==25539==    at 0x4004B0: main (stack_uninit.c:1)
The stack 'main (stack_uninit.c:1)' points to the beginning of the
function's code .
Is it possible to get the exact line where the uninitialized stack
object was created (line 4 instead of line 1)?
If this is hard or impossible, could you change the message text to
make it less confusing?
Something like: 'Uninitialised value was created by a stack allocation
at or after this point:'.
I think the current behaviour is reasonable. The stack memory is
allocated upon entry to the function; if you have more than one stack
variable they will be allocated all at once, not one at a time.
Because of this, the debug info, which Valgrind relies on, identifies
the stack allocation with the opening brace of the function, which is
often on its own line but in your example is on the same line as the
declaration for main().

N
Konstantin Serebryany
2009-05-19 08:58:22 UTC
Permalink
On Tue, May 19, 2009 at 2:29 AM, Nicholas Nethercote
Post by Nicholas Nethercote
On Mon, May 18, 2009 at 6:11 PM, Konstantin Serebryany
Post by Konstantin Serebryany
Hello Memcheckers,
% cat  stack_uninit.c
int main() {
 int unrelated[100];
 // ...
 int uninited[10];
 return uninited[3] ? 1 : 0;
}
% ~/valgrind/trunk/Inst/bin/valgrind -q --track-origins=yes  ./a.out
==25539== Syscall param exit_group(status) contains uninitialised byte(s)
...
==25539==  Uninitialised value was created by a stack allocation
==25539==    at 0x4004B0: main (stack_uninit.c:1)
The stack 'main (stack_uninit.c:1)' points to the beginning of the
function's code .
Is it possible to get the exact line where the uninitialized stack
object was created (line 4 instead of line 1)?
If this is hard or impossible, could you change the message text to
make it less confusing?
Something like: 'Uninitialised value was created by a stack allocation
at or after this point:'.
I think the current behaviour is reasonable.  The stack memory is
allocated upon entry to the function;  if you have more than one stack
variable they will be allocated all at once, not one at a time.
Because of this, the debug info, which Valgrind relies on, identifies
the stack allocation with the opening brace of the function, which is
often on its own line but in your example is on the same line as the
declaration for main().
That is right. But not every memcheck user understands that.
I just suggested to make the report phrase a bit more descriptive.

Thanks,

--kcc
Post by Nicholas Nethercote
N
Nicholas Nethercote
2009-05-20 02:04:26 UTC
Permalink
On Tue, May 19, 2009 at 6:58 PM, Konstantin Serebryany
Post by Konstantin Serebryany
Post by Nicholas Nethercote
I think the current behaviour is reasonable.  The stack memory is
allocated upon entry to the function;  if you have more than one stack
variable they will be allocated all at once, not one at a time.
Because of this, the debug info, which Valgrind relies on, identifies
the stack allocation with the opening brace of the function, which is
often on its own line but in your example is on the same line as the
declaration for main().
That is right. But not every memcheck user understands that.
I just suggested to make the report phrase a bit more descriptive.
I would be reluctant to make an accurate message less accurate in
order to address a user's lack of knowledge about how stack frames
work.

Nick

Loading...