mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
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);
This commit is contained in:
parent
5991f9a156
commit
24544a10c0
@ -25,13 +25,10 @@ static void
|
|||||||
send_control_event_string_replacement(uint16_t event, event_format_t which,
|
send_control_event_string_replacement(uint16_t event, event_format_t which,
|
||||||
const char *msg)
|
const char *msg)
|
||||||
{
|
{
|
||||||
int msg_len;
|
|
||||||
|
|
||||||
(void) event;
|
(void) event;
|
||||||
(void) which;
|
(void) which;
|
||||||
msg_len = strlen(msg);
|
tor_free(received_msg);
|
||||||
received_msg = tor_malloc_zero(msg_len+1);
|
received_msg = tor_strdup(msg);
|
||||||
strncpy(received_msg, msg, msg_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make sure each hidden service descriptor async event generation
|
/** Make sure each hidden service descriptor async event generation
|
||||||
@ -67,7 +64,6 @@ test_hs_desc_event(void *arg)
|
|||||||
test_assert(received_msg);
|
test_assert(received_msg);
|
||||||
test_streq(received_msg, expected_msg);
|
test_streq(received_msg, expected_msg);
|
||||||
tor_free(received_msg);
|
tor_free(received_msg);
|
||||||
received_msg = NULL;
|
|
||||||
|
|
||||||
/* test received event */
|
/* test received event */
|
||||||
rend_query.auth_type = 1;
|
rend_query.auth_type = 1;
|
||||||
@ -77,7 +73,6 @@ test_hs_desc_event(void *arg)
|
|||||||
test_assert(received_msg);
|
test_assert(received_msg);
|
||||||
test_streq(received_msg, expected_msg);
|
test_streq(received_msg, expected_msg);
|
||||||
tor_free(received_msg);
|
tor_free(received_msg);
|
||||||
received_msg = NULL;
|
|
||||||
|
|
||||||
/* test failed event */
|
/* test failed event */
|
||||||
rend_query.auth_type = 2;
|
rend_query.auth_type = 2;
|
||||||
@ -87,7 +82,6 @@ test_hs_desc_event(void *arg)
|
|||||||
test_assert(received_msg);
|
test_assert(received_msg);
|
||||||
test_streq(received_msg, expected_msg);
|
test_streq(received_msg, expected_msg);
|
||||||
tor_free(received_msg);
|
tor_free(received_msg);
|
||||||
received_msg = NULL;
|
|
||||||
|
|
||||||
/* test invalid auth type */
|
/* test invalid auth type */
|
||||||
rend_query.auth_type = 999;
|
rend_query.auth_type = 999;
|
||||||
@ -97,14 +91,10 @@ test_hs_desc_event(void *arg)
|
|||||||
test_assert(received_msg);
|
test_assert(received_msg);
|
||||||
test_streq(received_msg, expected_msg);
|
test_streq(received_msg, expected_msg);
|
||||||
tor_free(received_msg);
|
tor_free(received_msg);
|
||||||
received_msg = NULL;
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
UNMOCK(send_control_event_string);
|
UNMOCK(send_control_event_string);
|
||||||
if (received_msg) {
|
tor_free(received_msg);
|
||||||
tor_free(received_msg);
|
|
||||||
received_msg = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct testcase_t hs_tests[] = {
|
struct testcase_t hs_tests[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user