summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-07-12 18:19:30 +0000
committerNick Mathewson <nickm@torproject.org>2005-07-12 18:19:30 +0000
commit0828feaf7cd4cf156a074eafd9cc83399d4781c2 (patch)
treeef3b277b66813b1dc299771c2128a271c20f49ae
parent8f9790a0235d5176c01f45b2c07eec5b46d7a2c9 (diff)
downloadtor-0828feaf7cd4cf156a074eafd9cc83399d4781c2.tar.gz
tor-0828feaf7cd4cf156a074eafd9cc83399d4781c2.zip
Add belt-and-suspenders fix to coredump from yesterday; document more functions in buffers.c
svn:r4532
-rw-r--r--src/or/buffers.c18
1 files 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 <b>c</b> in the
+ * <b>len</b>characters after <b>start</b> on <b>buf</b>. 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 <b>buf</b>. 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 <b>buf</b>, and write it,
+ * NUL-terminated, into the *<b>data_len</b> byte buffer at <b>data_out</b>.
+ * Set *<b>data_len</b> 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)
{