From: Mathieu Desnoyers Date: Thu, 4 Jul 2013 19:23:22 +0000 (-0400) Subject: Fix tests: use of uninitialized variables X-Git-Tag: v0.7.8~3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f90535ef41a3ddef0c8bcd76a6ecb89f3fd09fc3;p=urcu.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 4a6912f..41b13d8 100644 --- a/tests/test_mutex.c +++ b/tests/test_mutex.c @@ -357,12 +357,12 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 655c287..4996e7f 100644 --- a/tests/test_perthreadlock.c +++ b/tests/test_perthreadlock.c @@ -364,11 +364,11 @@ int main(int argc, char **argv) printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 d0cc11c..e61fe94 100644 --- a/tests/test_perthreadlock_timing.c +++ b/tests/test_perthreadlock_timing.c @@ -164,10 +164,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, thread id : %lx, tid %lu\n", "main", (unsigned long) pthread_self(), diff --git a/tests/test_rwlock.c b/tests/test_rwlock.c index 6c137cb..2989040 100644 --- a/tests/test_rwlock.c +++ b/tests/test_rwlock.c @@ -353,10 +353,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 bc77370..69a8850 100644 --- a/tests/test_rwlock_timing.c +++ b/tests/test_rwlock_timing.c @@ -155,10 +155,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, thread id : %lx, tid %lu\n", "main", (unsigned long) pthread_self(), diff --git a/tests/test_urcu.c b/tests/test_urcu.c index 62dfa18..b342f41 100644 --- a/tests/test_urcu.c +++ b/tests/test_urcu.c @@ -403,10 +403,10 @@ int main(int argc, char **argv) (unsigned long)gettid()); 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_assign.c b/tests/test_urcu_assign.c index 74c6b19..6e12b18 100644 --- a/tests/test_urcu_assign.c +++ b/tests/test_urcu_assign.c @@ -400,10 +400,10 @@ int main(int argc, char **argv) (unsigned long) gettid()); 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 30c79c1..75b6015 100644 --- a/tests/test_urcu_bp.c +++ b/tests/test_urcu_bp.c @@ -399,10 +399,10 @@ int main(int argc, char **argv) (unsigned long) gettid()); 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_defer.c b/tests/test_urcu_defer.c index b759e84..0bf4f81 100644 --- a/tests/test_urcu_defer.c +++ b/tests/test_urcu_defer.c @@ -388,10 +388,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 498abc6..62e7039 100644 --- a/tests/test_urcu_gc.c +++ b/tests/test_urcu_gc.c @@ -416,11 +416,11 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 a2b5b7b..d5df1eb 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -540,10 +540,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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)); err = create_all_cpu_call_rcu_data(0); if (err) { diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index f8dafab..67d6765 100644 --- a/tests/test_urcu_lfq.c +++ b/tests/test_urcu_lfq.c @@ -375,10 +375,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 4d6925b..5c350eb 100644 --- a/tests/test_urcu_lfs.c +++ b/tests/test_urcu_lfs.c @@ -373,11 +373,12 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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) { printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n"); diff --git a/tests/test_urcu_lfs_rcu.c b/tests/test_urcu_lfs_rcu.c index b6d830c..6857581 100644 --- a/tests/test_urcu_lfs_rcu.c +++ b/tests/test_urcu_lfs_rcu.c @@ -370,10 +370,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 6c47b72..b3cad83 100644 --- a/tests/test_urcu_qsbr.c +++ b/tests/test_urcu_qsbr.c @@ -406,10 +406,10 @@ int main(int argc, char **argv) (unsigned long) gettid()); 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_qsbr_gc.c b/tests/test_urcu_qsbr_gc.c index 76fe4b7..2a9677c 100644 --- a/tests/test_urcu_qsbr_gc.c +++ b/tests/test_urcu_qsbr_gc.c @@ -416,11 +416,11 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 b50c95f..ff4ba6e 100644 --- a/tests/test_urcu_qsbr_timing.c +++ b/tests/test_urcu_qsbr_timing.c @@ -197,10 +197,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, thread id : %lx, tid %lu\n", "main", (unsigned long) pthread_self(), diff --git a/tests/test_urcu_timing.c b/tests/test_urcu_timing.c index 4de8896..c0315c1 100644 --- a/tests/test_urcu_timing.c +++ b/tests/test_urcu_timing.c @@ -195,10 +195,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, thread id : %lx, tid %lu\n", "main", (unsigned long) pthread_self(), diff --git a/tests/test_urcu_wfcq.c b/tests/test_urcu_wfcq.c index 124968d..fe61027 100644 --- a/tests/test_urcu_wfcq.c +++ b/tests/test_urcu_wfcq.c @@ -471,10 +471,11 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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(3 * 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, 3 * 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 7cadae1..5eeaa3c 100644 --- a/tests/test_urcu_wfq.c +++ b/tests/test_urcu_wfq.c @@ -336,10 +336,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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 c0c5599..9b67813 100644 --- a/tests/test_urcu_wfs.c +++ b/tests/test_urcu_wfs.c @@ -336,10 +336,10 @@ int main(int argc, char **argv) "main", (unsigned long) pthread_self(), (unsigned long) gettid()); - 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_wfs_init(&s); next_aff = 0;