Re: [PATCH] fetch--tool: fix uninitialized buffer when reading from stdin
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Feb 26, 2007, 16:47 UTC
- Message-ID
- <Pine.LNX.4.63.0702261741360.22628@wbgn013.biozentrum.uni-wuerzburg.de>
- In-Reply-To
- <Pine.LNX.4.64.0702260821310.12485@woody.linux-foundation.org>
Hi,
On Mon, 26 Feb 2007, Linus Torvalds wrote:
Show 6 quoted lines
> > + if (read > 0 && data[read - 1] == '\n') > > + data[read - 1] = '\0'; > > + else > > + data[read] = '\0'; > > First off, "read" here may be -1.
Ah yes. I somehow had the erroneous impression that xread() die()s on error like xmalloc()...
> /* Why do this? Because Dscho did.. */ > if (offset && data[offset-1] == '\n') > offset--;
Well yes, it probably does not change anything except the output, which you see only when debugging.
It's not like I care deeply, because this part of the code will hopefully soon go away, when git-fetch is a proper builtin.
However, I compile with -DXMALLOC_POISON=1 and _that_ did not play well, whereas the read fails rather rarely on stdin...
But I agree your patch is saner.
Ciao, Dscho