From 4aafa4a63ad9b86b3910e4f3607792ebe45bb329 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Aug 2020 17:25:44 +0200 Subject: Fix incorrect format specifiers --- test/bitset_test.c | 2 +- test/btree_test.c | 65 +++++++++++++++++++++++++----------------------- test/dict_bench.c | 4 ++- test/hash_test.c | 2 +- test/ring_test.c | 12 ++++----- test/sorted_array_test.c | 2 +- test/tree_bench.c | 24 +++++++++--------- test/tree_test.c | 2 +- wscript | 2 -- 9 files changed, 59 insertions(+), 56 deletions(-) diff --git a/test/bitset_test.c b/test/bitset_test.c index 3ac1bb7..554e238 100644 --- a/test/bitset_test.c +++ b/test/bitset_test.c @@ -71,7 +71,7 @@ main(void) } const size_t count = zix_bitset_count_up_to(b, t, i); if (count != 0) { - return test_fail("Count to %zu is %zu != %zu\n", i, count, 0); + return test_fail("Count to %zu is %zu != %d\n", i, count, 0); } } diff --git a/test/btree_test.c b/test/btree_test.c index 974a987..1b900fe 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -22,17 +22,12 @@ #include #include +#include #include #include #include #include -#ifdef _MSC_VER -# define PRIdPTR "Id" -#else -# include -#endif - static bool expect_failure = false; // Return a pseudo-pseudo-pseudo-random-ish integer with no duplicates @@ -167,9 +162,9 @@ stress(const unsigned test_num, const size_t n_elems) for (size_t i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems, i); if (!zix_btree_find(t, (void*)r, &ti)) { - return test_fail(t, "%lu already in tree\n", (uintptr_t)r); + return test_fail(t, "%" PRIuPTR " already in tree\n", (uintptr_t)r); } else if ((st = zix_btree_insert(t, (void*)r))) { - return test_fail(t, "Insert %lu failed (%s)\n", + return test_fail(t, "Insert %" PRIuPTR " failed (%s)\n", (uintptr_t)r, zix_strerror(st)); } } @@ -199,9 +194,9 @@ stress(const unsigned test_num, const size_t n_elems) for (size_t i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems, i); if (zix_btree_find(t, (void*)r, &ti)) { - return test_fail(t, "Find %lu @ %zu failed\n", (uintptr_t)r, i); + return test_fail(t, "Find %" PRIuPTR " @ %zu failed\n", (uintptr_t)r, i); } else if ((uintptr_t)zix_btree_get(ti) != r) { - return test_fail(t, "Search data corrupt (%" PRIdPTR " != %" PRIdPTR ")\n", + return test_fail(t, "Search data corrupt (%" PRIuPTR " != %" PRIuPTR ")\n", (uintptr_t)zix_btree_get(ti), r); } zix_btree_iter_free(ti); @@ -215,11 +210,13 @@ stress(const unsigned test_num, const size_t n_elems) for (size_t i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems, i); if (zix_btree_lower_bound(t, (void*)r, &ti)) { - return test_fail(t, "Lower bound %lu @ %zu failed\n", (uintptr_t)r, i); + return test_fail(t, "Lower bound %" PRIuPTR " @ %zu failed\n", + (uintptr_t)r, i); } else if (zix_btree_iter_is_end(ti)) { - return test_fail(t, "Lower bound %lu @ %zu hit end\n", (uintptr_t)r, i); + return test_fail(t, "Lower bound %" PRIuPTR " @ %zu hit end\n", + (uintptr_t)r, i); } else if ((uintptr_t)zix_btree_get(ti) != r) { - return test_fail(t, "Lower bound corrupt (%" PRIdPTR " != %" PRIdPTR "\n", + return test_fail(t, "Lower bound corrupt (%" PRIuPTR " != %" PRIuPTR "\n", (uintptr_t)zix_btree_get(ti), r); } zix_btree_iter_free(ti); @@ -229,7 +226,8 @@ stress(const unsigned test_num, const size_t n_elems) for (size_t i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems * 3, n_elems + i); if (!zix_btree_find(t, (void*)r, &ti)) { - return test_fail(t, "Unexpectedly found %lu\n", (uintptr_t)r); + return test_fail(t, "Unexpectedly found %" PRIuPTR "\n", + (uintptr_t)r); } } @@ -241,7 +239,7 @@ stress(const unsigned test_num, const size_t n_elems) zix_btree_iter_increment(ti), ++i) { const uintptr_t iter_data = (uintptr_t)zix_btree_get(ti); if (iter_data < last) { - return test_fail(t, "Iter @ %zu corrupt (%" PRIdPTR " < %" PRIdPTR ")\n", + return test_fail(t, "Iter @ %zu corrupt (%" PRIuPTR " < %" PRIuPTR ")\n", i, iter_data, last); } last = iter_data; @@ -262,13 +260,13 @@ stress(const unsigned test_num, const size_t n_elems) // Search for the middle element then iterate from there r = ith_elem(test_num, n_elems, n_elems / 2); if (zix_btree_find(t, (void*)r, &ti)) { - return test_fail(t, "Find %lu failed\n", (uintptr_t)r); + return test_fail(t, "Find %" PRIuPTR " failed\n", (uintptr_t)r); } last = (uintptr_t)zix_btree_get(ti); zix_btree_iter_increment(ti); for (i = 1; !zix_btree_iter_is_end(ti); zix_btree_iter_increment(ti), ++i) { if ((uintptr_t)zix_btree_get(ti) == last) { - return test_fail(t, "Duplicate element @ %u %" PRIdPTR "\n", i, last); + return test_fail(t, "Duplicate element @ %" PRIuPTR " %" PRIuPTR "\n", i, last); } last = (uintptr_t)zix_btree_get(ti); } @@ -280,15 +278,18 @@ stress(const unsigned test_num, const size_t n_elems) r = ith_elem(test_num, n_elems, e); uintptr_t removed; if (zix_btree_remove(t, (void*)r, (void**)&removed, &next)) { - return test_fail(t, "Error removing item %lu\n", (uintptr_t)r); + return test_fail(t, "Error removing item %" PRIuPTR "\n", + (uintptr_t)r); } else if (removed != r) { - return test_fail(t, "Removed wrong item %lu != %lu\n", + return test_fail(t, + "Removed wrong item %" PRIuPTR " != %" PRIuPTR "\n", removed, (uintptr_t)r); } else if (test_num == 0) { const uintptr_t next_value = ith_elem(test_num, n_elems, e + 1); if (!((zix_btree_iter_is_end(next) && e == n_elems - 1) || (uintptr_t)zix_btree_get(next) == next_value)) { - return test_fail(t, "Delete all next iterator %lu != %lu\n", + return test_fail(t, + "Delete all next iterator %" PRIuPTR " != %" PRIuPTR "\n", (uintptr_t)zix_btree_get(next), next_value); } } @@ -314,7 +315,8 @@ stress(const unsigned test_num, const size_t n_elems) r = ith_elem(test_num, n_elems * 3, n_elems + e); uintptr_t removed; if (!zix_btree_remove(t, (void*)r, (void**)&removed, &next)) { - return test_fail(t, "Non-existant deletion of %lu succeeded\n", (uintptr_t)r); + return test_fail(t, "Non-existant deletion of %" PRIuPTR " succeeded\n", + (uintptr_t)r); } } zix_btree_iter_free(next); @@ -330,15 +332,15 @@ stress(const unsigned test_num, const size_t n_elems) r = ith_elem(test_num, n_elems, n_elems - (n_elems / 4) + e); uintptr_t removed; if (zix_btree_remove(t, (void*)r, (void**)&removed, &next)) { - return test_fail(t, "Deletion of %lu failed\n", (uintptr_t)r); + return test_fail(t, "Deletion of %" PRIuPTR " failed\n", (uintptr_t)r); } else if (removed != r) { - return test_fail(t, "Removed wrong item %lu != %lu\n", + return test_fail(t, "Removed wrong item %" PRIuPTR " != %" PRIuPTR "\n", removed, (uintptr_t)r); } else if (test_num == 0) { const uintptr_t next_value = ith_elem(test_num, n_elems, e + 1); if (!zix_btree_iter_is_end(next) && (uintptr_t)zix_btree_get(next) == next_value) { - return test_fail(t, "Next iterator %lu != %lu\n", + return test_fail(t, "Next iterator %" PRIuPTR " != %" PRIuPTR "\n", (uintptr_t)zix_btree_get(next), next_value); } } @@ -357,7 +359,7 @@ stress(const unsigned test_num, const size_t n_elems) uintptr_t removed; 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 %lu\n", (uintptr_t)r); + return test_fail(t, "Error deleting %" PRIuPTR "\n", (uintptr_t)r); } } zix_btree_iter_free(next); @@ -370,12 +372,13 @@ stress(const unsigned test_num, const size_t n_elems) const uintptr_t value = (uintptr_t)zix_btree_get(next); uintptr_t removed = 0; if (zix_btree_remove(t, zix_btree_get(next), (void**)&removed, &next)) { - return test_fail(t, "Error removing next item %lu\n", (uintptr_t)r); + return test_fail(t, "Error removing next item %" PRIuPTR "\n", + (uintptr_t)r); } else if (removed != value) { - return test_fail(t, "Removed wrong next item %lu != %lu\n", + return test_fail(t, "Removed wrong next item %" PRIuPTR " != %" PRIuPTR "\n", removed, (uintptr_t)value); } else if (removed < last_value) { - return test_fail(t, "Removed unordered next item %lu < %lu\n", + return test_fail(t, "Removed unordered next item %" PRIuPTR " < %" PRIuPTR "\n", removed, (uintptr_t)value); } @@ -399,7 +402,7 @@ stress(const unsigned test_num, const size_t n_elems) r = ith_elem(test_num, n_elems, i); if (r != 0) { // Can't insert wildcards if ((st = zix_btree_insert(t, (void*)r))) { - return test_fail(t, "Insert %lu failed (%s)\n", + return test_fail(t, "Insert %" PRIuPTR " failed (%s)\n", (uintptr_t)r, zix_strerror(st)); } } @@ -417,10 +420,10 @@ stress(const unsigned test_num, const size_t n_elems) const uintptr_t iter_data = (uintptr_t)zix_btree_get(ti); const uintptr_t cut = wildcard_cut(test_num, n_elems); if (iter_data != cut) { - return test_fail(t, "Lower bound %" PRIdPTR " != %" PRIdPTR "\n", + return test_fail(t, "Lower bound %" PRIuPTR " != %" PRIuPTR "\n", iter_data, cut); } else if (wildcard_cmp((void*)wildcard, (void*)iter_data, &ctx)) { - return test_fail(t, "Wildcard lower bound %" PRIdPTR " != %" PRIdPTR "\n", + return test_fail(t, "Wildcard lower bound %" PRIuPTR " != %" PRIuPTR "\n", iter_data, cut); } diff --git a/test/dict_bench.c b/test/dict_bench.c index 21d9cfb..92f2e5e 100644 --- a/test/dict_bench.c +++ b/test/dict_bench.c @@ -187,7 +187,9 @@ main(int argc, char** argv) } if (strcmp((const char*)match->buf, strings[index])) { return test_fail("Hash: Bad match %p for `%s': `%s'\n", - (const void*)match, strings[index], match->buf); + (const void*)match, + strings[index], + (const char*)match->buf); } } fprintf(search_dat, "\t%lf", bench_end(&search_start)); diff --git a/test/hash_test.c b/test/hash_test.c index eeb371d..8b3e9de 100644 --- a/test/hash_test.c +++ b/test/hash_test.c @@ -133,7 +133,7 @@ stress(void) return test_fail("Failed to find `%s'\n", strings[i]); } if (*match != strings[i]) { - return test_fail("Bad match for `%s': `%s'\n", strings[i], match); + return test_fail("Bad match for `%s': `%s'\n", strings[i], *match); } } diff --git a/test/ring_test.c b/test/ring_test.c index 5345754..bf7edd2 100644 --- a/test/ring_test.c +++ b/test/ring_test.c @@ -128,7 +128,7 @@ main(int argc, char** argv) n_writes = (unsigned)atoi(argv[2]); } - printf("Testing %u writes of %d ints to a %d int ring...\n", + printf("Testing %u writes of %d ints to a %u int ring...\n", n_writes, MSG_SIZE, size); ring = zix_ring_new(size); @@ -172,7 +172,7 @@ main(int argc, char** argv) char buf; uint32_t n = zix_ring_peek(ring, &buf, 1); if (n != 1) { - return failure("Peek n (%d) != 1\n", n); + return failure("Peek n (%u) != 1\n", n); } if (buf != 'a') { return failure("Peek error: '%c' != 'a'\n", buf); @@ -180,23 +180,23 @@ main(int argc, char** argv) n = zix_ring_skip(ring, 1); if (n != 1) { - return failure("Skip n (%d) != 1\n", n); + return failure("Skip n (%u) != 1\n", n); } if (zix_ring_read_space(ring) != 1) { - return failure("Read space %d != 1\n", zix_ring_read_space(ring)); + return failure("Read space %u != 1\n", zix_ring_read_space(ring)); } n = zix_ring_read(ring, &buf, 1); if (n != 1) { - return failure("Peek n (%d) != 1\n", n); + return failure("Peek n (%u) != 1\n", n); } if (buf != 'b') { return failure("Peek error: '%c' != 'b'\n", buf); } if (zix_ring_read_space(ring) != 0) { - return failure("Read space %d != 0\n", zix_ring_read_space(ring)); + return failure("Read space %u != 0\n", zix_ring_read_space(ring)); } n = zix_ring_peek(ring, &buf, 1); diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c index a90f1e7..ca4eac7 100644 --- a/test/sorted_array_test.c +++ b/test/sorted_array_test.c @@ -165,7 +165,7 @@ main(int argc, char** argv) return 1; } - printf("Running %u tests with %u elements (seed %d)", + printf("Running %u tests with %u elements (seed %u)", n_tests, n_elems, seed); for (unsigned i = 0; i < n_tests; ++i) { diff --git a/test/tree_bench.c b/test/tree_bench.c index 766402f..3a7e601 100644 --- a/test/tree_bench.c +++ b/test/tree_bench.c @@ -100,7 +100,7 @@ bench_zix_tree(size_t n_elems, r = unique_rand(i); int status = zix_tree_insert(t, (void*)r, &ti); if (status) { - return test_fail("Failed to insert %zu\n", r); + return test_fail("Failed to insert %" PRIdPTR "\n", r); } } fprintf(insert_dat, "\t%lf", bench_end(&insert_start)); @@ -110,10 +110,10 @@ bench_zix_tree(size_t n_elems, for (size_t i = 0; i < n_elems; i++) { r = unique_rand(i); if (zix_tree_find(t, (void*)r, &ti)) { - return test_fail("Failed to find %zu\n", r); + return test_fail("Failed to find %" PRIdPTR "\n", r); } if ((intptr_t)zix_tree_get(ti) != r) { - return test_fail("Failed to get %zu\n", r); + return test_fail("Failed to get %" PRIdPTR "\n", r); } } fprintf(search_dat, "\t%lf", bench_end(&search_start)); @@ -133,10 +133,10 @@ bench_zix_tree(size_t n_elems, r = unique_rand(i); ZixTreeIter* item; if (zix_tree_find(t, (void*)r, &item)) { - return test_fail("Failed to find %zu to delete\n", r); + return test_fail("Failed to find %" PRIdPTR " to delete\n", r); } if (zix_tree_remove(t, item)) { - return test_fail("Failed to remove %zu\n", r); + return test_fail("Failed to remove %" PRIdPTR "\n", r); } } fprintf(del_dat, "\t%lf", bench_end(&del_start)); @@ -162,7 +162,7 @@ bench_zix_btree(size_t n_elems, r = unique_rand(i); int status = zix_btree_insert(t, (void*)r); if (status) { - return test_fail("Failed to insert %zu\n", r); + return test_fail("Failed to insert %" PRIdPTR "\n", r); } } fprintf(insert_dat, "\t%lf", bench_end(&insert_start)); @@ -172,10 +172,10 @@ bench_zix_btree(size_t n_elems, for (size_t i = 0; i < n_elems; i++) { r = unique_rand(i); if (zix_btree_find(t, (void*)r, &ti)) { - return test_fail("Failed to find %zu\n", r); + return test_fail("Failed to find %" PRIdPTR "\n", r); } if ((intptr_t)zix_btree_get(ti) != r) { - return test_fail("Failed to get %zu\n", r); + return test_fail("Failed to get %" PRIdPTR "\n", r); } } fprintf(search_dat, "\t%lf", bench_end(&search_start)); @@ -197,7 +197,7 @@ bench_zix_btree(size_t n_elems, r = unique_rand(i); void* removed; if (zix_btree_remove(t, (void*)r, &removed, NULL)) { - return test_fail("Failed to remove %zu\n", r); + return test_fail("Failed to remove %" PRIdPTR "\n", r); } } fprintf(del_dat, "\t%lf", bench_end(&del_start)); @@ -314,7 +314,7 @@ bench_glib(size_t n_elems, r = unique_rand(i); GSequenceIter* iter = g_sequence_insert_sorted(t, (void*)r, g_int_cmp, NULL); if (!iter || g_sequence_iter_is_end(iter)) { - return test_fail("Failed to insert %zu\n", r); + return test_fail("Failed to insert %" PRIdPTR "\n", r); } } fprintf(insert_dat, "\t%lf", bench_end(&insert_start)); @@ -325,7 +325,7 @@ bench_glib(size_t n_elems, r = unique_rand(i); GSequenceIter* iter = g_sequence_lookup(t, (void*)r, g_int_cmp, NULL); if (!iter || g_sequence_iter_is_end(iter)) { - return test_fail("Failed to find %zu\n", r); + return test_fail("Failed to find %" PRIdPTR "\n", r); } } fprintf(search_dat, "\t%lf", bench_end(&search_start)); @@ -346,7 +346,7 @@ bench_glib(size_t n_elems, GSequenceIter* iter = g_sequence_lookup(t, (void*)r, g_int_cmp, NULL); if (!iter || g_sequence_iter_is_end(iter)) { - return test_fail("Failed to remove %zu\n", r); + return test_fail("Failed to remove %" PRIdPTR "\n", r); } g_sequence_remove(iter); } diff --git a/test/tree_test.c b/test/tree_test.c index 0748142..1aebb50 100644 --- a/test/tree_test.c +++ b/test/tree_test.c @@ -216,7 +216,7 @@ main(int argc, char** argv) return 1; } - printf("Running %u tests with %u elements (seed %d)", + printf("Running %u tests with %u elements (seed %u)", n_tests, n_elems, seed); for (unsigned i = 0; i < n_tests; ++i) { diff --git a/wscript b/wscript index d1b78ef..bdc0fd2 100644 --- a/wscript +++ b/wscript @@ -43,7 +43,6 @@ def configure(conf): '-Wno-atomic-implicit-seq-cst', '-Wno-bad-function-cast', '-Wno-cast-align', - '-Wno-format', '-Wno-implicit-int-conversion', '-Wno-padded', '-Wno-reserved-id-macro', @@ -54,7 +53,6 @@ def configure(conf): '-Wno-bad-function-cast', '-Wno-cast-align', '-Wno-conversion', - '-Wno-format', '-Wno-inline', '-Wno-null-dereference', '-Wno-padded', -- cgit v1.2.1