diff options
author | David Robillard <d@drobilla.net> | 2020-08-13 17:25:46 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-13 17:25:46 +0200 |
commit | 15efd87598d434d8ee7dc45af3da70ba5ad6c312 (patch) | |
tree | ef99fc34534e4ccdac23a41c7bf55df46945f676 | |
parent | 84addbedee65322625a101f1cf5a97860a26b1ef (diff) | |
download | zix-15efd87598d434d8ee7dc45af3da70ba5ad6c312.tar.gz zix-15efd87598d434d8ee7dc45af3da70ba5ad6c312.tar.bz2 zix-15efd87598d434d8ee7dc45af3da70ba5ad6c312.zip |
Fix Wno-shorten-64-to-32 warnings
-rw-r--r-- | test/btree_test.c | 2 | ||||
-rw-r--r-- | test/sorted_array_test.c | 9 | ||||
-rw-r--r-- | test/tree_bench.c | 8 | ||||
-rw-r--r-- | test/tree_test.c | 11 | ||||
-rw-r--r-- | wscript | 1 | ||||
-rw-r--r-- | zix/ampatree.c | 6 | ||||
-rw-r--r-- | zix/patree.c | 8 | ||||
-rw-r--r-- | zix/trie.c | 4 |
8 files changed, 25 insertions, 24 deletions
diff --git a/test/btree_test.c b/test/btree_test.c index 1b900fe..8d687dc 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -452,7 +452,7 @@ main(int argc, char** argv) } const unsigned n_tests = 3; - unsigned n_elems = (argc > 1) ? atol(argv[1]) : 524288U; + unsigned n_elems = (argc > 1) ? (unsigned)atol(argv[1]) : 524288u; printf("Running %u tests with %u elements", n_tests, n_elems); for (unsigned i = 0; i < n_tests; ++i) { diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c index ca4eac7..30ff139 100644 --- a/test/sorted_array_test.c +++ b/test/sorted_array_test.c @@ -36,7 +36,8 @@ int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) { const intptr_t ia = *(const intptr_t*)a; const intptr_t ib = *(const intptr_t*)b; - return ia - ib; + + return ia < ib ? -1 : ia > ib ? 1 : 0; } static intptr_t @@ -152,11 +153,11 @@ main(int argc, char** argv) if (argc == 1) { n_elems = 4096; } else { - n_elems = atol(argv[1]); + n_elems = (unsigned)atol(argv[1]); if (argc > 2) { - seed = atol(argv[2]); + seed = (unsigned)atol(argv[2]); } else { - seed = time(NULL); + seed = (unsigned)time(NULL); } } diff --git a/test/tree_bench.c b/test/tree_bench.c index 3a7e601..9e58c8d 100644 --- a/test/tree_bench.c +++ b/test/tree_bench.c @@ -30,17 +30,17 @@ // #define BENCH_SORTED_ARRAY 1 // Return a pseudo-pseudo-pseudo-random-ish integer with no duplicates -static uint32_t -unique_rand(uint32_t i) +static size_t +unique_rand(size_t i) { i ^= 0x5CA1AB1E; // Juggle bits to avoid linear clumps // Largest prime < 2^32 which satisfies (2^32 = 3 mod 4) - static const uint32_t prime = 4294967291; + static const size_t prime = 4294967291; if (i >= prime) { return i; // Values >= prime are mapped to themselves } else { - const uint32_t residue = ((uint64_t)i * i) % prime; + const size_t residue = ((uint64_t)i * i) % prime; return (i <= prime / 2) ? residue : prime - residue; } } diff --git a/test/tree_test.c b/test/tree_test.c index 1aebb50..5331344 100644 --- a/test/tree_test.c +++ b/test/tree_test.c @@ -37,11 +37,12 @@ int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) { const intptr_t ia = (intptr_t)a; const intptr_t ib = (intptr_t)b; - return ia - ib; + + return ia < ib ? -1 : ia > ib ? 1 : 0; } static uintptr_t -ith_elem(int test_num, size_t n_elems, int i) +ith_elem(int test_num, size_t n_elems, size_t i) { switch (test_num % 3) { case 0: @@ -203,11 +204,11 @@ main(int argc, char** argv) if (argc == 1) { n_elems = 100000; } else { - n_elems = atol(argv[1]); + n_elems = (unsigned)atol(argv[1]); if (argc > 2) { - seed = atol(argv[2]); + seed = (unsigned)atol(argv[2]); } else { - seed = time(NULL); + seed = (unsigned)time(NULL); } } @@ -45,7 +45,6 @@ def configure(conf): '-Wno-implicit-int-conversion', '-Wno-padded', '-Wno-reserved-id-macro', - '-Wno-shorten-64-to-32', '-Wno-sign-conversion', ], 'gcc': [ diff --git a/zix/ampatree.c b/zix/ampatree.c index 58d1332..55b79c9 100644 --- a/zix/ampatree.c +++ b/zix/ampatree.c @@ -98,7 +98,7 @@ zix_ampatree_node_size(n_edges_t n_children) } ZIX_PRIVATE ZixAMPatreeNode* -realloc_node(ZixAMPatreeNode* n, int n_children) +realloc_node(ZixAMPatreeNode* n, n_edges_t n_children) { return (ZixAMPatreeNode*)realloc(n, zix_ampatree_node_size(n_children)); } @@ -171,7 +171,7 @@ patree_add_edge(ZixAMPatreeNode** n_ptr, child->str = str; child->n_children = 0; - n = (ZixAMPatreeNode*)realloc_node(n, n->n_children + 1); + n = (ZixAMPatreeNode*)realloc_node(n, n->n_children + 1u); ZixAMPatreeNode* m = (ZixAMPatreeNode*)malloc(zix_ampatree_node_size(n->n_children + 1)); m->label_first = n->label_first; m->label_last = n->label_last; @@ -292,7 +292,7 @@ zix_ampatree_find(const ZixAMPatree* t, const char* const str, const char** matc /* Prefix compare search string and label */ const uint8_t* const l = child->label_first; const size_t len = child->label_last - l + 1; - const int change_index = zix_trie_change_index(p, l, len); + const size_t change_index = zix_trie_change_index(p, l, len); p += change_index; diff --git a/zix/patree.c b/zix/patree.c index f984005..54a5637 100644 --- a/zix/patree.c +++ b/zix/patree.c @@ -48,8 +48,8 @@ struct _ZixPatree { }; /** Round `size` up to the next multiple of the word size. */ -ZIX_PRIVATE uint32_t -zix_patree_pad(uint32_t size) +ZIX_PRIVATE n_edges_t +zix_patree_pad(n_edges_t size) { return (size + sizeof(void*) - 1) & (~(sizeof(void*) - 1)); } @@ -112,7 +112,7 @@ zix_patree_node_size(n_edges_t n_children) } ZIX_PRIVATE ZixPatreeNode* -realloc_node(ZixPatreeNode* n, int n_children) +realloc_node(ZixPatreeNode* n, n_edges_t n_children) { return (ZixPatreeNode*)realloc(n, zix_patree_node_size(n_children)); } @@ -186,7 +186,7 @@ patree_add_edge(ZixPatreeNode** n_ptr, child->str = str; child->n_children = 0; - n = realloc_node(n, n->n_children + 1); + n = realloc_node(n, n->n_children + 1u); #ifdef ZIX_TRIE_LINEAR_SEARCH memmove(n->children + zix_patree_pad(n->n_children + 1), n->children + zix_patree_pad(n->n_children), @@ -47,8 +47,8 @@ struct _ZixTrie { }; /** Round `size` up to the next multiple of the word size. */ -ZIX_PRIVATE uint32_t -zix_trie_pad(uint32_t size) +ZIX_PRIVATE n_edges_t +zix_trie_pad(n_edges_t size) { return (size + sizeof(void*) - 1) & (~(sizeof(void*) - 1)); } |