Re: Interesting coding idea

From: Dave Vandervies (dj3vande_at_csclub.uwaterloo.ca)
Date: 10/25/04


Date: Mon, 25 Oct 2004 18:54:10 +0000 (UTC)

In article <b%afd.3012$HA5.353696@juliett.dax.net>,
boa <root@localhost.com> wrote:
>Dave Vandervies wrote:

>> Why not build a DeathStation simulator?
>>
>> Create a VM that allows aggressive testing for bad (especially not-
>> well-defined) code, and a compiler targeting it that optimizes for
>> checkability rather than performance or size.

[Snip a few ideas]

>> Other thoughts?

>It exists already and is called valgrind ;-)

That would be this valgrind (first hit on Google)?
"Valgrind, an open-source memory debugger for x86-linux"

How many of these will valgrind catch?
--------
/*Mentioned in my post - have the VM be aware of sequence points so it
    can catch this
*/
i=i++;
--------
int *foo(int *dummy)
{
    int i;
    return &i;
}
int bar(int *p)
{
    int dummy=42;
    return *p;
}

/*In a function somewhere*/
/*Ideally, we want to warn here, when a no-longer-valid pointer is stored
    in a variable (or, better, immediately on return from foo when the
    storage the pointer points at goes away)
*/
p=foo(&i);
/*p is an invalid pointer; typical stack-using implementations will
    have it pointing at the dummy int in bar()
*/
i=bar(p);
--------
char buf[10];
char *str=some_string_pointer;
buf[0]='\0';
/*We want to warn about this (claimed buffer size larger than actual
    destination buffer) even if str fits into buf
*/
strncat(buf,str,20);
--------

Without knowing anything other than that it's a memory debugger, I'd give
part marks for the third one (no warning if the buffer doesn't overflow)
and a small chance at catching the second one.

Of course, it looks like it won't even get there if I try to run it on
a Mac.

So, quite obviously not what I was thinking of.

dave

-- 
Dave Vandervies                                dj3vande@csclub.uwaterloo.ca
I suspect all the things you mention are covered within the first 150 pages
of [K&R2]. At that point, most books on programming are still showing you
how to use the GUI editor.              --Richard Heathfield in comp.lang.c


Relevant Pages

  • Re: Interesting coding idea
    ... >Dave Vandervies wrote: ... That would be this valgrind (first hit on Google)? ... int *foo ...
    (comp.programming)
  • Re: Interesting coding idea
    ... Dave Vandervies wrote: ... > That would be this valgrind? ... > int bar ... > destination buffer) even if str fits into buf ...
    (comp.lang.c)
  • Re: Interesting coding idea
    ... Dave Vandervies wrote: ... > That would be this valgrind? ... > int bar ... > destination buffer) even if str fits into buf ...
    (comp.programming)
  • Re: malloc creates seg faults?
    ... I also installed valgrind and tried running memcheck on it. ... Product* prodndup(const Product* src, int n); ...
    (comp.lang.cpp)