summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/btree_test.c26
-rw-r--r--test/sorted_array_test.c2
-rw-r--r--test/tree_test.c2
-rw-r--r--wscript1
-rw-r--r--zix/bitset.c2
-rw-r--r--zix/btree.c10
-rw-r--r--zix/sorted_array.c14
-rw-r--r--zix/trie.c2
-rw-r--r--zix/trie_util.h4
9 files changed, 32 insertions, 31 deletions
diff --git a/test/btree_test.c b/test/btree_test.c
index 488fbf7..3b41984 100644
--- a/test/btree_test.c
+++ b/test/btree_test.c
@@ -36,8 +36,8 @@
static bool expect_failure = false;
// Return a pseudo-pseudo-pseudo-random-ish integer with no duplicates
-static uint32_t
-unique_rand(uint32_t i)
+static uintptr_t
+unique_rand(size_t i)
{
i ^= 0x00005CA1E; // Juggle bits to avoid linear clumps
@@ -46,7 +46,7 @@ unique_rand(uint32_t i)
if (i >= prime) {
return i; // Values >= prime are mapped to themselves
} else {
- const uint32_t residue = ((uint64_t)i * i) % prime;
+ const uint64_t residue = ((uint64_t)i * i) % prime;
return (i <= prime / 2) ? residue : prime - residue;
}
}
@@ -66,8 +66,8 @@ int_cmp(const void* a, const void* b, ZIX_UNUSED const void* user_data)
}
}
-static uint32_t
-ith_elem(int test_num, size_t n_elems, int i)
+static uintptr_t
+ith_elem(const unsigned test_num, const size_t n_elems, const size_t i)
{
switch (test_num % 3) {
case 0: return i + 1; // Increasing
@@ -76,17 +76,17 @@ ith_elem(int test_num, size_t n_elems, int i)
}
}
-static void destroy(void* ptr)
+static void destroy(ZIX_UNUSED void* ptr)
{
}
typedef struct {
- int test_num;
- size_t n_elems;
+ unsigned test_num;
+ size_t n_elems;
} TestContext;
-static uint32_t
-wildcard_cut(int test_num, size_t n_elems)
+static uintptr_t
+wildcard_cut(unsigned test_num, size_t n_elems)
{
return ith_elem(test_num, n_elems, n_elems / 3);
}
@@ -95,9 +95,9 @@ wildcard_cut(int test_num, size_t n_elems)
static int
wildcard_cmp(const void* a, const void* b, const void* user_data)
{
- const TestContext* ctx = (TestContext*)user_data;
+ const TestContext* ctx = (const TestContext*)user_data;
const size_t n_elems = ctx->n_elems;
- const int test_num = ctx->test_num;
+ const unsigned test_num = ctx->test_num;
const uintptr_t ia = (uintptr_t)a;
const uintptr_t ib = (uintptr_t)b;
if (ia == 0) {
@@ -133,7 +133,7 @@ test_fail(ZixBTree* t, const char* fmt, ...)
}
static int
-stress(const int test_num, const size_t n_elems)
+stress(const unsigned test_num, const size_t n_elems)
{
assert(n_elems > 0);
diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c
index 5ebe8e8..519ccb2 100644
--- a/test/sorted_array_test.c
+++ b/test/sorted_array_test.c
@@ -39,7 +39,7 @@ int_cmp(const void* a, const void* b, ZIX_UNUSED const void* user_data)
return ia - ib;
}
-static int
+static uintptr_t
ith_elem(int test_num, unsigned n_elems, int i)
{
switch (test_num % 3) {
diff --git a/test/tree_test.c b/test/tree_test.c
index 07f59c1..1389359 100644
--- a/test/tree_test.c
+++ b/test/tree_test.c
@@ -40,7 +40,7 @@ int_cmp(const void* a, const void* b, ZIX_UNUSED const void* user_data)
return ia - ib;
}
-static int
+static uintptr_t
ith_elem(int test_num, size_t n_elems, int i)
{
switch (test_num % 3) {
diff --git a/wscript b/wscript
index 76a9901..f9b7cf2 100644
--- a/wscript
+++ b/wscript
@@ -39,6 +39,7 @@ def configure(conf):
if Options.options.ultra_strict and not conf.env.MSVC_COMPILER:
conf.env.append_value('CFLAGS', ['-Wunused-parameter'])
+ conf.env.append_value('CFLAGS', ['-Wsign-conversion'])
# Check for mlock
conf.check_function('c', 'mlock',
diff --git a/zix/bitset.c b/zix/bitset.c
index e5f8348..2f551b2 100644
--- a/zix/bitset.c
+++ b/zix/bitset.c
@@ -103,7 +103,7 @@ zix_bitset_count_up_to_if(const ZixBitset* b, const ZixBitsetTally* t, size_t i)
if (extra) {
const ZixBitset mask = ~(~(ZixBitset)0 << extra);
- count += __builtin_popcountl(b[full_elems] & mask);
+ count += (size_t)__builtin_popcountl(b[full_elems] & mask);
}
return count;
diff --git a/zix/btree.c b/zix/btree.c
index de5d777..9990b18 100644
--- a/zix/btree.c
+++ b/zix/btree.c
@@ -170,7 +170,7 @@ zix_btree_max_vals(const ZixBTreeNode* const node)
ZIX_PRIVATE uint16_t
zix_btree_min_vals(const ZixBTreeNode* const node)
{
- return ((zix_btree_max_vals(node) + 1U) / 2U) - 1U;
+ return (uint16_t)(((zix_btree_max_vals(node) + 1U) / 2U) - 1U);
}
/** Shift pointers in `array` of length `n` right starting at `i`. */
@@ -212,7 +212,7 @@ zix_btree_split_child(ZixBTreeNode* const n,
// LHS and RHS get roughly half, less the middle value which moves up
lhs->n_vals = max_n_vals / 2U;
- rhs->n_vals = max_n_vals - lhs->n_vals - 1U;
+ rhs->n_vals = (uint16_t)(max_n_vals - lhs->n_vals - 1);
// Copy large half of values from LHS to new RHS node
memcpy(rhs->vals,
@@ -223,7 +223,7 @@ zix_btree_split_child(ZixBTreeNode* const n,
if (!lhs->is_leaf) {
memcpy(rhs->children,
lhs->children + lhs->n_vals + 1,
- (rhs->n_vals + 1) * sizeof(ZixBTreeNode*));
+ (rhs->n_vals + 1U) * sizeof(ZixBTreeNode*));
}
// Move middle value up to parent
@@ -416,9 +416,9 @@ zix_btree_merge(ZixBTree* const t, ZixBTreeNode* const n, const unsigned i)
if (!lhs->is_leaf) {
memcpy(lhs->children + lhs->n_vals,
rhs->children,
- (rhs->n_vals + 1) * sizeof(void*));
+ (rhs->n_vals + 1U) * sizeof(void*));
}
- lhs->n_vals += rhs->n_vals;
+ lhs->n_vals = (uint16_t)(lhs->n_vals + rhs->n_vals);
if (--n->n_vals == 0) {
// Root is now empty, replace it with its only child
diff --git a/zix/sorted_array.c b/zix/sorted_array.c
index 8929d35..b2096b2 100644
--- a/zix/sorted_array.c
+++ b/zix/sorted_array.c
@@ -97,7 +97,7 @@ zix_sorted_array_insert(ZixSortedArray* a,
zix_sorted_array_find(a, e, ai);
assert(*ai);
- const size_t i = ((char*)*ai - (char*)a->array) / a->elem_size;
+ const size_t i = (size_t)((char*)*ai - (char*)a->array) / a->elem_size;
a->array = realloc(a->array, ++a->num_elems * a->elem_size);
memmove((char*)a->array + ((i + 1) * a->elem_size),
@@ -116,7 +116,7 @@ ZIX_API
ZixStatus
zix_sorted_array_remove(ZixSortedArray* a, ZixSortedArrayIter ai)
{
- const size_t i = ((char*)ai - (char*)a->array) / a->elem_size;
+ const size_t i = (size_t)((char*)ai - (char*)a->array) / a->elem_size;
memmove((char*)a->array + (i * a->elem_size),
(char*)a->array + ((i + 1) * a->elem_size),
(a->num_elems - i - 1) * a->elem_size);
@@ -148,12 +148,12 @@ zix_sorted_array_find(const ZixSortedArray* a,
const void* e,
ZixSortedArrayIter* ai)
{
- intptr_t lower = 0;
- intptr_t upper = a->num_elems - 1;
+ uintptr_t lower = 0;
+ uintptr_t upper = (uintptr_t)a->num_elems - 1;
while (upper >= lower) {
- const intptr_t i = lower + ((upper - lower) / 2);
- void* const elem_i = zix_sorted_array_index_unchecked(a, i);
- const int cmp = a->cmp(elem_i, e, a->cmp_data);
+ const uintptr_t i = lower + ((upper - lower) / 2);
+ void* const elem_i = zix_sorted_array_index_unchecked(a, i);
+ const int cmp = a->cmp(elem_i, e, a->cmp_data);
if (cmp == 0) {
*ai = elem_i;
diff --git a/zix/trie.c b/zix/trie.c
index 9942206..e942cff 100644
--- a/zix/trie.c
+++ b/zix/trie.c
@@ -101,7 +101,7 @@ zix_trie_node_size(n_edges_t num_children)
}
ZIX_PRIVATE ZixTrieNode*
-realloc_node(ZixTrieNode* n, int num_children)
+realloc_node(ZixTrieNode* n, n_edges_t num_children)
{
return (ZixTrieNode*)realloc(n, zix_trie_node_size(num_children));
}
diff --git a/zix/trie_util.h b/zix/trie_util.h
index e21d9d6..ed429b3 100644
--- a/zix/trie_util.h
+++ b/zix/trie_util.h
@@ -42,7 +42,7 @@ zix_trie_find_key(const uint8_t* const keys, const size_t n, const uint8_t k)
#else
/** Return the index of the first element in `keys` >= `k`, or `n`. */
-ZIX_PRIVATE size_t
+static inline size_t
zix_trie_find_key(const uint8_t* const keys, const size_t n, const uint8_t k)
{
size_t first = 0;
@@ -111,7 +111,7 @@ zix_trie_change_index_sse(const uint8_t* a, const uint8_t* b, const size_t len)
#endif
-ZIX_PRIVATE size_t
+static inline size_t
zix_trie_change_index(const uint8_t* a, const uint8_t* b, const size_t len)
{
#ifdef __SSE4_2__