Re: Increase some limits in git-mailinfo

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

 




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.


> > +	/* 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.

> > +		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
-
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]