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.