|
From: RAMPARANY F. FTRD/DIH/G. <fan...@fr...> - 2004-03-24 08:43:25
|
Does valgrind detect illegal access to statically allocated memory? e.g. valgrind doesn't report any error on the following code: ... int mytable[5]; ... mytable[6] =3D mytable[7]; ... |
|
From: Tom H. <th...@cy...> - 2004-03-24 08:53:48
|
In message <429...@ft...>
RAMPARANY Fano <fan...@fr...> wrote:
> Does valgrind detect illegal access to statically allocated memory?
>
> e.g. valgrind doesn't report any error on the following code:
>
> ...
> int mytable[5];
> ...
> mytable[6] = mytable[7];
> ...
That isn't statically allocated, it's allocated on the stack.
In general valgrind will not be able to detect stack overruns like
this. Although it will warn about the use of uninitialised values from
the stack, any value above the current stack point is considered
accessible and therefore writable.
It is in fact virtually impossible to spot the kind of error you show
with a purely run time instrumenter, as you would normally need to add
padding between the variables at compile time to detect the overruns.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Henrik N. <hn...@ma...> - 2004-03-24 09:17:07
|
On Wed, 24 Mar 2004, RAMPARANY Fano FTRD/DIH/GRE wrote: > Does valgrind detect illegal access to statically allocated memory? Only if you pad the variable with inaccessible data. Normally the compiler packs static variables together in the data segment, so valgrin can not detect such misuse as for all valgrind knows you are accessing the next static variable.. (or more exactly some data in the static data segment of your application) You can however manually instrument your program to add suitable "red" zones arount suspectible variables just like valgrind automatically does on malloc:ed memory. See the "Client Requests" section in the memcheck chapter. But in many cases it is simpler to just allocate the variables with malloc instead as assays and pointers are semantically equivalent in C (except for sizeof).. converting to malloc also makes it possible for valgrind to guess what you intended to access in it's error report Regards Henrik |