diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-02-03 16:12:30 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-02-03 16:12:30 -0500 |
commit | 24544a10c0f9e9022d13a413bf3330745d851afa (patch) | |
tree | e898bd355b814d889d16fe79cf5625d12cca41f7 /src/test/test_hs.c | |
parent | 5991f9a15646d53b838562fd1424b6a8fd9ef614 (diff) | |
download | tor-24544a10c0f9e9022d13a413bf3330745d851afa.tar.gz tor-24544a10c0f9e9022d13a413bf3330745d851afa.zip |
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);
Diffstat (limited to 'src/test/test_hs.c')
-rw-r--r-- | src/test/test_hs.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/test/test_hs.c b/src/test/test_hs.c index a9e6644397..75c9b62871 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[] = { |