Subject: Re: [RFC PATCH v2 01/16] pkt-line: Add strbuf based functions

From: "Shawn O. Pearce" <[email-masked]>
Date: Tue, 13 Oct 2009 11:10:41 -0700

Johannes Sixt <[email-masked]> wrote:
> Shawn O. Pearce schrieb:
> > -int packet_read_line(int fd, char *buffer, unsigned size)
> > +static int packet_length(unsigned *ret_len, const char *linelen)
...
> > +	*ret_len = len;
> > +	return 0;
> > +}
> 
> len can be signed: Valid lengths fit into a signed int. Then you can
> 'return len;' on success and 'return -1;' on failure and don't need return
> the result by reference. packet_read_line() ultimately converts it to int
> anyway:

Great catch, thanks.  This is actually from a prior version of code
where I was exposing this function to callers... but even then the
method could have just returned int with the value because as you
point out, all valid lengths fit in int and must be >= 0.
 
-- 
Shawn.