Re: Valgrind updates
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 29, 2009, 14:22 UTC
- Message-ID
- <alpine.DEB.1.00.0901291514240.3586@pacific.mpi-cbg.de>
- In-Reply-To
- <alpine.LFD.2.00.0901281751580.3123@localhost.localdomain>
Hi,
On Wed, 28 Jan 2009, Linus Torvalds wrote:
Show 5 quoted lines
> 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.
Show 8 quoted lines
> > 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