commit 24544a10c0f9e9022d13a413bf3330745d851afa Author: Nick Mathewson nickm@torproject.org Date: Mon Feb 3 16:12:30 2014 -0500
Clean up test_hs.c: warning fix; tor_free() usage.
My OSX laptop rightly gave a warning because of sticking strlen() into an int, but once I took a closer look... it appears that the strlen() was part of a needlessly verbose implementation for tor_strdup().
While I was there, I fixed the usage of tor_free() in test_hs.c: It checks for NULL, and it zeros its argument. So instead of if (foo) { tor_free(foo); foo = NULL; } we should just say tor_free(foo); --- src/test/test_hs.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/src/test/test_hs.c b/src/test/test_hs.c index a9e6644..75c9b62 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -25,13 +25,10 @@ static void send_control_event_string_replacement(uint16_t event, event_format_t which, const char *msg) { - int msg_len; - (void) event; (void) which; - msg_len = strlen(msg); - received_msg = tor_malloc_zero(msg_len+1); - strncpy(received_msg, msg, msg_len); + tor_free(received_msg); + received_msg = tor_strdup(msg); }
/** Make sure each hidden service descriptor async event generation @@ -67,7 +64,6 @@ test_hs_desc_event(void *arg) test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); - received_msg = NULL;
/* test received event */ rend_query.auth_type = 1; @@ -77,7 +73,6 @@ test_hs_desc_event(void *arg) test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); - received_msg = NULL;
/* test failed event */ rend_query.auth_type = 2; @@ -87,7 +82,6 @@ test_hs_desc_event(void *arg) test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); - received_msg = NULL;
/* test invalid auth type */ rend_query.auth_type = 999; @@ -97,14 +91,10 @@ test_hs_desc_event(void *arg) test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); - received_msg = NULL;
done: UNMOCK(send_control_event_string); - if (received_msg) { - tor_free(received_msg); - received_msg = NULL; - } + tor_free(received_msg); }
struct testcase_t hs_tests[] = {
tor-commits@lists.torproject.org