|
From: Bob R. <bob...@co...> - 2006-06-05 20:24:44
|
On Mon, Jun 05, 2006 at 08:25:54AM +1000, Nicholas Nethercote wrote:
> On Sun, 4 Jun 2006, Bob Rossi wrote:
>
> >> Before the experts answer you, it sounds to me like maybe you're passing
> >> around some un-initialized value which happens to have the right value
> >> (or just a "better" value) when running under Valgrind.
> >
> > I thought valgrind would discover if unintialized values are being used
> > though. Isn't that true?
>
> In general, yes. But the execution environment under Valgrind is different
> to that natively -- memory is laid out in different ways, etc. Very
> occasionally this changes program behaviour; but when it does it's usually
> because the program is buggy, eg. it's got a wild memory read/write that may
> hit addressible, initialised memory uner Valgrind but not natively. I
> imagine something like that is happening here. It's unfortunate for the
> poor user because Memcheck then can't detect the problem.
OK, if we include
#define _GNU_SOURCE /* ptsname_r() under Linux */
#include <sys/types.h>
we get the prototype
extern char *ptsname (int __fd) __attribute__ ((__nothrow__));
in the translation unit.
If we include
#include <sys/types.h>
#define _GNU_SOURCE /* ptsname_r() under Linux */
we do not get the prototype in the translation unit.
Then, we do this,
char *name;
if (!(name = ptsname(*masterfd)))
In the case where the prototype is defined, it works fine and there
is no crash. In the case where there is no prototype, we get this
error.
../../../../cgdb/various/util/src/pseudo.c:304: warning: assignment
makes pointer from integer without a cast
That's because it thinks ptsname returns an int, and assigns it to a
char*. This works when the sizeof(char*) == sizeof(int). However on this
64 amd machine, sizeof (char*)=8 sizeof (int)=4. This gives us the
crash.
Now, I'm wondering why valgrind reports no error on this circumstance.
Would this be an improvement to memcheck? It took us quite some time to
figure out the problem.
Thanks,
Bob Rossi
|