Re: Valgrind updates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Wed, 28 Jan 2009, Linus Torvalds wrote:

> On Tue, 27 Jan 2009, Johannes Schindelin wrote:
> > 
> > To help ye Gods, I put together this almost minimal C program:
> 
> This one is buggy.

Not exactly buggy.  Underexplained.

> > 	out = fopen("/dev/null", "w");
> > 	fwrite(compressed + 51, 51, 1, out);
> > 	fwrite(compressed + 51, 1, 1, stderr);
> > 	fflush(out);
> > 	fclose(out);
> 
> The problem is that the first argument to that first "fwrite()" is simply 
> wrong. It shouldn't be "compressed + 51", it should be just "compressed". 

Nope.  It should be "compressed + 51" to narrow down the issue, as 
valgrind does not complain about _any other_ offset.

Not even when that is _well_ after the 58 bytes deflate() says are 
available.

> As it is, you're writing 51 bytes, starting at 51 bytes in, and that's 
> obviously not correct (you only got 58 bytes from deflate()).

It is not, granted.  But I left it in for a purpose: to show that valgrind 
does not even bother to mention bytes we think should be invalid.

I thought that there might be a shortcut for /dev/null, so I changed the 
outfile to a real file, and it _still_ does not complain.

> So valgrind does complain about it, but for a perfectly valid reason.

Only it does not.  It complains about the write of 1 byte, not the write 
of 51.

But I know why: "out" is opened buffered, so it shows the error (well 
delayed, I might add, and not in a helpful manner) when fflush() is 
called.

The real issue, namely that an access of offset 51 triggers a valgrind 
error, is demonstrated by my small test case.

Ciao,
Dscho
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux