From 0828feaf7cd4cf156a074eafd9cc83399d4781c2 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 12 Jul 2005 18:19:30 +0000 Subject: [PATCH] Add belt-and-suspenders fix to coredump from yesterday; document more functions in buffers.c svn:r4532 --- src/or/buffers.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/or/buffers.c b/src/or/buffers.c index 4bc1173b01..84d26efa80 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -1105,6 +1105,9 @@ fetch_from_buf_control0(buf_t *buf, uint32_t *len_out, uint16_t *type_out, tor_assert(type_out); tor_assert(body_out); + *len_out = 0; + *body_out = NULL; + if (buf->datalen < 4) return 0; @@ -1125,13 +1128,13 @@ fetch_from_buf_control0(buf_t *buf, uint32_t *len_out, uint16_t *type_out, *body_out = tor_malloc(msglen+1); fetch_from_buf(*body_out, msglen, buf); (*body_out)[msglen] = '\0'; - } else { - *body_out = NULL; } return 1; } -/** DOCDOC */ +/** Helper: return a pointer to the first instance of c in the + * lencharacters after start on buf. Return NULL if the + * character isn't found. */ static char * find_char_on_buf(buf_t *buf, char *start, size_t len, char c) { @@ -1144,6 +1147,8 @@ find_char_on_buf(buf_t *buf, char *start, size_t len, char c) return memchr(buf->mem, c, len_rest); } +/** Helper: return a pointer to the first CRLF after cp on buf. Return + * NULL if no CRLF is found. */ static char * find_crlf_on_buf(buf_t *buf, char *cp) { @@ -1162,7 +1167,12 @@ find_crlf_on_buf(buf_t *buf, char *cp) } } -/* DOCDOC : 0 means 'need to read more'. means done, -1 means "grow buffer." */ +/** Try to read a single CRLF-terminated line from buf, and write it, + * NUL-terminated, into the *data_len byte buffer at data_out. + * Set *data_len to the number of bytes in the line, not counting the + * terminating NUL. Return 1 if we read a whole line, return 0 if we don't + * have a whole line yet, and return -1 if we we need to grow the buffer. + */ int fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len) {