Fix tests: use of uninitialized variables
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 4 Jul 2013 19:23:22 +0000 (15:23 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 4 Jul 2013 19:23:22 +0000 (15:23 -0400)
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 <mathieu.desnoyers@efficios.com>
21 files changed:
tests/test_mutex.c
tests/test_perthreadlock.c
tests/test_perthreadlock_timing.c
tests/test_rwlock.c
tests/test_rwlock_timing.c
tests/test_urcu.c
tests/test_urcu_assign.c
tests/test_urcu_bp.c
tests/test_urcu_defer.c
tests/test_urcu_gc.c
tests/test_urcu_hash.c
tests/test_urcu_lfq.c
tests/test_urcu_lfs.c
tests/test_urcu_lfs_rcu.c
tests/test_urcu_qsbr.c
tests/test_urcu_qsbr_gc.c
tests/test_urcu_qsbr_timing.c
tests/test_urcu_timing.c
tests/test_urcu_wfcq.c
tests/test_urcu_wfq.c
tests/test_urcu_wfs.c

index 83adfdbcb75a7fd0d8159728adc46447db835794..2f25454bd395df3a0f9aebade45fbe8aba58c193 100644 (file)
@@ -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;
 
index be6e59d557c9be527a0eeb1b671f4e4cf8dbdd48..39e2febb8f053cc9f82a3facfda956eacc62ecfa 100644 (file)
@@ -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)
index 9321f034f1221882c0dfc307033c3fc514d90473..97bdd044eae4d231621456efbd4b010b3d72c1aa 100644 (file)
@@ -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());
index 287b14eda2aeabcf3e5689d0857e00cee6971b5c..5a0e8c190410c7e2402cc411f650f4a1ee740cd4 100644 (file)
@@ -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;
 
index 3ff7ee42eb6d455063c3f766c35b221370356612..d916071f61b459f9ea4f8ea24ec74445cd2b6e9c 100644 (file)
@@ -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());
index 3017e812aa4687bfb5eae21178ff2d45434aee47..27648786bd27eb77ec974d245f39cf5abd8b4620 100644 (file)
@@ -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;
 
index 67253da34dc6023d80e500924d41427898900405..dc6bf2f8c852c3048de59f4c71dc04b35962550e 100644 (file)
@@ -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;
 
index a0d6f117bdb811f1a356797c6ab6155f0104dc8f..9ec5f3edf2e49a2bada79d91c616cbfb0230059c 100644 (file)
@@ -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;
 
index 395014e72153800c58fe8b80e9faa61d572b4d24..4e785c4beca4f0d4c9501a14d1203b58ce417fc8 100644 (file)
@@ -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;
 
index 6e5cc1d90a2dd65eea3a58b362f2ee50b3246802..5c57f3fbb33f8899d5abd5efda249ed53ca7c245 100644 (file)
@@ -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++)
index 9416224d8af115491d689ff4328078482591d78c..f862adbf92c58d827dfaf0fc1601ebe5a1c4b212 100644 (file)
@@ -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;
index 52ca22557c7e6e8a3f52284873ca1b8ffe5295af..5717f236af37aedba5a0980cffd758a112d30545 100644 (file)
@@ -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) {
index b2a33712a5aefa488d69bfc746291c72471cd463..5659d9a750638f099b3acdbaa05666e0c857571d 100644 (file)
@@ -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) {
index 89077dc7bb4a3670a2b72810461ab60280d599ff..b76bde159e5333dfaaa26312ec19a2d154a45f44 100644 (file)
@@ -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) {
index 2e9e2b2c409a120bb0fee68f9eb6521b175062d5..85d8430c5f7a8cadd28519c14a4846139f01f612 100644 (file)
@@ -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;
 
index 64d2e2431d0447a041e5edc90eb2ab79a73e73fa..e0a2004f09d253f57a49babc749abd0cc9b80c15 100644 (file)
@@ -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++)
index bb29301da20fd13c57ffc121034d7a34db8184fa..9b5195d9605e4ba914cf76cdeab14f2c63019c12 100644 (file)
@@ -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());
index 4fbdcca8f594f5681696609e75ce110d28e6e7e9..e31b676ca506adf3dac9d20bdee7c6fba01a47fb 100644 (file)
@@ -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());
index 5a36c76f24e73739cd090438934d708b152b251f..f04c9bd8b6874424bf830f722787c6e531e415eb 100644 (file)
@@ -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;
index db00d8c77c36f1d73dfa7cc57ddb4c9ce958d488..382a1f6f38abb54926b1d0d0a563ca6564999f01 100644 (file)
@@ -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;
index 2a031fe25850cc62d3943e77f05a83cd6c1ddd69..0fe7d4c708292822ff2ad01734a41ff6e723e1ae 100644 (file)
@@ -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;
This page took 0.037409 seconds and 4 git commands to generate.