Thread (36 messages) flat view 36 messages, 8 authors, 2016-06-15

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

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:47:32

Johannes Sixt [off-list ref] wrote:
Shawn O. Pearce schrieb:
quoted
-int packet_read_line(int fd, char *buffer, unsigned size)
+static int packet_length(unsigned *ret_len, const char *linelen)
...
quoted
+	*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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help