|
From: Jean P. <2s...@ma...> - 2004-09-06 21:55:27
|
Hello, I'm currently evaluating valgrind against commercial software like purify and insure++ and so far it performs well. One bug I found very annoying is this one : double array[3]; array[3] = 0; And it seems that valgrind doesn't detect this one. In fact, so far I only found one product who can detect this and this is the bounds checking patch of gcc. I wonder if valgrind can be tweaked to detect this category of problem ? Thanks for any hint ! |
|
From: Paul P. <pa...@pa...> - 2004-09-06 22:15:50
|
Jean Pierre wrote:
> One bug I found very annoying is this one :
>
> double array[3];
> array[3] = 0;
Surely that is *not* a static array?
> In fact, so far I only found one product who can detect this and this is
> the bounds checking patch of gcc.
FWIW, Insure++ is *supposed* to find that bug (and an equivalent
one with the static array):
$ cat junk.c
int main()
{
double array[3];
static double xyz[3];
array[3] = 0;
xyz[3] = 1;
return 0;
}
$ insure gcc -g junk.c
[junk.c:5] **WRITE_BAD_INDEX**
Writing array out of range: array[3]
>> array[3] = 0;
[junk.c:6] **WRITE_BAD_INDEX**
Writing array out of range: xyz[3]
>> xyz[3] = 0;
$ ./a.out
[junk.c:5] **WRITE_BAD_INDEX**
>> array[3] = 0;
Writing array out of range: array[3]
Index used : 3
Valid range: 0 thru 2 (inclusive)
Stack trace where the error occurred:
main() junk.c, 5
**Memory corrupted. Program may crash!!**
[junk.c:6] **WRITE_BAD_INDEX**
>> xyz[3] = 0;
Writing array out of range: xyz[3]
Index used : 3
Valid range: 0 thru 2 (inclusive)
Stack trace where the error occurred:
main() junk.c, 6
Cheers,
|
|
From: Jean P. <2s...@ma...> - 2004-09-06 22:56:51
|
On Mon, 06 Sep 2004 15:15:41 -0700, Paul Pluzhnikov <pa...@pa...> wrote : > Jean Pierre wrote: > > > One bug I found very annoying is this one : > > > > double array[3]; > > array[3] = 0; > > Surely that is *not* a static array? Oops. By 'static' array, I wanted to mean a 'normal array' (as oppposed to dynamically allocated array). > > > In fact, so far I only found one product who can detect this and > > this is the bounds checking patch of gcc. > > FWIW, Insure++ is *supposed* to find that bug (and an equivalent > one with the static array): > Great ! I'll try their product. Do you know if valgrind could in theory detect this kind of problem too ? |
|
From: Tom H. <th...@cy...> - 2004-09-06 23:07:47
|
In message <20040906235552.04af6d04@linuxcestcomplique>
Jean Pierre <2s...@ma...> wrote:
> One bug I found very annoying is this one :
>
> double array[3];
> array[3] = 0;
>
> And it seems that valgrind doesn't detect this one.
It can't really do so - no run time only system can. The only systems
that detect that problem are those that do compile time manipulations
to either add bounds checking or insert guard words between the stack
variables.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Jean P. <2s...@ma...> - 2004-09-06 23:15:54
|
On Tue, 07 Sep 2004 00:07:46 +0100, Tom Hughes <th...@cy...> wrote : > > One bug I found very annoying is this one : > > > > double array[3]; > > array[3] = 0; > > > > And it seems that valgrind doesn't detect this one. > > It can't really do so - no run time only system can. The only systems > that detect that problem are those that do compile time manipulations > to either add bounds checking or insert guard words between the stack > variables. > Thanks for your answer. I'm stuck with Insure++ and gcc bounds-checking then... |
|
From: Oswald B. <os...@kd...> - 2004-09-06 23:16:23
|
On Tue, Sep 07, 2004 at 12:07:46AM +0100, Tom Hughes wrote: > It can't really do so - no run time only system can. > actually, i think a run time only solution would work to some extent, particularly if we have debug info available. julian, do you happen to still have the mails i sent you two years ago? :) -- Hi! I'm a .signature virus! Copy me into your ~/.signature, please! -- Chaos, panic, and disorder - my work here is done. |
|
From: Nicholas N. <nj...@ca...> - 2004-09-07 12:02:12
|
On Tue, 7 Sep 2004, Oswald Buddenhagen wrote: >> It can't really do so - no run time only system can. >> > actually, i think a run time only solution would work to some extent, > particularly if we have debug info available. I've worked on this, and got a runtime-only tool working that could detect bounds errors on static arrays (but not stack arrays). It relies on debug information to know where the static arrays are. Unfortunately the technique is not very robust which is why it's not in the Valgrind distribution, and probably never will be. Detecting these bounds errors is really something that is best done at the source level, so GCC's bounds-checking patches or Insure++ seem the best option. N |
|
From: Paul P. <pa...@pa...> - 2004-09-06 23:28:12
|
Jean Pierre wrote: > Oops. By 'static' array, I wanted to mean a 'normal array' (as oppposed > to dynamically allocated array). What you meant are arrays with automatic or static (as opposed to dynamic) storage duration. > Do you know if valgrind could in theory detect this kind of problem too This has been discussed here many times before. The consensus appears to be that VG will never be able to reliably catch either: http://sourceforge.net/mailarchive/message.php?msg_id=7603767 http://sourceforge.net/mailarchive/message.php?msg_id=8776351 Purify does detect (some?) static (but not automatic) array bounds, because they insert red-zones during the link stage. CCured detects both, but only for C (no C++ support). Cheers, |
|
From: Jean P. <2s...@ma...> - 2004-09-06 23:35:34
|
On Mon, 06 Sep 2004 16:27:07 -0700, Paul Pluzhnikov <pa...@pa...> wrote : > > Oops. By 'static' array, I wanted to mean a 'normal array' (as > > oppposed to dynamically allocated array). > > What you meant are arrays with automatic or static (as opposed > to dynamic) storage duration. > > > Do you know if valgrind could in theory detect this kind of problem > > too > > This has been discussed here many times before. > > The consensus appears to be that VG will never be able to reliably > catch either: > http://sourceforge.net/mailarchive/message.php?msg_id=7603767 > http://sourceforge.net/mailarchive/message.php?msg_id=8776351 > > Purify does detect (some?) static (but not automatic) array > bounds, because they insert red-zones during the link stage. > > CCured detects both, but only for C (no C++ support). Ok thanks for the information. I've looked at CCured but it seems to be quite hard to use on large projects, so I will stay with gcc bounds-checking (which does an excellent job, I wonder why it isn't more famous ?). Sorry to haven't made a search on the subject before posting... |