git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Increase some limits in git-mailinfo

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 26, 2007, 20:13 UTC
Message-ID
<Pine.LNX.4.64.0702261207520.12485@woody.linux-foundation.org>
In-Reply-To
<Pine.LNX.4.63.0702262020590.22628@wbgn013.biozentrum.uni-wuerzburg.de>
On Mon, 26 Feb 2007, Johannes Schindelin wrote:
> 
> I know that you copied that, but why not use the new prefixcmp() function?

Heh. Partly just because I copied it, partly because I'm not that used to the interface (and partly becuase I hate how it uses the same complex interface as 'strncmp()' does - I'd much rather see a _boolean_ return value, instead of the tristate one it uses. I doubt anybody would ever use it for sorting purposes anyway, and the tristate return value just results in code that is harder to read).

So I'd rather have it return true if it matches, rather than false if it matches and -1/1 if it doesn't. But that's water under the bridge.

Show 17 quoted lines
> > +	/* Get the first part of the line.. */
> > +	if (!fgets(line, sz, in))
> > +		return 0;
> > +
> > +	/*
> > +	 * Is it an empty line or not a valid rfc2822 header?
> > +	 * If so, stop here, and return false ("not a header")
> > +	 */
> > +	len = eatspace(line);
> > +	if (!len || !is_rfc2822_header(line)) {
> > +		/* Re-add the newline */
> > +		line[len] = '\n';
> > +		line[len + 1] = '\0';
> 
> Just a micro-issue: if the input ends in the middle of a header line, 
> _and_ this line is of exactly the right size (sz), then len + 1 is not 
> necessarily smaller than sz, right?
Yeah. It's an old bug, though, the old code had the same behaviour.
But you're right. It might be better to have a
	assert(sz);
	sz--;

at the top of the function, and just realize that sz is the size of the buffer minus the size for the final '\0', and that also indirectly would mean that even if the initial fgets() didn't have a '\n' at the end, we always have space to insert it.

Show 5 quoted lines
> > +		addlen = eatspace(continuation);
> > +		if (len < sz) {
> 
> Shouldn't this be "sz - 1"? We are setting "line[len] = 0;" later... While 
> at it, we can always check for "addlen > 0", just in case?
Yeah. Again, the "sz--" would solve that.
			Linus
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 4 of 8 in “Increase some limits in git-mailinfo”
  1. Linus TorvaldsFeb 26, 2007
  2. Linus TorvaldsFeb 26, 2007
  3. Johannes SchindelinFeb 26, 2007
  4. Linus TorvaldsFeb 26, 2007
  5. Johannes SchindelinFeb 26, 2007
  6. Linus TorvaldsFeb 26, 2007
  7. Johannes SchindelinFeb 26, 2007
  8. Linus TorvaldsFeb 26, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.