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:31:57 +0000 (15:31 -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 4a6912f1812283b590ee7df5f9384c91fd34e964..41b13d8b98f1eb21064cc9a4abf806abbc1cd283 100644 (file)
@@ -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;
 
index 655c2873533d85b6ea9b3bc08fb81cdbc3068747..4996e7f0c0d395ce70cc26774c9906b4daab8b5f 100644 (file)
@@ -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)
index d0cc11c3841df70e08a1718417cc9e9c134d1116..e61fe94519c54b423e392465009f6c7252ad1b38 100644 (file)
@@ -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(),
index 6c137cb1b1f9af05ac1308aa4ea22db74c1f2881..298904077143239678f2ca33a929054862649734 100644 (file)
@@ -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;
 
index bc7737002596a5856f278b5fcd1898292d069c83..69a8850fafa48b1d7ed80c525f4ae11b86bf0cfc 100644 (file)
@@ -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(),
index 62dfa1848e8435fd4f59c2cd498f24f939cefd7e..b342f41a2e53024dc61a1b2601776cefc6756a43 100644 (file)
@@ -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;
 
index 74c6b196e0ff6e81935ed6311bb70a874b586a01..6e12b181450dac9d4e8683b86a3f4989ca8f56cd 100644 (file)
@@ -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;
 
index 30c79c17e32113a2c85ec219beb60c1b0f301528..75b60156812fdbadc4793b2cdb2f5d7728d9c297 100644 (file)
@@ -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;
 
index b759e846b982fd8c0ef696bacfb9a068d0447f32..0bf4f813952131945efd06f3d487a56b9b8295e8 100644 (file)
@@ -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;
 
index 498abc60817a7c03c6214bdd14e2b331cb6b6cd6..62e7039cc4388f58efef7271f21a231158ef0eed 100644 (file)
@@ -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++)
index a2b5b7bca656902dc11b3d3e3d2902a8235df0c0..d5df1eb8ee352d872782867d4932d674bfde7123 100644 (file)
@@ -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) {
index f8dafab479165050f4679b2f1e9cc6aca2122013..67d676561d0a8f90523f29aae0cb43a5ad60eb70 100644 (file)
@@ -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) {
index 4d6925b8257dbc269ae2a1f08ad1048172a9e676..5c350eb470adf8c7e2348dc05c2fe765628ca4c8 100644 (file)
@@ -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");
index b6d830c28e0be6e2e031ca2234f86070d9231c91..68575815fce2b96664cb587a58d7c49722de7164 100644 (file)
@@ -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) {
index 6c47b720e8ee944bcfa9572a29c4fe84eb33942e..b3cad835aba53b65144a66ae44104cafde45882b 100644 (file)
@@ -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;
 
index 76fe4b7817eb6471f69faba64dd2829772cbd533..2a9677cda8c65526f7d5497341ec746b482d4432 100644 (file)
@@ -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++)
index b50c95f3f82bdfd3010499291246d084c371c0b0..ff4ba6e3b63d5988de0f7be95626d3aae58c7987 100644 (file)
@@ -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(),
index 4de8896b77d024abe2d11b43ba5b9414f1bbbef3..c0315c158cbeea73ec72e0db30a6072ab8f7892b 100644 (file)
@@ -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(),
index 124968d3ec702fd89368edc8ecf565710f771f0f..fe61027f60c95c48b2b7cc4e138bcced494c4c07 100644 (file)
@@ -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;
index 7cadae17641bb2eac17180389c82f354f40db8c0..5eeaa3c940522fcd574175498a82f9d3be5a89a4 100644 (file)
@@ -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;
index c0c55998873c859eed8d697eb97ce9702d036b02..9b6781389d8fdcf3a005fbdbae89a166150adad8 100644 (file)
@@ -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;
This page took 0.036435 seconds and 4 git commands to generate.