[mercury-users] Valgrind -- works and reports bugs in a hello_world
Ondrej Bojar
oboj7042 at ss1000.ms.mff.cuni.cz
Sat Mar 29 00:50:52 AEDT 2003
On Fri, 28 Mar 2003, Nicholas Nethercote wrote:
> > Thanks. Using MLFLAGS=... --shared ... enables valgrind to observe memory
> > misuse.
> Did it actually help you with your original problem?
Yes and no. Except for the harmless errors reported, it alters the
behaviour of the code, so that it segfaults deterministically much
earlier. It doesn't though report any error before the segfault, only
after it.
When carefully adding debug prints, I figured out, that it crashes in a
method of a C++ object when assigning to a variable of the object;
#define BUFFER_SIZE 100000
class CReport {
...
protected:
...
char Buffer[BUFFER_SIZE]; // My colleague is a pig
void* AktPosice; // This is the critical l_value
...
And this is the critical place near the segfault:
int delka;
...
delka = read (DesR, Buffer, BUFFER_SIZE);
if (delka <= 0) // Check for an i/o error
return 0;
AktPosice = Buffer; // This segfaults
A debugging print right before the assignment to AktPosice claims, that
the delka was set to 1048 by the read.
I assume, this is indeed the place of the bug. I guess the problem is
with the real size of types 'char' and the usage of the type 'int' for
'delka' instead of size_t. Unfortunately, I do not know, how to code the
thing correctly. (I've always been afraid of such issues.)
Could anybody fix this?
Many thanks, Andrew.
>
> > For a 'main-->io__write_string("Hello.\n")' program are there 155 errors
> > reported. Is this all right? :-)
>
> Valgrind's not perfect, and the errors are in libgc.so which might be
> doing some horribly complex things that confuse it. But it is probably
> worth someone investigating.
>
> N
> --------------------------------------------------------------------------
> mercury-users mailing list
> post: mercury-users at cs.mu.oz.au
> administrative address: owner-mercury-users at cs.mu.oz.au
> unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
> subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
> --------------------------------------------------------------------------
>
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list