commit f0b136a268f39cdb7840d0bdf630e3954a245a69 Author: Nick Mathewson nickm@torproject.org Date: Fri Jun 10 18:55:50 2011 -0400
Fix warnings from clang analyzer --- src/main.c | 10 +++++++++- src/test/unittest_obfs2.c | 17 +++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/main.c b/src/main.c index ace9e8c..5ca365f 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ */
#include <stdlib.h> +#include <errno.h> #include <stdio.h> #include <string.h> #include <signal.h> @@ -251,6 +252,7 @@ main(int argc, const char **argv) Finally, we allocate space on the n_options_array so that we can put the number of options there. */ + /*XXXX (Why not actually allocate this before the start of the loop?)*/ temp = realloc(protocol_options, sizeof(char**)*actual_protocols); if (!temp) @@ -300,10 +302,16 @@ main(int argc, const char **argv)
/*Let's open a new listener for each protocol. */ int h; - listener_t *listeners[actual_protocols]; + listener_t **listeners; listener_t *temp_listener; int n_listeners=0; protocol_params_t *proto_params=NULL; + listeners = calloc(sizeof(listener_t*), actual_protocols); + if (!listeners) { + log_warn("Allocation failure: %s", strerror(errno)); + return 1; + } + for (h=0;h<actual_protocols;h++) {
log_debug("Spawning listener %d!", h+1); diff --git a/src/test/unittest_obfs2.c b/src/test/unittest_obfs2.c index 62a2ff3..af31adc 100644 --- a/src/test/unittest_obfs2.c +++ b/src/test/unittest_obfs2.c @@ -133,9 +133,9 @@ test_proto_setup(void *data) tt_assert(server_proto->state);
end: - if (client_proto->state) + if (client_proto) proto_destroy(client_proto); - if (server_proto->state) + if (server_proto) proto_destroy(server_proto); }
@@ -200,10 +200,10 @@ test_proto_handshake(void *data) sizeof(crypt_t)));
end: - if (client_proto->state) - proto_destroy(client_proto); - if (server_proto->state) - proto_destroy(server_proto); + if (client_proto) + proto_destroy(client_proto); + if (server_proto) + proto_destroy(server_proto);
if (proto_params_client) free(proto_params_client); @@ -273,6 +273,7 @@ test_proto_transfer(void *data) output_buffer, dummy_buffer));
n = evbuffer_peek(dummy_buffer, -1, NULL, &v[0], 2); + tt_int_op(n, !=, -1);
/* Let's check if it matches. */ tt_int_op(0, ==, strncmp(msg1, v[0].iov_base, 54)); @@ -294,9 +295,9 @@ test_proto_transfer(void *data) (void) n; /* XXXX: use n for something, or remove it. */
end: - if (client_proto->state) + if (client_proto) proto_destroy(client_proto); - if (server_proto->state) + if (server_proto) proto_destroy(server_proto);
if (proto_params_client)