diff options
author | David Robillard <d@drobilla.net> | 2020-12-31 15:48:28 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-12-31 18:13:35 +0100 |
commit | ad42412e3353893ccb365cf357a286b0afe545ba (patch) | |
tree | a5b1951eeb2d8a396e5d3d33dbf9cee8d326d6b9 | |
parent | a4a67d67cbbed4e027a4587c9956adbd404d097d (diff) | |
download | zix-ad42412e3353893ccb365cf357a286b0afe545ba.tar.gz zix-ad42412e3353893ccb365cf357a286b0afe545ba.tar.bz2 zix-ad42412e3353893ccb365cf357a286b0afe545ba.zip |
Initialize all variables
-rw-r--r-- | .clang-tidy | 1 | ||||
-rw-r--r-- | benchmark/.clang-tidy | 1 | ||||
-rw-r--r-- | benchmark/dict_bench.c | 2 | ||||
-rw-r--r-- | benchmark/tree_bench.c | 6 | ||||
-rw-r--r-- | src/strindex.c | 8 | ||||
-rw-r--r-- | test/.clang-tidy | 1 | ||||
-rw-r--r-- | test/btree_test.c | 14 | ||||
-rw-r--r-- | test/ring_test.c | 8 | ||||
-rw-r--r-- | test/sem_test.c | 4 | ||||
-rw-r--r-- | test/sorted_array_test.c | 7 | ||||
-rw-r--r-- | test/tree_test.c | 10 |
11 files changed, 32 insertions, 30 deletions
diff --git a/.clang-tidy b/.clang-tidy index 34d28eb..817a439 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,6 @@ Checks: > -cert-dcl37-c, -cert-dcl51-cpp, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, - -cppcoreguidelines-init-variables, -hicpp-multiway-paths-covered, -llvmlibc-*, -misc-no-recursion, diff --git a/benchmark/.clang-tidy b/benchmark/.clang-tidy index 17625d5..eab2452 100644 --- a/benchmark/.clang-tidy +++ b/benchmark/.clang-tidy @@ -13,7 +13,6 @@ Checks: > -cert-msc50-cpp, -cert-msc51-cpp, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, - -cppcoreguidelines-init-variables, -hicpp-multiway-paths-covered, -llvm-header-guard, -llvmlibc-*, diff --git a/benchmark/dict_bench.c b/benchmark/dict_bench.c index 0ed794f..23e2f55 100644 --- a/benchmark/dict_bench.c +++ b/benchmark/dict_bench.c @@ -65,7 +65,7 @@ main(int argc, char** argv) char* buf = (char*)calloc(1, 1); size_t buf_len = 1; size_t this_str_len = 0; - for (int c; (c = fgetc(fd)) != EOF;) { + for (int c = 0; (c = fgetc(fd)) != EOF;) { if (isspace(c)) { if (this_str_len == 0) { continue; diff --git a/benchmark/tree_bench.c b/benchmark/tree_bench.c index bcf8699..4d1f30f 100644 --- a/benchmark/tree_bench.c +++ b/benchmark/tree_bench.c @@ -141,7 +141,8 @@ bench_zix_tree(size_t n_elems, struct timespec del_start = bench_start(); for (size_t i = 0; i < n_elems; i++) { r = unique_rand(i); - ZixTreeIter* item; + + ZixTreeIter* item = NULL; if (zix_tree_find(t, (void*)r, &item)) { return test_fail("Failed to find %" PRIdPTR " to delete\n", r); } @@ -207,7 +208,8 @@ bench_zix_btree(size_t n_elems, struct timespec del_start = bench_start(); for (size_t i = 0; i < n_elems; i++) { r = unique_rand(i); - void* removed; + + void* removed = NULL; if (zix_btree_remove(t, (void*)r, &removed, NULL)) { return test_fail("Failed to remove %" PRIdPTR "\n", r); } diff --git a/src/strindex.c b/src/strindex.c index a92b09b..cd1a322 100644 --- a/src/strindex.c +++ b/src/strindex.c @@ -153,8 +153,8 @@ strindex_split_edge(ZixStrindexNode* child, size_t index) static ZixStatus strindex_insert(ZixStrindexNode* n, char* suffix_first, char* first, char* last) { - size_t child_i; - ZixStrindexNode* child; + size_t child_i = 0; + ZixStrindexNode* child = NULL; assert(first <= last); if (strindex_find_edge(n, *first, &child_i)) { @@ -199,8 +199,8 @@ zix_strindex_find(ZixStrindex* strindex, const char* const str, char** match) const char* orig_p = p; #endif - ZixStrindexNode* n = strindex->root; - size_t child_i; + ZixStrindexNode* n = strindex->root; + size_t child_i = 0; *match = NULL; diff --git a/test/.clang-tidy b/test/.clang-tidy index dc7dbc4..ecef880 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -13,7 +13,6 @@ Checks: > -cert-msc50-cpp, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -cppcoreguidelines-avoid-non-const-global-variables, - -cppcoreguidelines-init-variables, -google-readability-casting, -hicpp-multiway-paths-covered, -llvm-header-guard, diff --git a/test/btree_test.c b/test/btree_test.c index 5c32020..8b43aed 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -300,7 +300,8 @@ stress(const unsigned test_num, const size_t n_elems) ZixBTreeIter* next = NULL; for (size_t e = 0; e < n_elems; e++) { r = ith_elem(test_num, n_elems, e); - uintptr_t removed; + + uintptr_t removed = 0; if (zix_btree_remove(t, (void*)r, (void**)&removed, &next)) { return test_fail(t, "Error removing item %" PRIuPTR "\n", (uintptr_t)r); } @@ -342,8 +343,8 @@ stress(const unsigned test_num, const size_t n_elems) // Delete elements that don't exist for (size_t e = 0; e < n_elems; e++) { - r = ith_elem(test_num, n_elems * 3, n_elems + e); - uintptr_t removed; + r = ith_elem(test_num, n_elems * 3, n_elems + e); + uintptr_t removed = 0; if (!zix_btree_remove(t, (void*)r, (void**)&removed, &next)) { return test_fail( t, "Non-existant deletion of %" PRIuPTR " succeeded\n", (uintptr_t)r); @@ -360,7 +361,7 @@ stress(const unsigned test_num, const size_t n_elems) // Delete some elements towards the end for (size_t e = 0; e < n_elems / 4; e++) { r = ith_elem(test_num, n_elems, n_elems - (n_elems / 4) + e); - uintptr_t removed; + uintptr_t removed = 0; if (zix_btree_remove(t, (void*)r, (void**)&removed, &next)) { return test_fail(t, "Deletion of %" PRIuPTR " failed\n", (uintptr_t)r); } @@ -394,8 +395,9 @@ stress(const unsigned test_num, const size_t n_elems) // Delete some elements in a random order for (size_t e = 0; e < zix_btree_size(t) / 2; e++) { r = ith_elem(test_num, n_elems, rand() % n_elems); - uintptr_t removed; - ZixStatus rst = zix_btree_remove(t, (void*)r, (void**)&removed, &next); + + uintptr_t removed = 0; + ZixStatus rst = zix_btree_remove(t, (void*)r, (void**)&removed, &next); if (rst != ZIX_STATUS_SUCCESS && rst != ZIX_STATUS_NOT_FOUND) { return test_fail(t, "Error deleting %" PRIuPTR "\n", (uintptr_t)r); } diff --git a/test/ring_test.c b/test/ring_test.c index 915d099..1a26cd3 100644 --- a/test/ring_test.c +++ b/test/ring_test.c @@ -144,12 +144,12 @@ main(int argc, char** argv) zix_ring_mlock(ring); - ZixThread reader_thread; + ZixThread reader_thread; // NOLINT if (zix_thread_create(&reader_thread, MSG_SIZE * 4, reader, NULL)) { return failure("Failed to create reader thread\n"); } - ZixThread writer_thread; + ZixThread writer_thread; // NOLINT if (zix_thread_create(&writer_thread, MSG_SIZE * 4, writer, NULL)) { return failure("Failed to create writer thread\n"); } @@ -172,8 +172,8 @@ main(int argc, char** argv) zix_ring_write(ring, "a", 1); zix_ring_write(ring, "b", 1); - char buf; - uint32_t n = zix_ring_peek(ring, &buf, 1); + char buf = 0; + uint32_t n = zix_ring_peek(ring, &buf, 1); if (n != 1) { return failure("Peek n (%u) != 1\n", n); } diff --git a/test/sem_test.c b/test/sem_test.c index 5db7c08..a1f2a0e 100644 --- a/test/sem_test.c +++ b/test/sem_test.c @@ -68,13 +68,13 @@ main(int argc, char** argv) return 1; } - ZixThread reader_thread; + ZixThread reader_thread; // NOLINT if (zix_thread_create(&reader_thread, 128, reader, NULL)) { fprintf(stderr, "Failed to create reader thread\n"); return 1; } - ZixThread writer_thread; + ZixThread writer_thread; // NOLINT if (zix_thread_create(&writer_thread, 128, writer, NULL)) { fprintf(stderr, "Failed to create writer thread\n"); return 1; diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c index d991784..a782db4 100644 --- a/test/sorted_array_test.c +++ b/test/sorted_array_test.c @@ -58,8 +58,8 @@ test_fail(void) static int stress(unsigned test_num, unsigned n_elems) { - intptr_t r; - ZixSortedArrayIter ti; + intptr_t r = 0; + ZixSortedArrayIter ti = NULL; ZixSortedArray* t = zix_sorted_array_new(true, int_cmp, NULL, sizeof(intptr_t)); @@ -126,7 +126,8 @@ stress(unsigned test_num, unsigned n_elems) // Delete all elements for (unsigned e = 0; e < n_elems; e++) { r = ith_elem(test_num, n_elems, e); - ZixSortedArrayIter item; + + ZixSortedArrayIter item = NULL; if (zix_sorted_array_find(t, &r, &item) != ZIX_STATUS_SUCCESS) { fprintf(stderr, "Failed to find item to remove\n"); return test_fail(); diff --git a/test/tree_test.c b/test/tree_test.c index 08913e8..d1e710e 100644 --- a/test/tree_test.c +++ b/test/tree_test.c @@ -59,10 +59,9 @@ test_fail(void) static int stress(unsigned test_num, size_t n_elems) { - intptr_t r; - ZixTreeIter* ti; - - ZixTree* t = zix_tree_new(true, int_cmp, NULL, NULL); + intptr_t r = 0; + ZixTreeIter* ti = NULL; + ZixTree* t = zix_tree_new(true, int_cmp, NULL, NULL); srand(seed); @@ -152,7 +151,8 @@ stress(unsigned test_num, size_t n_elems) // Delete all elements for (size_t e = 0; e < n_elems; e++) { r = ith_elem(test_num, n_elems, e); - ZixTreeIter* item; + + ZixTreeIter* item = NULL; if (zix_tree_find(t, (void*)r, &item) != ZIX_STATUS_SUCCESS) { fprintf(stderr, "Failed to find item to remove\n"); return test_fail(); |