Remove the unused "nulterminate" option to buf_pullup()

I was going to add a test for this, but I realized that it had no
users.  So, removed.
This commit is contained in:
Nick Mathewson 2015-09-01 14:36:25 -04:00
parent 0e60c52c6c
commit fc191df930
4 changed files with 15 additions and 26 deletions

2
changes/pullup_nulterm Normal file
View file

@ -0,0 +1,2 @@
o Code simplifications and refactoring:
- Remove the unused "nulterminate" argument from buf_pullup().

View file

@ -182,7 +182,7 @@ preferred_chunk_size(size_t target)
* If <b>nulterminate</b> is true, ensure that there is a 0 byte in
* buf->head->mem right after all the data. */
STATIC void
buf_pullup(buf_t *buf, size_t bytes, int nulterminate)
buf_pullup(buf_t *buf, size_t bytes)
{
/* XXXX nothing uses nulterminate; remove it. */
chunk_t *dest, *src;
@ -194,17 +194,9 @@ buf_pullup(buf_t *buf, size_t bytes, int nulterminate)
if (buf->datalen < bytes)
bytes = buf->datalen;
if (nulterminate) {
capacity = bytes + 1;
if (buf->head->datalen >= bytes && CHUNK_REMAINING_CAPACITY(buf->head)) {
*CHUNK_WRITE_PTR(buf->head) = '\0';
return;
}
} else {
capacity = bytes;
if (buf->head->datalen >= bytes)
return;
}
capacity = bytes;
if (buf->head->datalen >= bytes)
return;
if (buf->head->memlen >= capacity) {
/* We don't need to grow the first chunk, but we might need to repack it.*/
@ -248,11 +240,6 @@ buf_pullup(buf_t *buf, size_t bytes, int nulterminate)
}
}
if (nulterminate) {
tor_assert(CHUNK_REMAINING_CAPACITY(buf->head));
*CHUNK_WRITE_PTR(buf->head) = '\0';
}
check();
}
@ -1203,7 +1190,7 @@ fetch_from_buf_http(buf_t *buf,
/* Okay, we have a full header. Make sure it all appears in the first
* chunk. */
if ((int)buf->head->datalen < crlf_offset + 4)
buf_pullup(buf, crlf_offset+4, 0);
buf_pullup(buf, crlf_offset+4);
headerlen = crlf_offset + 4;
headers = buf->head->data;
@ -1451,7 +1438,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
do {
n_drain = 0;
buf_pullup(buf, want_length, 0);
buf_pullup(buf, want_length);
tor_assert(buf->head && buf->head->datalen >= 2);
want_length = 0;
@ -1870,7 +1857,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
*want_length_out = SOCKS4_NETWORK_LEN;
return 0; /* not yet */
}
// buf_pullup(buf, 1280, 0);
// buf_pullup(buf, 1280);
req->command = (unsigned char) *(data+1);
if (req->command != SOCKS_COMMAND_CONNECT &&
req->command != SOCKS_COMMAND_RESOLVE) {
@ -2038,7 +2025,7 @@ fetch_from_buf_socks_client(buf_t *buf, int state, char **reason)
if (buf->datalen < 2)
return 0;
buf_pullup(buf, MAX_SOCKS_MESSAGE_LEN, 0);
buf_pullup(buf, MAX_SOCKS_MESSAGE_LEN);
tor_assert(buf->head && buf->head->datalen >= 2);
r = parse_socks_client((uint8_t*)buf->head->data, buf->head->datalen,

View file

@ -101,7 +101,7 @@ void assert_buf_ok(buf_t *buf);
#ifdef BUFFERS_PRIVATE
STATIC int buf_find_string_offset(const buf_t *buf, const char *s, size_t n);
STATIC void buf_pullup(buf_t *buf, size_t bytes, int nulterminate);
STATIC void buf_pullup(buf_t *buf, size_t bytes);
void buf_get_first_chunk_data(const buf_t *buf, const char **cp, size_t *sz);
#define DEBUG_CHUNK_ALLOC

View file

@ -218,7 +218,7 @@ test_buffer_pullup(void *arg)
/* There are a bunch of cases for pullup. One is the trivial case. Let's
mess around with an empty buffer. */
buf_pullup(buf, 16, 1);
buf_pullup(buf, 16);
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, OP_EQ, NULL);
tt_uint_op(sz, OP_EQ, 0);
@ -240,7 +240,7 @@ test_buffer_pullup(void *arg)
* can get tested. */
tt_int_op(fetch_from_buf(tmp, 3000, buf), OP_EQ, 3000);
tt_mem_op(tmp,OP_EQ, stuff, 3000);
buf_pullup(buf, 2048, 0);
buf_pullup(buf, 2048);
assert_buf_ok(buf);
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, OP_NE, NULL);
@ -263,7 +263,7 @@ test_buffer_pullup(void *arg)
tt_ptr_op(cp, OP_NE, NULL);
tt_int_op(sz, OP_LE, 4096);
buf_pullup(buf, 12500, 0);
buf_pullup(buf, 12500);
assert_buf_ok(buf);
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, OP_NE, NULL);
@ -286,7 +286,7 @@ test_buffer_pullup(void *arg)
write_to_buf(stuff, 4000, buf);
write_to_buf(stuff+4000, 4000, buf);
fetch_from_buf(tmp, 100, buf); /* dump 100 bytes from first chunk */
buf_pullup(buf, 16000, 0); /* Way too much. */
buf_pullup(buf, 16000); /* Way too much. */
assert_buf_ok(buf);
buf_get_first_chunk_data(buf, &cp, &sz);
tt_ptr_op(cp, OP_NE, NULL);