From: Mathieu Desnoyers Date: Thu, 4 Jul 2013 19:23:22 +0000 (-0400) Subject: Fix tests: use of uninitialized variables X-Git-Tag: v0.8.0~11 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9aa14175d93952464fa8ec15df54e2656c349c0b;p=userspace-rcu.git Fix tests: use of uninitialized variables Were working fine by luck, since they were allocated at the start of newly spawned test programs. Identified by Coverity. Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/test_mutex.c b/tests/test_mutex.c index 83adfdb..2f25454 100644 --- a/tests/test_mutex.c +++ b/tests/test_mutex.c @@ -337,12 +337,12 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); - tot_nr_reads = malloc(sizeof(*tot_nr_reads) * nr_readers); - tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); + tot_nr_reads = calloc(nr_readers, sizeof(*tot_nr_reads)); + tot_nr_writes = calloc(nr_writers, sizeof(*tot_nr_writes)); next_aff = 0; diff --git a/tests/test_perthreadlock.c b/tests/test_perthreadlock.c index be6e59d..39e2feb 100644 --- a/tests/test_perthreadlock.c +++ b/tests/test_perthreadlock.c @@ -345,11 +345,11 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - tot_nr_reads = malloc(sizeof(*tot_nr_reads) * nr_readers); - tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); - per_thread_lock = malloc(sizeof(*per_thread_lock) * nr_readers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + tot_nr_reads = calloc(nr_readers, sizeof(*tot_nr_reads)); + tot_nr_writes = calloc(nr_writers, sizeof(*tot_nr_writes)); + per_thread_lock = calloc(nr_readers, sizeof(*per_thread_lock)); for (i = 0; i < nr_readers; i++) { err = pthread_mutex_init(&per_thread_lock[i].lock, NULL); if (err != 0) diff --git a/tests/test_perthreadlock_timing.c b/tests/test_perthreadlock_timing.c index 9321f03..97bdd04 100644 --- a/tests/test_perthreadlock_timing.c +++ b/tests/test_perthreadlock_timing.c @@ -143,10 +143,10 @@ int main(int argc, char **argv) num_read = atoi(argv[1]); num_write = atoi(argv[2]); - reader_time = malloc(sizeof(*reader_time) * num_read); - writer_time = malloc(sizeof(*writer_time) * num_write); - tid_reader = malloc(sizeof(*tid_reader) * num_read); - tid_writer = malloc(sizeof(*tid_writer) * num_write); + reader_time = calloc(num_read, sizeof(*reader_time)); + writer_time = calloc(num_write, sizeof(*writer_time)); + tid_reader = calloc(num_read, sizeof(*tid_reader)); + tid_writer = calloc(num_write, sizeof(*tid_writer)); printf("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); diff --git a/tests/test_rwlock.c b/tests/test_rwlock.c index 287b14e..5a0e8c1 100644 --- a/tests/test_rwlock.c +++ b/tests/test_rwlock.c @@ -333,10 +333,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); next_aff = 0; diff --git a/tests/test_rwlock_timing.c b/tests/test_rwlock_timing.c index 3ff7ee4..d916071 100644 --- a/tests/test_rwlock_timing.c +++ b/tests/test_rwlock_timing.c @@ -134,10 +134,10 @@ int main(int argc, char **argv) num_read = atoi(argv[1]); num_write = atoi(argv[2]); - reader_time = malloc(sizeof(*reader_time) * num_read); - writer_time = malloc(sizeof(*writer_time) * num_write); - tid_reader = malloc(sizeof(*tid_reader) * num_read); - tid_writer = malloc(sizeof(*tid_writer) * num_write); + reader_time = calloc(num_read, sizeof(*reader_time)); + writer_time = calloc(num_write, sizeof(*writer_time)); + tid_reader = calloc(num_read, sizeof(*tid_reader)); + tid_writer = calloc(num_write, sizeof(*tid_writer)); printf("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); diff --git a/tests/test_urcu.c b/tests/test_urcu.c index 3017e81..2764878 100644 --- a/tests/test_urcu.c +++ b/tests/test_urcu.c @@ -346,10 +346,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); next_aff = 0; diff --git a/tests/test_urcu_assign.c b/tests/test_urcu_assign.c index 67253da..dc6bf2f 100644 --- a/tests/test_urcu_assign.c +++ b/tests/test_urcu_assign.c @@ -380,10 +380,10 @@ int main(int argc, char **argv) "main", urcu_get_thread_id()); test_array = calloc(1, sizeof(*test_array) * ARRAY_SIZE); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); next_aff = 0; diff --git a/tests/test_urcu_bp.c b/tests/test_urcu_bp.c index a0d6f11..9ec5f3e 100644 --- a/tests/test_urcu_bp.c +++ b/tests/test_urcu_bp.c @@ -341,10 +341,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); next_aff = 0; diff --git a/tests/test_urcu_defer.c b/tests/test_urcu_defer.c index 395014e..4e785c4 100644 --- a/tests/test_urcu_defer.c +++ b/tests/test_urcu_defer.c @@ -368,10 +368,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + tot_nr_writes = calloc(nr_writers, sizeof(*tot_nr_writes)); next_aff = 0; diff --git a/tests/test_urcu_gc.c b/tests/test_urcu_gc.c index 6e5cc1d..5c57f3f 100644 --- a/tests/test_urcu_gc.c +++ b/tests/test_urcu_gc.c @@ -396,11 +396,11 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); - pending_reclaims = malloc(sizeof(*pending_reclaims) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + tot_nr_writes = calloc(nr_writers, sizeof(*tot_nr_writes)); + pending_reclaims = calloc(nr_writers, sizeof(*pending_reclaims)); if (reclaim_batch * sizeof(*pending_reclaims[i].queue) < CAA_CACHE_LINE_SIZE) for (i = 0; i < nr_writers; i++) diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c index 9416224..f862adb 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -550,22 +550,22 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); if (!tid_reader) { mainret = 1; goto end; } - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); if (!tid_writer) { mainret = 1; goto end_free_tid_reader; } - count_reader = malloc(sizeof(*count_reader) * nr_readers); + count_reader = calloc(nr_readers, sizeof(*count_reader)); if (!count_reader) { mainret = 1; goto end_free_tid_writer; } - count_writer = malloc(sizeof(*count_writer) * nr_writers); + count_writer = calloc(nr_writers, sizeof(*count_writer)); if (!count_writer) { mainret = 1; goto end_free_count_reader; diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index 52ca225..5717f23 100644 --- a/tests/test_urcu_lfq.c +++ b/tests/test_urcu_lfq.c @@ -350,10 +350,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); - tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); + tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer)); + tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer)); + count_enqueuer = calloc(nr_enqueuers, 2 * sizeof(*count_enqueuer)); + count_dequeuer = calloc(nr_dequeuers, 2 * sizeof(*count_dequeuer)); cds_lfq_init_rcu(&q, call_rcu); err = create_all_cpu_call_rcu_data(0); if (err) { diff --git a/tests/test_urcu_lfs.c b/tests/test_urcu_lfs.c index b2a3371..5659d9a 100644 --- a/tests/test_urcu_lfs.c +++ b/tests/test_urcu_lfs.c @@ -434,10 +434,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); - tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); + tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer)); + tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer)); + count_enqueuer = calloc(nr_enqueuers, 2 * sizeof(*count_enqueuer)); + count_dequeuer = calloc(nr_dequeuers, 2 * sizeof(*count_dequeuer)); cds_lfs_init(&s); err = create_all_cpu_call_rcu_data(0); if (err) { diff --git a/tests/test_urcu_lfs_rcu.c b/tests/test_urcu_lfs_rcu.c index 89077dc..b76bde1 100644 --- a/tests/test_urcu_lfs_rcu.c +++ b/tests/test_urcu_lfs_rcu.c @@ -351,10 +351,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); - tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); + tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer)); + tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer)); + count_enqueuer = calloc(nr_enqueuers, 2 * sizeof(*count_enqueuer)); + count_dequeuer = calloc(nr_dequeuers, 2 * sizeof(*count_dequeuer)); cds_lfs_init_rcu(&s); err = create_all_cpu_call_rcu_data(0); if (err) { diff --git a/tests/test_urcu_qsbr.c b/tests/test_urcu_qsbr.c index 2e9e2b2..85d8430 100644 --- a/tests/test_urcu_qsbr.c +++ b/tests/test_urcu_qsbr.c @@ -352,10 +352,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); next_aff = 0; diff --git a/tests/test_urcu_qsbr_gc.c b/tests/test_urcu_qsbr_gc.c index 64d2e24..e0a2004 100644 --- a/tests/test_urcu_qsbr_gc.c +++ b/tests/test_urcu_qsbr_gc.c @@ -396,11 +396,11 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); - pending_reclaims = malloc(sizeof(*pending_reclaims) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + tot_nr_writes = calloc(nr_writers, sizeof(*tot_nr_writes)); + pending_reclaims = calloc(nr_writers, sizeof(*pending_reclaims)); if (reclaim_batch * sizeof(*pending_reclaims[i].queue) < CAA_CACHE_LINE_SIZE) for (i = 0; i < nr_writers; i++) diff --git a/tests/test_urcu_qsbr_timing.c b/tests/test_urcu_qsbr_timing.c index bb29301..9b5195d 100644 --- a/tests/test_urcu_qsbr_timing.c +++ b/tests/test_urcu_qsbr_timing.c @@ -175,10 +175,10 @@ int main(int argc, char **argv) num_read = atoi(argv[1]); num_write = atoi(argv[2]); - reader_time = malloc(sizeof(*reader_time) * num_read); - writer_time = malloc(sizeof(*writer_time) * num_write); - tid_reader = malloc(sizeof(*tid_reader) * num_read); - tid_writer = malloc(sizeof(*tid_writer) * num_write); + reader_time = calloc(num_read, sizeof(*reader_time)); + writer_time = calloc(num_write, sizeof(*writer_time)); + tid_reader = calloc(num_read, sizeof(*tid_reader)); + tid_writer = calloc(num_write, sizeof(*tid_writer)); printf("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); diff --git a/tests/test_urcu_timing.c b/tests/test_urcu_timing.c index 4fbdcca..e31b676 100644 --- a/tests/test_urcu_timing.c +++ b/tests/test_urcu_timing.c @@ -174,10 +174,10 @@ int main(int argc, char **argv) num_read = atoi(argv[1]); num_write = atoi(argv[2]); - reader_time = malloc(sizeof(*reader_time) * num_read); - writer_time = malloc(sizeof(*writer_time) * num_write); - tid_reader = malloc(sizeof(*tid_reader) * num_read); - tid_writer = malloc(sizeof(*tid_writer) * num_write); + reader_time = calloc(num_read, sizeof(*reader_time)); + writer_time = calloc(num_write, sizeof(*writer_time)); + tid_reader = calloc(num_read, sizeof(*tid_reader)); + tid_writer = calloc(num_write, sizeof(*tid_writer)); printf("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); diff --git a/tests/test_urcu_wfcq.c b/tests/test_urcu_wfcq.c index 5a36c76..f04c9bd 100644 --- a/tests/test_urcu_wfcq.c +++ b/tests/test_urcu_wfcq.c @@ -464,10 +464,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); - tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(3 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(4 * sizeof(*count_dequeuer) * nr_dequeuers); + tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer)); + tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer)); + count_enqueuer = calloc(nr_enqueuers, 3 * sizeof(*count_enqueuer)); + count_dequeuer = calloc(nr_dequeuers, 4 * sizeof(*count_dequeuer)); cds_wfcq_init(&head, &tail); next_aff = 0; diff --git a/tests/test_urcu_wfq.c b/tests/test_urcu_wfq.c index db00d8c..382a1f6 100644 --- a/tests/test_urcu_wfq.c +++ b/tests/test_urcu_wfq.c @@ -322,10 +322,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); - tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); + tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer)); + tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer)); + count_enqueuer = calloc(nr_enqueuers, 2 * sizeof(*count_enqueuer)); + count_dequeuer = calloc(nr_dequeuers, 2 * sizeof(*count_dequeuer)); cds_wfq_init(&q); next_aff = 0; diff --git a/tests/test_urcu_wfs.c b/tests/test_urcu_wfs.c index 2a031fe..0fe7d4c 100644 --- a/tests/test_urcu_wfs.c +++ b/tests/test_urcu_wfs.c @@ -452,10 +452,10 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, tid %lu\n", "main", urcu_get_thread_id()); - tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); - tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); - count_enqueuer = malloc(3 * sizeof(*count_enqueuer) * nr_enqueuers); - count_dequeuer = malloc(4 * sizeof(*count_dequeuer) * nr_dequeuers); + tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer)); + tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer)); + count_enqueuer = calloc(nr_enqueuers, 3 * sizeof(*count_enqueuer)); + count_dequeuer = calloc(nr_dequeuers, 4 * sizeof(*count_dequeuer)); cds_wfs_init(&s); next_aff = 0;