diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-02-16 15:40:15 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-02-16 15:40:15 -0500 |
commit | 5d2a23397a3775eecb35bea23edffbef40b6cd94 (patch) | |
tree | 6680efe61ba7e04c346bf7f0c9238d82d17331a7 | |
parent | 7117959199a230cc7f1684794b8b13235b5f2715 (diff) | |
download | tor-5d2a23397a3775eecb35bea23edffbef40b6cd94.tar.gz tor-5d2a23397a3775eecb35bea23edffbef40b6cd94.zip |
Fix a few coverity "Use after NULL check" warnings
Also remove the unit test mocks that allowed get_options() to be
NULL; that's an invariant violation for get_options().
-rw-r--r-- | src/common/workqueue.c | 2 | ||||
-rw-r--r-- | src/or/cpuworker.c | 3 | ||||
-rw-r--r-- | src/or/status.c | 2 | ||||
-rw-r--r-- | src/test/test_status.c | 57 |
4 files changed, 3 insertions, 61 deletions
diff --git a/src/common/workqueue.c b/src/common/workqueue.c index e9466b8124..823fb51cc9 100644 --- a/src/common/workqueue.c +++ b/src/common/workqueue.c @@ -371,12 +371,12 @@ threadpool_start_threads(threadpool_t *pool, int n) while (pool->n_threads < n) { void *state = pool->new_thread_state_fn(pool->new_thread_state_arg); workerthread_t *thr = workerthread_new(state, pool, pool->reply_queue); - thr->index = pool->n_threads; if (!thr) { tor_mutex_release(&pool->lock); return -1; } + thr->index = pool->n_threads; pool->threads[pool->n_threads++] = thr; } tor_mutex_release(&pool->lock); diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 5787c75530..09ffdb81d1 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -359,8 +359,7 @@ cpuworker_onion_handshake_replyfn(void *work_) log_debug(LD_OR, "decoding onionskin failed. " "(Old key or bad software.) Closing."); - if (circ) - circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL); + circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL); goto done_processing; } diff --git a/src/or/status.c b/src/or/status.c index 8057abef16..98db688e5b 100644 --- a/src/or/status.c +++ b/src/or/status.c @@ -132,7 +132,7 @@ log_heartbeat(time_t now) circuit_log_ancient_one_hop_circuits(1800); - if (options && options->BridgeRelay) { + if (options->BridgeRelay) { char *msg = NULL; msg = format_client_stats_heartbeat(now); if (msg) diff --git a/src/test/test_status.c b/src/test/test_status.c index aa71aa6a9b..5e9922af0b 100644 --- a/src/test/test_status.c +++ b/src/test/test_status.c @@ -240,7 +240,6 @@ NS(test_main)(void *arg) NS_DECL(double, tls_get_write_overhead_ratio, (void)); NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(const or_options_t *, get_options, (void)); NS_DECL(int, public_server_mode, (const or_options_t *options)); NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void)); @@ -252,7 +251,6 @@ NS(test_main)(void *arg) NS_MOCK(tls_get_write_overhead_ratio); NS_MOCK(we_are_hibernating); - NS_MOCK(get_options); NS_MOCK(public_server_mode); NS_MOCK(router_get_my_routerinfo); @@ -264,7 +262,6 @@ NS(test_main)(void *arg) done: NS_UNMOCK(tls_get_write_overhead_ratio); NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(get_options); NS_UNMOCK(public_server_mode); NS_UNMOCK(router_get_my_routerinfo); } @@ -281,12 +278,6 @@ NS(we_are_hibernating)(void) return 0; } -static const or_options_t * -NS(get_options)(void) -{ - return NULL; -} - static int NS(public_server_mode)(const or_options_t *options) { @@ -311,7 +302,6 @@ NS(router_get_my_routerinfo)(void) NS_DECL(double, tls_get_write_overhead_ratio, (void)); NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(const or_options_t *, get_options, (void)); NS_DECL(int, public_server_mode, (const or_options_t *options)); NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void)); NS_DECL(const node_t *, node_get_by_id, (const char *identity_digest)); @@ -331,7 +321,6 @@ NS(test_main)(void *arg) NS_MOCK(tls_get_write_overhead_ratio); NS_MOCK(we_are_hibernating); - NS_MOCK(get_options); NS_MOCK(public_server_mode); NS_MOCK(router_get_my_routerinfo); NS_MOCK(node_get_by_id); @@ -353,7 +342,6 @@ NS(test_main)(void *arg) done: NS_UNMOCK(tls_get_write_overhead_ratio); NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(get_options); NS_UNMOCK(public_server_mode); NS_UNMOCK(router_get_my_routerinfo); NS_UNMOCK(node_get_by_id); @@ -374,12 +362,6 @@ NS(we_are_hibernating)(void) return 0; } -static const or_options_t * -NS(get_options)(void) -{ - return NULL; -} - static int NS(public_server_mode)(const or_options_t *options) { @@ -472,7 +454,6 @@ NS(server_mode)(const or_options_t *options) NS_DECL(double, tls_get_write_overhead_ratio, (void)); NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(const or_options_t *, get_options, (void)); NS_DECL(int, public_server_mode, (const or_options_t *options)); NS_DECL(long, get_uptime, (void)); NS_DECL(uint64_t, get_bytes_read, (void)); @@ -489,7 +470,6 @@ NS(test_main)(void *arg) NS_MOCK(tls_get_write_overhead_ratio); NS_MOCK(we_are_hibernating); - NS_MOCK(get_options); NS_MOCK(public_server_mode); NS_MOCK(get_uptime); NS_MOCK(get_bytes_read); @@ -507,7 +487,6 @@ NS(test_main)(void *arg) done: NS_UNMOCK(tls_get_write_overhead_ratio); NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(get_options); NS_UNMOCK(public_server_mode); NS_UNMOCK(get_uptime); NS_UNMOCK(get_bytes_read); @@ -528,12 +507,6 @@ NS(we_are_hibernating)(void) return 1; } -static const or_options_t * -NS(get_options)(void) -{ - return NULL; -} - static int NS(public_server_mode)(const or_options_t *options) { @@ -599,7 +572,6 @@ NS(server_mode)(const or_options_t *options) NS_DECL(double, tls_get_write_overhead_ratio, (void)); NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(const or_options_t *, get_options, (void)); NS_DECL(int, public_server_mode, (const or_options_t *options)); NS_DECL(long, get_uptime, (void)); NS_DECL(uint64_t, get_bytes_read, (void)); @@ -622,7 +594,6 @@ NS(test_main)(void *arg) NS_MOCK(tls_get_write_overhead_ratio); NS_MOCK(we_are_hibernating); - NS_MOCK(get_options); NS_MOCK(public_server_mode); NS_MOCK(get_uptime); NS_MOCK(get_bytes_read); @@ -644,7 +615,6 @@ NS(test_main)(void *arg) done: NS_UNMOCK(tls_get_write_overhead_ratio); NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(get_options); NS_UNMOCK(public_server_mode); NS_UNMOCK(get_uptime); NS_UNMOCK(get_bytes_read); @@ -669,15 +639,6 @@ NS(we_are_hibernating)(void) return 0; } -static const or_options_t * -NS(get_options)(void) -{ - NS(mock_options) = tor_malloc_zero(sizeof(or_options_t)); - NS(mock_options)->AccountingMax = 0; - - return NS(mock_options); -} - static int NS(public_server_mode)(const or_options_t *options) { @@ -792,7 +753,6 @@ NS(get_or_state)(void) NS_DECL(double, tls_get_write_overhead_ratio, (void)); NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(const or_options_t *, get_options, (void)); NS_DECL(int, public_server_mode, (const or_options_t *options)); NS_DECL(long, get_uptime, (void)); NS_DECL(uint64_t, get_bytes_read, (void)); @@ -810,7 +770,6 @@ NS(test_main)(void *arg) NS_MOCK(tls_get_write_overhead_ratio); NS_MOCK(we_are_hibernating); - NS_MOCK(get_options); NS_MOCK(public_server_mode); NS_MOCK(get_uptime); NS_MOCK(get_bytes_read); @@ -833,7 +792,6 @@ NS(test_main)(void *arg) stats_n_data_cells_packaged = 0; NS_UNMOCK(tls_get_write_overhead_ratio); NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(get_options); NS_UNMOCK(public_server_mode); NS_UNMOCK(get_uptime); NS_UNMOCK(get_bytes_read); @@ -855,12 +813,6 @@ NS(we_are_hibernating)(void) return 0; } -static const or_options_t * -NS(get_options)(void) -{ - return NULL; -} - static int NS(public_server_mode)(const or_options_t *options) { @@ -951,7 +903,6 @@ NS(accounting_is_enabled)(const or_options_t *options) NS_DECL(double, tls_get_write_overhead_ratio, (void)); NS_DECL(int, we_are_hibernating, (void)); -NS_DECL(const or_options_t *, get_options, (void)); NS_DECL(int, public_server_mode, (const or_options_t *options)); NS_DECL(long, get_uptime, (void)); NS_DECL(uint64_t, get_bytes_read, (void)); @@ -969,7 +920,6 @@ NS(test_main)(void *arg) NS_MOCK(tls_get_write_overhead_ratio); NS_MOCK(we_are_hibernating); - NS_MOCK(get_options); NS_MOCK(public_server_mode); NS_MOCK(get_uptime); NS_MOCK(get_bytes_read); @@ -989,7 +939,6 @@ NS(test_main)(void *arg) done: NS_UNMOCK(tls_get_write_overhead_ratio); NS_UNMOCK(we_are_hibernating); - NS_UNMOCK(get_options); NS_UNMOCK(public_server_mode); NS_UNMOCK(get_uptime); NS_UNMOCK(get_bytes_read); @@ -1011,12 +960,6 @@ NS(we_are_hibernating)(void) return 0; } -static const or_options_t * -NS(get_options)(void) -{ - return NULL; -} - static int NS(public_server_mode)(const or_options_t *options) { |