From 71c4a3a6d66e96661fd341e1a089c4d8bd63fb13 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 28 Jun 2022 18:48:41 -0400 Subject: Use uppercase integer literal suffixes I give in. --- .clang-tidy | 1 - benchmark/.clang-tidy | 1 - benchmark/dict_bench.c | 12 +++---- benchmark/tree_bench.c | 4 +-- include/.clang-tidy | 2 -- include/zix/btree.h | 6 ++-- src/.clang-tidy | 1 - src/btree.c | 98 +++++++++++++++++++++++++------------------------- src/bump_allocator.c | 6 ++-- src/digest.c | 82 +++++++++++++++++++++--------------------- src/hash.c | 28 +++++++-------- src/ring.c | 10 +++--- test/.clang-tidy | 2 -- test/allocator_test.c | 6 ++-- test/bitset_test.c | 2 +- test/btree_test.c | 52 +++++++++++++-------------- test/digest_test.c | 32 ++++++++--------- test/hash_test.c | 36 +++++++++---------- test/ring_test.c | 12 +++---- test/test_data.h | 12 +++---- test/tree_test.c | 4 +-- 21 files changed, 201 insertions(+), 208 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 723b4f1..8cec0ea 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,7 +4,6 @@ Checks: > *, -*-magic-numbers, - -*-uppercase-literal-suffix, -altera-*, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -hicpp-multiway-paths-covered, diff --git a/benchmark/.clang-tidy b/benchmark/.clang-tidy index 8bbb5c1..01a5eb7 100644 --- a/benchmark/.clang-tidy +++ b/benchmark/.clang-tidy @@ -4,7 +4,6 @@ Checks: > *, -*-magic-numbers, - -*-uppercase-literal-suffix, -altera-*, -android-cloexec-fopen, -bugprone-easily-swappable-parameters, diff --git a/benchmark/dict_bench.c b/benchmark/dict_bench.c index b9c8cc4..82a4b78 100644 --- a/benchmark/dict_bench.c +++ b/benchmark/dict_bench.c @@ -36,8 +36,8 @@ typedef struct { static inline uint64_t lcg64(const uint64_t i) { - static const uint64_t a = 6364136223846793005ull; - static const uint64_t c = 1ull; + static const uint64_t a = 6364136223846793005ULL; + static const uint64_t c = 1ULL; return (a * i) + c; } @@ -51,7 +51,7 @@ identity(const void* record) static size_t zix_chunk_hash(const ZixChunk* const chunk) { - return zix_digest(0u, chunk->buf, chunk->len); + return zix_digest(0U, chunk->buf, chunk->len); } static bool @@ -65,10 +65,10 @@ static const unsigned seed = 1; static Inputs read_inputs(FILE* const fd) { - static const size_t max_n_strings = 1u << 20u; - static const Inputs no_inputs = {NULL, 0u, NULL}; + static const size_t max_n_strings = 1U << 20U; + static const Inputs no_inputs = {NULL, 0U, NULL}; - Inputs inputs = {NULL, 0u, NULL}; + Inputs inputs = {NULL, 0U, NULL}; size_t buf_len = 1; size_t this_str_len = 0; for (int c = 0; (c = fgetc(fd)) != EOF;) { diff --git a/benchmark/tree_bench.c b/benchmark/tree_bench.c index b825d96..1fca1a3 100644 --- a/benchmark/tree_bench.c +++ b/benchmark/tree_bench.c @@ -141,7 +141,7 @@ bench_zix_btree(size_t n_elems, { start_test("ZixBTree"); - uintptr_t r = 0u; + uintptr_t r = 0U; ZixBTreeIter ti = zix_btree_end_iter; ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); @@ -206,7 +206,7 @@ bench_glib(size_t n_elems, { start_test("GSequence"); - uintptr_t r = 0u; + uintptr_t r = 0U; GSequence* t = g_sequence_new(NULL); // Insert n_elems elements diff --git a/include/.clang-tidy b/include/.clang-tidy index 7a48cc4..a644849 100644 --- a/include/.clang-tidy +++ b/include/.clang-tidy @@ -3,12 +3,10 @@ Checks: > *, - -*-uppercase-literal-suffix, -altera-*, -clang-diagnostic-unused-function, -clang-diagnostic-unused-macros, -hicpp-multiway-paths-covered, - -hicpp-uppercase-literal-suffix, -llvmlibc-*, WarningsAsErrors: '*' HeaderFilterRegex: '.*' diff --git a/include/zix/btree.h b/include/zix/btree.h index 92e5c5f..24a0171 100644 --- a/include/zix/btree.h +++ b/include/zix/btree.h @@ -33,7 +33,7 @@ extern "C" { height of 6 is enough to store trillions. */ #ifndef ZIX_BTREE_MAX_HEIGHT -# define ZIX_BTREE_MAX_HEIGHT 6u +# define ZIX_BTREE_MAX_HEIGHT 6U #endif /// A B-Tree @@ -60,8 +60,8 @@ typedef struct { /// A static end iterator for convenience static const ZixBTreeIter zix_btree_end_iter = { {NULL, NULL, NULL, NULL, NULL, NULL}, - {0u, 0u, 0u, 0u, 0u, 0u}, - 0u}; + {0U, 0U, 0U, 0U, 0U, 0U}, + 0U}; /** Create a new (empty) B-Tree. diff --git a/src/.clang-tidy b/src/.clang-tidy index 8c165a5..98a0bc8 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -4,7 +4,6 @@ Checks: > *, -*-magic-numbers, - -*-uppercase-literal-suffix, -altera-*, -bugprone-easily-swappable-parameters, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, diff --git a/src/btree.c b/src/btree.c index 9bb0904..f0060c3 100644 --- a/src/btree.c +++ b/src/btree.c @@ -17,12 +17,12 @@ typedef uint16_t ZixShort; #endif #ifndef ZIX_BTREE_PAGE_SIZE -# define ZIX_BTREE_PAGE_SIZE 4096u +# define ZIX_BTREE_PAGE_SIZE 4096U #endif -#define ZIX_BTREE_NODE_SPACE (ZIX_BTREE_PAGE_SIZE - 2u * sizeof(ZixShort)) -#define ZIX_BTREE_LEAF_VALS ((ZIX_BTREE_NODE_SPACE / sizeof(void*)) - 1u) -#define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2u) +#define ZIX_BTREE_NODE_SPACE (ZIX_BTREE_PAGE_SIZE - 2U * sizeof(ZixShort)) +#define ZIX_BTREE_LEAF_VALS ((ZIX_BTREE_NODE_SPACE / sizeof(void*)) - 1U) +#define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2U) struct ZixBTreeImpl { ZixAllocator* allocator; @@ -43,28 +43,28 @@ struct ZixBTreeNodeImpl { struct { void* vals[ZIX_BTREE_INODE_VALS]; - ZixBTreeNode* children[ZIX_BTREE_INODE_VALS + 1u]; + ZixBTreeNode* children[ZIX_BTREE_INODE_VALS + 1U]; } inode; } data; }; -#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \ +#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ (defined(__cplusplus) && __cplusplus >= 201103L)) static_assert(sizeof(ZixBTree) <= ZIX_BTREE_PAGE_SIZE, ""); static_assert(sizeof(ZixBTreeNode) <= ZIX_BTREE_PAGE_SIZE, ""); static_assert(sizeof(ZixBTreeNode) >= - ZIX_BTREE_PAGE_SIZE - 2u * sizeof(ZixBTreeNode*), + ZIX_BTREE_PAGE_SIZE - 2U * sizeof(ZixBTreeNode*), ""); #endif static ZixBTreeNode* zix_btree_node_new(ZixAllocator* const allocator, const bool leaf) { -#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \ +#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ (defined(__cplusplus) && __cplusplus >= 201103L)) assert(sizeof(ZixBTreeNode) <= ZIX_BTREE_PAGE_SIZE); assert(sizeof(ZixBTreeNode) >= - ZIX_BTREE_PAGE_SIZE - 2u * sizeof(ZixBTreeNode*)); + ZIX_BTREE_PAGE_SIZE - 2U * sizeof(ZixBTreeNode*)); #endif ZixBTreeNode* const node = (ZixBTreeNode*)zix_aligned_alloc( @@ -72,7 +72,7 @@ zix_btree_node_new(ZixAllocator* const allocator, const bool leaf) if (node) { node->is_leaf = leaf; - node->n_vals = 0u; + node->n_vals = 0U; } return node; @@ -92,7 +92,7 @@ zix_btree_new(ZixAllocator* const allocator, const ZixComparator cmp, const void* const cmp_data) { -#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \ +#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ (defined(__cplusplus) && __cplusplus >= 201103L)) assert(sizeof(ZixBTree) <= ZIX_BTREE_PAGE_SIZE); #endif @@ -126,7 +126,7 @@ zix_btree_free_children(ZixBTree* const t, const void* const destroy_user_data) { if (!n->is_leaf) { - for (ZixShort i = 0; i < n->n_vals + 1u; ++i) { + for (ZixShort i = 0; i < n->n_vals + 1U; ++i) { zix_btree_free_children( t, zix_btree_child(n, i), destroy, destroy_user_data); zix_aligned_free(t->allocator, zix_btree_child(n, i)); @@ -135,11 +135,11 @@ zix_btree_free_children(ZixBTree* const t, if (destroy) { if (n->is_leaf) { - for (ZixShort i = 0u; i < n->n_vals; ++i) { + for (ZixShort i = 0U; i < n->n_vals; ++i) { destroy(n->data.leaf.vals[i], destroy_user_data); } } else { - for (ZixShort i = 0u; i < n->n_vals; ++i) { + for (ZixShort i = 0U; i < n->n_vals; ++i) { destroy(n->data.inode.vals[i], destroy_user_data); } } @@ -167,7 +167,7 @@ zix_btree_clear(ZixBTree* const t, memset(t->root, 0, sizeof(ZixBTreeNode)); t->root->is_leaf = true; - t->size = 0u; + t->size = 0U; } size_t @@ -186,7 +186,7 @@ zix_btree_max_vals(const ZixBTreeNode* const node) static ZixShort zix_btree_min_vals(const ZixBTreeNode* const node) { - return (ZixShort)(((zix_btree_max_vals(node) + 1u) / 2u) - 1u); + return (ZixShort)(((zix_btree_max_vals(node) + 1U) / 2U) - 1U); } /// Shift pointers in `array` of length `n` right starting at `i` @@ -269,12 +269,12 @@ zix_btree_node_is_sorted_with_respect_to(const ZixComparator compare, const unsigned n_values, const void* const key) { - if (n_values <= 1u) { + if (n_values <= 1U) { return true; } int cmp = compare(values[0], key, compare_user_data); - for (unsigned i = 1u; i < n_values; ++i) { + for (unsigned i = 1U; i < n_values; ++i) { const int next_cmp = compare(values[i], key, compare_user_data); if ((cmp >= 0 && next_cmp < 0) || (cmp > 0 && next_cmp <= 0)) { return false; @@ -295,11 +295,11 @@ zix_btree_find_value(const ZixComparator compare, const void* const key, bool* const equal) { - unsigned first = 0u; + unsigned first = 0U; unsigned count = n_values; - while (count > 0u) { - const unsigned half = count >> 1u; + while (count > 0U) { + const unsigned half = count >> 1U; const unsigned i = first + half; void* const value = values[i]; const int cmp = compare(value, key, compare_user_data); @@ -310,8 +310,8 @@ zix_btree_find_value(const ZixComparator compare, } if (cmp < 0) { - first += half + 1u; - count -= half + 1u; + first += half + 1U; + count -= half + 1U; } else { count = half; } @@ -335,11 +335,11 @@ zix_btree_find_pattern(const ZixComparator compare_key, compare_key, compare_key_user_data, values, n_values, key)); #endif - unsigned first = 0u; + unsigned first = 0U; unsigned count = n_values; - while (count > 0u) { - const unsigned half = count >> 1u; + while (count > 0U) { + const unsigned half = count >> 1U; const unsigned i = first + half; void* const value = values[i]; const int cmp = compare_key(value, key, compare_key_user_data); @@ -351,8 +351,8 @@ zix_btree_find_pattern(const ZixComparator compare_key, } else if (cmp < 0) { // Search right half - first += half + 1u; - count -= half + 1u; + first += half + 1U; + count -= half + 1U; } else { // Search left half @@ -362,8 +362,8 @@ zix_btree_find_pattern(const ZixComparator compare_key, assert(!*equal || (compare_key(values[first], key, compare_key_user_data) == 0 && - (first == 0u || - (compare_key(values[first - 1u], key, compare_key_user_data) < 0)))); + (first == 0U || + (compare_key(values[first - 1U], key, compare_key_user_data) < 0)))); return first; } @@ -510,9 +510,9 @@ zix_btree_iter_push(ZixBTreeIter* const ti, static void zix_btree_iter_pop(ZixBTreeIter* const ti) { - assert(ti->level > 0u); + assert(ti->level > 0U); ti->nodes[ti->level] = NULL; - ti->indexes[ti->level] = 0u; + ti->indexes[ti->level] = 0U; --ti->level; } @@ -659,7 +659,7 @@ zix_btree_remove_max(ZixBTree* const t, ZixBTreeNode* n) while (!n->is_leaf) { ZixBTreeNode* const* const children = n->data.inode.children; - const unsigned y = n->n_vals - 1u; + const unsigned y = n->n_vals - 1U; const unsigned z = n->n_vals; n = zix_btree_can_remove_from(children[z]) ? children[z] @@ -680,11 +680,11 @@ zix_btree_fatten_child(ZixBTree* const t, ZixBTreeIter* const iter) assert(!n->is_leaf); ZixBTreeNode* const* const children = n->data.inode.children; - if (i > 0 && zix_btree_can_remove_from(children[i - 1u])) { + if (i > 0 && zix_btree_can_remove_from(children[i - 1U])) { return zix_btree_rotate_right(n, i); // Steal a key from left sibling } - if (i < n->n_vals && zix_btree_can_remove_from(children[i + 1u])) { + if (i < n->n_vals && zix_btree_can_remove_from(children[i + 1U])) { return zix_btree_rotate_left(n, i); // Steal a key from right sibling } @@ -692,7 +692,7 @@ zix_btree_fatten_child(ZixBTree* const t, ZixBTreeIter* const iter) if (i == n->n_vals) { --iter->indexes[iter->level]; - return zix_btree_merge(t, n, i - 1u); // Merge last two children + return zix_btree_merge(t, n, i - 1U); // Merge last two children } return zix_btree_merge(t, n, i); // Merge left and right siblings @@ -722,7 +722,7 @@ zix_btree_replace_value(ZixBTree* const t, : (rhs->n_vals > lhs->n_vals) ? zix_btree_remove_min(t, rhs) // Children are balanced, use index parity as a low-bias tie breaker - : (i & 1u) ? zix_btree_remove_max(t, lhs) + : (i & 1U) ? zix_btree_remove_max(t, lhs) : zix_btree_remove_min(t, rhs); return ZIX_STATUS_SUCCESS; @@ -748,9 +748,9 @@ zix_btree_remove(ZixBTree* const t, minimum. This ensures that there is always room to remove, without having to merge nodes again on a traversal back up. */ - if (!n->is_leaf && n->n_vals == 1u && - !zix_btree_can_remove_from(n->data.inode.children[0u]) && - !zix_btree_can_remove_from(n->data.inode.children[1u])) { + if (!n->is_leaf && n->n_vals == 1U && + !zix_btree_can_remove_from(n->data.inode.children[0U]) && + !zix_btree_can_remove_from(n->data.inode.children[1U])) { // Root has only two children, both minimal, merge them into a new root n = zix_btree_merge(t, n, 0); } @@ -798,10 +798,10 @@ zix_btree_remove(ZixBTree* const t, *out = zix_btree_aerase(n->data.leaf.vals, --n->n_vals, i); // Update next iterator - if (n->n_vals == 0u) { + if (n->n_vals == 0U) { // Removed the last element in the tree assert(n == t->root); - assert(t->size == 1u); + assert(t->size == 1U); *ti = zix_btree_end_iter; } else if (i == n->n_vals) { // Removed the largest element in this leaf, increment to the next @@ -865,7 +865,7 @@ zix_btree_lower_bound(const ZixBTree* const t, *ti = zix_btree_end_iter; ZixBTreeNode* n = t->root; // Current node - uint16_t found_level = 0u; // Lowest level a match was found at + uint16_t found_level = 0U; // Lowest level a match was found at bool found = false; // True if a match was ever found // Search down until we reach a leaf @@ -936,13 +936,13 @@ zix_btree_begin(const ZixBTree* const t) ZixBTreeIter iter = zix_btree_end_iter; - if (t->size > 0u) { + if (t->size > 0U) { ZixBTreeNode* n = t->root; - zix_btree_iter_set_frame(&iter, n, 0u); + zix_btree_iter_set_frame(&iter, n, 0U); while (!n->is_leaf) { n = zix_btree_child(n, 0); - zix_btree_iter_push(&iter, n, 0u); + zix_btree_iter_push(&iter, n, 0U); } } @@ -960,7 +960,7 @@ zix_btree_end(const ZixBTree* const t) bool zix_btree_iter_equals(const ZixBTreeIter lhs, const ZixBTreeIter rhs) { - const size_t indexes_size = (lhs.level + 1u) * sizeof(uint16_t); + const size_t indexes_size = (lhs.level + 1U) * sizeof(uint16_t); return (lhs.level == rhs.level) && (lhs.nodes[0] == rhs.nodes[0]) && (!lhs.nodes[0] || !memcmp(lhs.indexes, rhs.indexes, indexes_size)); @@ -993,11 +993,11 @@ zix_btree_iter_increment(ZixBTreeIter* const i) const ZixBTreeNode* const node = i->nodes[i->level]; ZixBTreeNode* const child = node->data.inode.children[index]; - zix_btree_iter_push(i, child, 0u); + zix_btree_iter_push(i, child, 0U); // Move down and left until we hit a leaf while (!i->nodes[i->level]->is_leaf) { - zix_btree_iter_push(i, i->nodes[i->level]->data.inode.children[0], 0u); + zix_btree_iter_push(i, i->nodes[i->level]->data.inode.children[0], 0U); } } diff --git a/src/bump_allocator.c b/src/bump_allocator.c index d6d1c41..eedd3e9 100644 --- a/src/bump_allocator.c +++ b/src/bump_allocator.c @@ -16,9 +16,9 @@ static size_t round_up_multiple(const size_t number, const size_t factor) { assert(factor); // Factor must be non-zero - assert((factor & (factor - 1)) == 0u); // Factor must be a power of two + assert((factor & (factor - 1)) == 0U); // Factor must be a power of two - return (number + factor - 1u) & ~(factor - 1u); + return (number + factor - 1U) & ~(factor - 1U); } ZIX_MALLOC_FUNC @@ -100,7 +100,7 @@ zix_bump_aligned_alloc(ZixAllocator* const allocator, const size_t old_top = state->top; assert(alignment >= min_alignment); - assert(size % alignment == 0u); + assert(size % alignment == 0U); /* First, calculate how much we need to offset the top to achieve this alignment. Note that it's not the offset that needs to be aligned (since diff --git a/src/digest.c b/src/digest.c index 133f5c0..3af9e8c 100644 --- a/src/digest.c +++ b/src/digest.c @@ -23,16 +23,16 @@ static inline uint64_t mix64(uint64_t h) { - h ^= h >> 23u; - h *= 0x2127599BF4325C37ull; - h ^= h >> 47u; + h ^= h >> 23U; + h *= 0x2127599BF4325C37ULL; + h ^= h >> 47U; return h; } uint64_t zix_digest64(const uint64_t seed, const void* const key, const size_t len) { - static const uint64_t m = 0x880355F21E6D1965ull; + static const uint64_t m = 0x880355F21E6D1965ULL; // Process as many 64-bit blocks as possible const size_t n_blocks = len / sizeof(uint64_t); @@ -40,7 +40,7 @@ zix_digest64(const uint64_t seed, const void* const key, const size_t len) const uint8_t* const blocks_end = data + (n_blocks * sizeof(uint64_t)); uint64_t h = seed ^ (len * m); for (; data != blocks_end; data += sizeof(uint64_t)) { - uint64_t k = 0u; + uint64_t k = 0U; memcpy(&k, data, sizeof(uint64_t)); h ^= mix64(k); @@ -49,25 +49,25 @@ zix_digest64(const uint64_t seed, const void* const key, const size_t len) // Process any trailing bytes const uint8_t* const tail = blocks_end; - uint64_t v = 0u; - switch (len & 7u) { + uint64_t v = 0U; + switch (len & 7U) { case 7: - v |= (uint64_t)tail[6] << 48u; + v |= (uint64_t)tail[6] << 48U; FALLTHROUGH(); case 6: - v |= (uint64_t)tail[5] << 40u; + v |= (uint64_t)tail[5] << 40U; FALLTHROUGH(); case 5: - v |= (uint64_t)tail[4] << 32u; + v |= (uint64_t)tail[4] << 32U; FALLTHROUGH(); case 4: - v |= (uint64_t)tail[3] << 24u; + v |= (uint64_t)tail[3] << 24U; FALLTHROUGH(); case 3: - v |= (uint64_t)tail[2] << 16u; + v |= (uint64_t)tail[2] << 16U; FALLTHROUGH(); case 2: - v |= (uint64_t)tail[1] << 8u; + v |= (uint64_t)tail[1] << 8U; FALLTHROUGH(); case 1: v |= (uint64_t)tail[0]; @@ -82,16 +82,16 @@ zix_digest64(const uint64_t seed, const void* const key, const size_t len) uint64_t zix_digest64_aligned(const uint64_t seed, const void* const key, size_t len) { - static const uint64_t m = 0x880355F21E6D1965ull; + static const uint64_t m = 0x880355F21E6D1965ULL; - assert((uintptr_t)key % sizeof(uint64_t) == 0u); - assert(len % sizeof(uint64_t) == 0u); + assert((uintptr_t)key % sizeof(uint64_t) == 0U); + assert(len % sizeof(uint64_t) == 0U); const uint64_t* const blocks = (const uint64_t*)key; const size_t n_blocks = len / sizeof(uint64_t); uint64_t h = seed ^ (len * m); - for (size_t i = 0u; i < n_blocks; ++i) { + for (size_t i = 0U; i < n_blocks; ++i) { h ^= mix64(blocks[i]); h *= m; } @@ -119,19 +119,19 @@ rotl32(const uint32_t val, const uint32_t bits) static inline uint32_t mix32(uint32_t h) { - h ^= h >> 16u; - h *= 0x85EBCA6Bu; - h ^= h >> 13u; - h *= 0xC2B2AE35u; - h ^= h >> 16u; + h ^= h >> 16U; + h *= 0x85EBCA6BU; + h ^= h >> 13U; + h *= 0xC2B2AE35U; + h ^= h >> 16U; return h; } uint32_t zix_digest32(const uint32_t seed, const void* const key, const size_t len) { - static const uint32_t c1 = 0xCC9E2D51u; - static const uint32_t c2 = 0x1B873593u; + static const uint32_t c1 = 0xCC9E2D51U; + static const uint32_t c2 = 0x1B873593U; // Process as many 32-bit blocks as possible const size_t n_blocks = len / sizeof(uint32_t); @@ -139,7 +139,7 @@ zix_digest32(const uint32_t seed, const void* const key, const size_t len) const uint8_t* const blocks_end = data + (n_blocks * sizeof(uint32_t)); uint32_t h = seed; for (; data != blocks_end; data += sizeof(uint32_t)) { - uint32_t k = 0u; + uint32_t k = 0U; memcpy(&k, data, sizeof(uint32_t)); k *= c1; @@ -148,23 +148,23 @@ zix_digest32(const uint32_t seed, const void* const key, const size_t len) h ^= k; h = rotl32(h, 13); - h = h * 5u + 0xE6546B64u; + h = h * 5U + 0xE6546B64U; } // Process any trailing bytes - uint32_t k = 0u; - switch (len & 3u) { - case 3u: - k ^= (uint32_t)data[2u] << 16u; + uint32_t k = 0U; + switch (len & 3U) { + case 3U: + k ^= (uint32_t)data[2U] << 16U; FALLTHROUGH(); - case 2u: - k ^= (uint32_t)data[1u] << 8u; + case 2U: + k ^= (uint32_t)data[1U] << 8U; FALLTHROUGH(); - case 1u: - k ^= (uint32_t)data[0u]; + case 1U: + k ^= (uint32_t)data[0U]; k *= c1; - k = rotl32(k, 15u); + k = rotl32(k, 15U); k *= c2; h ^= k; } @@ -177,16 +177,16 @@ zix_digest32_aligned(const uint32_t seed, const void* const key, const size_t len) { - static const uint32_t c1 = 0xCC9E2D51u; - static const uint32_t c2 = 0x1B873593u; + static const uint32_t c1 = 0xCC9E2D51U; + static const uint32_t c2 = 0x1B873593U; - assert((uintptr_t)key % sizeof(uint32_t) == 0u); - assert(len % sizeof(uint32_t) == 0u); + assert((uintptr_t)key % sizeof(uint32_t) == 0U); + assert(len % sizeof(uint32_t) == 0U); const uint32_t* const blocks = (const uint32_t*)key; const size_t n_blocks = len / sizeof(uint32_t); uint32_t h = seed; - for (size_t i = 0u; i < n_blocks; ++i) { + for (size_t i = 0U; i < n_blocks; ++i) { uint32_t k = blocks[i]; k *= c1; @@ -195,7 +195,7 @@ zix_digest32_aligned(const uint32_t seed, h ^= k; h = rotl32(h, 13); - h = h * 5u + 0xE6546B64u; + h = h * 5U + 0xE6546B64U; } return mix32(h ^ (uint32_t)len); diff --git a/src/hash.c b/src/hash.c index f0f2fe9..750156f 100644 --- a/src/hash.c +++ b/src/hash.c @@ -22,8 +22,8 @@ struct ZixHashImpl { ZixHashEntry* entries; ///< Pointer to dynamically allocated table }; -static const size_t min_n_entries = 4u; -static const size_t tombstone = 0xDEADu; +static const size_t min_n_entries = 4U; +static const size_t tombstone = 0xDEADU; ZixHash* zix_hash_new(ZixAllocator* const allocator, @@ -44,9 +44,9 @@ zix_hash_new(ZixAllocator* const allocator, hash->key_func = key_func; hash->hash_func = hash_func; hash->equal_func = equal_func; - hash->count = 0u; + hash->count = 0U; hash->n_entries = min_n_entries; - hash->mask = hash->n_entries - 1u; + hash->mask = hash->n_entries - 1U; hash->entries = (ZixHashEntry*)zix_calloc(allocator, hash->n_entries, sizeof(ZixHashEntry)); @@ -72,7 +72,7 @@ ZixHashIter zix_hash_begin(const ZixHash* const hash) { assert(hash); - return hash->entries[0u].value ? 0u : zix_hash_next(hash, 0u); + return hash->entries[0U].value ? 0U : zix_hash_next(hash, 0U); } ZixHashIter @@ -137,7 +137,7 @@ is_match(const ZixHash* const hash, static inline size_t next_index(const ZixHash* const hash, const size_t i) { - return (i == hash->mask) ? 0u : (i + 1u); + return (i == hash->mask) ? 0U : (i + 1U); } static inline ZixHashIter @@ -174,11 +174,11 @@ rehash(ZixHash* const hash, const size_t old_n_entries) hash->entries = new_entries; // Reinsert every element into the new array - for (size_t i = 0u; i < old_n_entries; ++i) { + for (size_t i = 0U; i < old_n_entries; ++i) { ZixHashEntry* const entry = &old_entries[i]; if (entry->value) { - assert(hash->mask == hash->n_entries - 1u); + assert(hash->mask == hash->n_entries - 1U); const size_t new_h = fold_hash(entry->hash, hash->mask); const size_t new_i = find_entry(hash, entry->value, new_h, entry->hash); @@ -196,8 +196,8 @@ grow(ZixHash* const hash) const size_t old_n_entries = hash->n_entries; const size_t old_mask = hash->mask; - hash->n_entries <<= 1u; - hash->mask = hash->n_entries - 1u; + hash->n_entries <<= 1U; + hash->mask = hash->n_entries - 1U; const ZixStatus st = rehash(hash, old_n_entries); if (st) { @@ -214,8 +214,8 @@ shrink(ZixHash* const hash) if (hash->n_entries > min_n_entries) { const size_t old_n_entries = hash->n_entries; - hash->n_entries >>= 1u; - hash->mask = hash->n_entries - 1u; + hash->n_entries >>= 1U; + hash->mask = hash->n_entries - 1U; return rehash(hash, old_n_entries); } @@ -327,7 +327,7 @@ zix_hash_insert_at(ZixHash* const hash, entry->value = record; // Update size and rehash if we exceeded the maximum load - const size_t max_load = hash->n_entries / 2u + hash->n_entries / 8u; + const size_t max_load = hash->n_entries / 2U + hash->n_entries / 8U; const size_t new_count = hash->count + 1; if (new_count >= max_load) { const ZixStatus st = grow(hash); @@ -368,7 +368,7 @@ zix_hash_erase(ZixHash* const hash, // Decrease element count and rehash if necessary --hash->count; - if (hash->count < hash->n_entries / 4u) { + if (hash->count < hash->n_entries / 4U) { return shrink(hash); } diff --git a/src/ring.c b/src/ring.c index d5b942b..4998112 100644 --- a/src/ring.c +++ b/src/ring.c @@ -46,11 +46,11 @@ next_power_of_two(uint32_t size) { // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 size--; - size |= size >> 1u; - size |= size >> 2u; - size |= size >> 4u; - size |= size >> 8u; - size |= size >> 16u; + size |= size >> 1U; + size |= size >> 2U; + size |= size >> 4U; + size |= size >> 8U; + size |= size >> 16U; size++; return size; } diff --git a/test/.clang-tidy b/test/.clang-tidy index 0924b8f..ac418d7 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -4,7 +4,6 @@ Checks: > *, -*-magic-numbers, - -*-uppercase-literal-suffix, -altera-*, -android-cloexec-fopen, -bugprone-easily-swappable-parameters, @@ -12,7 +11,6 @@ Checks: > -cppcoreguidelines-avoid-non-const-global-variables, -google-readability-casting, -hicpp-multiway-paths-covered, - -hicpp-uppercase-literal-suffix, -llvm-header-guard, -llvmlibc-*, -misc-no-recursion, diff --git a/test/allocator_test.c b/test/allocator_test.c index b4aec16..e146de6 100644 --- a/test/allocator_test.c +++ b/test/allocator_test.c @@ -65,14 +65,14 @@ test_bump_allocator(void) char* const malloced = (char*)zix_malloc(&allocator.base, 3); assert(malloced >= buffer); assert(malloced <= buffer + sizeof(buffer)); - assert((uintptr_t)malloced % sizeof(uintmax_t) == 0u); + assert((uintptr_t)malloced % sizeof(uintmax_t) == 0U); assert(!zix_calloc(&allocator.base, 1017, 1)); char* const calloced = (char*)zix_calloc(&allocator.base, 4, 1); assert(calloced > malloced); assert(calloced <= buffer + sizeof(buffer)); - assert((uintptr_t)calloced % sizeof(uintmax_t) == 0u); + assert((uintptr_t)calloced % sizeof(uintmax_t) == 0U); assert(!calloced[0]); assert(!calloced[1]); assert(!calloced[2]); @@ -104,7 +104,7 @@ test_bump_allocator(void) assert(aligned); assert(aligned >= reclaimed); assert(aligned <= buffer + sizeof(buffer)); - assert((uintptr_t)aligned % 128 == 0u); + assert((uintptr_t)aligned % 128 == 0U); zix_aligned_free(&allocator.base, aligned); zix_free(&allocator.base, reclaimed); // Correct, but a noop diff --git a/test/bitset_test.c b/test/bitset_test.c index ef61eeb..ef0528f 100644 --- a/test/bitset_test.c +++ b/test/bitset_test.c @@ -7,7 +7,7 @@ #include -#define N_BITS 256u +#define N_BITS 256U #define N_ELEMS (ZIX_BITSET_ELEMS(N_BITS)) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) diff --git a/test/btree_test.c b/test/btree_test.c index 150a29d..878eef9 100644 --- a/test/btree_test.c +++ b/test/btree_test.c @@ -27,8 +27,8 @@ int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) const uintptr_t ia = (uintptr_t)a; const uintptr_t ib = (uintptr_t)b; - assert(ia != 0u); // No wildcards - assert(ib != 0u); // No wildcards + assert(ia != 0U); // No wildcards + assert(ib != 0U); // No wildcards return ia < ib ? -1 : ia > ib ? 1 : 0; } @@ -42,7 +42,7 @@ ith_elem(const unsigned test_num, const size_t n_elems, const size_t i) case 1: return n_elems - i; // Decreasing default: - return 1u + unique_rand(i); // Pseudo-random + return 1U + unique_rand(i); // Pseudo-random } } @@ -103,7 +103,7 @@ test_fail(ZixBTree* t, const char* fmt, ...) return EXIT_FAILURE; } -static const size_t n_clear_insertions = 1024u; +static const size_t n_clear_insertions = 1024U; static void destroy(void* const ptr, const void* const user_data) @@ -125,8 +125,8 @@ test_clear(void) { ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); - for (uintptr_t r = 0u; r < n_clear_insertions; ++r) { - assert(!zix_btree_insert(t, (void*)(r + 1u))); + for (uintptr_t r = 0U; r < n_clear_insertions; ++r) { + assert(!zix_btree_insert(t, (void*)(r + 1U))); } zix_btree_clear(t, destroy, NULL); @@ -140,8 +140,8 @@ test_free(void) { ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL); - for (uintptr_t r = 0u; r < n_clear_insertions; ++r) { - assert(!zix_btree_insert(t, (void*)(r + 1u))); + for (uintptr_t r = 0U; r < n_clear_insertions; ++r) { + assert(!zix_btree_insert(t, (void*)(r + 1U))); } assert(zix_btree_size(t) == n_clear_insertions); @@ -152,12 +152,12 @@ test_free(void) static void test_iter_comparison(void) { - static const size_t n_elems = 4096u; + static const size_t n_elems = 4096U; ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); // Store increasing numbers from 1 (jammed into the pointers themselves) - for (uintptr_t r = 1u; r < n_elems; ++r) { + for (uintptr_t r = 1U; r < n_elems; ++r) { assert(!zix_btree_insert(t, (void*)r)); } @@ -174,7 +174,7 @@ test_iter_comparison(void) assert(zix_btree_iter_equals(begin, j)); // Advance it and check that they are no longer equal - for (size_t r = 1u; r < n_elems - 1u; ++r) { + for (size_t r = 1U; r < n_elems - 1U; ++r) { j = zix_btree_iter_next(j); assert(!zix_btree_iter_is_end(j)); assert(!zix_btree_iter_equals(begin, j)); @@ -195,13 +195,13 @@ test_iter_comparison(void) static void test_insert_split_value(void) { - static const size_t n_insertions = 767u; // Number of insertions to split - static const uintptr_t split_value = 512u; // Value that will be pulled up + static const size_t n_insertions = 767U; // Number of insertions to split + static const uintptr_t split_value = 512U; // Value that will be pulled up ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); // Insert right up until it would cause a split - for (uintptr_t r = 1u; r < n_insertions; ++r) { + for (uintptr_t r = 1U; r < n_insertions; ++r) { assert(!zix_btree_insert(t, (void*)r)); } @@ -218,16 +218,16 @@ test_remove_cases(void) even multiples. This spreads the load around to hit as many cases as possible. */ - static const uintptr_t s1 = 2u; - static const uintptr_t s2 = 255u; - const size_t n_insertions = s1 * s2 * 1000u; + static const uintptr_t s1 = 2U; + static const uintptr_t s2 = 255U; + const size_t n_insertions = s1 * s2 * 1000U; ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL); // Insert in s1-sized chunks - for (uintptr_t phase = 0u; phase < s1; ++phase) { - for (uintptr_t r = 0u; r < n_insertions / s1; ++r) { - const uintptr_t value = (s1 * r) + phase + 1u; + for (uintptr_t phase = 0U; phase < s1; ++phase) { + for (uintptr_t r = 0U; r < n_insertions / s1; ++r) { + const uintptr_t value = (s1 * r) + phase + 1U; assert(!zix_btree_insert(t, (void*)value)); } @@ -235,9 +235,9 @@ test_remove_cases(void) // Remove in s2-sized chunks ZixBTreeIter next = zix_btree_end(t); - for (uintptr_t phase = 0u; phase < s2; ++phase) { - for (uintptr_t r = 0u; r < n_insertions / s2; ++r) { - const uintptr_t value = (s2 * r) + phase + 1u; + for (uintptr_t phase = 0U; phase < s2; ++phase) { + for (uintptr_t r = 0U; r < n_insertions / s2; ++r) { + const uintptr_t value = (s2 * r) + phase + 1U; void* out = NULL; assert(!zix_btree_remove(t, (void*)value, &out, &next)); @@ -604,7 +604,7 @@ test_failed_alloc(void) // Test that each allocation failing is handled gracefully const size_t n_new_allocs = allocator.n_allocations; - for (size_t i = 0u; i < n_new_allocs; ++i) { + for (size_t i = 0U; i < n_new_allocs; ++i) { allocator.n_remaining = i; assert(stress(&allocator.base, 0, 4096)); } @@ -625,8 +625,8 @@ main(int argc, char** argv) test_remove_cases(); test_failed_alloc(); - const unsigned n_tests = 3u; - const size_t n_elems = (argc > 1) ? strtoul(argv[1], NULL, 10) : 131072u; + const unsigned n_tests = 3U; + const size_t n_elems = (argc > 1) ? strtoul(argv[1], NULL, 10) : 131072U; printf("Running %u tests with %" PRIuPTR " elements", n_tests, n_elems); for (unsigned i = 0; i < n_tests; ++i) { diff --git a/test/digest_test.c b/test/digest_test.c index 59d28b3..c1a16a8 100644 --- a/test/digest_test.c +++ b/test/digest_test.c @@ -16,12 +16,12 @@ test_digest(void) static const uint8_t data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - size_t last = 0u; + size_t last = 0U; for (size_t offset = 0; offset < 7; ++offset) { - const size_t len = 8u - offset; + const size_t len = 8U - offset; for (size_t i = offset; i < 8; ++i) { - const size_t h = zix_digest(0u, &data[i], len); + const size_t h = zix_digest(0U, &data[i], len); assert(h != last); last = h; } @@ -33,11 +33,11 @@ test_digest32(void) { static const uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint32_t last = 0u; + uint32_t last = 0U; for (size_t offset = 0; offset < 3; ++offset) { for (size_t i = offset; i < 4; ++i) { - const uint32_t h = zix_digest32(0u, &data[i], 4); + const uint32_t h = zix_digest32(0U, &data[i], 4); assert(h != last); last = h; } @@ -50,11 +50,11 @@ test_digest64(void) static const uint8_t data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - uint64_t last = 0u; + uint64_t last = 0U; for (size_t offset = 0; offset < 7; ++offset) { for (size_t i = offset; i < 8; ++i) { - const uint64_t h = zix_digest64(0u, &data[i], 8); + const uint64_t h = zix_digest64(0U, &data[i], 8); assert(h != last); last = h; } @@ -66,13 +66,13 @@ test_digest32_aligned(void) { static const uint32_t data[] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint32_t last = 0u; + uint32_t last = 0U; for (size_t offset = 0; offset < 3; ++offset) { - const size_t len = 4u - offset; + const size_t len = 4U - offset; for (size_t i = offset; i < 4; ++i) { const uint32_t h = - zix_digest32_aligned(0u, &data[i], len * sizeof(uint32_t)); + zix_digest32_aligned(0U, &data[i], len * sizeof(uint32_t)); assert(h != last); last = h; } @@ -84,13 +84,13 @@ test_digest64_aligned(void) { static const uint64_t data[] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint64_t last = 0u; + uint64_t last = 0U; for (size_t offset = 0; offset < 3; ++offset) { - const size_t len = 4u - offset; + const size_t len = 4U - offset; for (size_t i = offset; i < 4; ++i) { const uint64_t h = - zix_digest64_aligned(0u, &data[i], len * sizeof(uint64_t)); + zix_digest64_aligned(0U, &data[i], len * sizeof(uint64_t)); assert(h != last); last = h; } @@ -102,12 +102,12 @@ test_digest_aligned(void) { static const size_t data[] = {1, 2, 3, 4, 5, 6, 7, 8}; - size_t last = 0u; + size_t last = 0U; for (size_t offset = 0; offset < 3; ++offset) { - const size_t len = 4u - offset; + const size_t len = 4U - offset; for (size_t i = offset; i < 4; ++i) { - const size_t h = zix_digest_aligned(0u, &data[i], len * sizeof(size_t)); + const size_t h = zix_digest_aligned(0U, &data[i], len * sizeof(size_t)); assert(h != last); last = h; } diff --git a/test/hash_test.c b/test/hash_test.c index 9dbcadd..287dbaa 100644 --- a/test/hash_test.c +++ b/test/hash_test.c @@ -59,15 +59,15 @@ identity(const char* record) ZIX_PURE_FUNC static size_t decent_string_hash(const char* const str) { - return zix_digest(0u, str, strlen(str)); + return zix_digest(0U, str, strlen(str)); } /// Terrible hash function from K&R first edition ZIX_PURE_FUNC static size_t terrible_string_hash(const char* str) { - size_t hash = 0u; - uint8_t c = 0u; + size_t hash = 0U; + uint8_t c = 0U; while ((c = (uint8_t)*str++)) { hash += c; @@ -82,19 +82,19 @@ string_hash_aligned(const char* const str) size_t length = strlen(str); length = (length + (sizeof(size_t) - 1)) / sizeof(size_t) * sizeof(size_t); - return zix_digest_aligned(0u, str, length); + return zix_digest_aligned(0U, str, length); } ZIX_PURE_FUNC static size_t string_hash32(const char* const str) { - return (size_t)zix_digest32(0u, str, strlen(str)); + return (size_t)zix_digest32(0U, str, strlen(str)); } ZIX_PURE_FUNC static size_t string_hash64(const char* const str) { - return (size_t)zix_digest64(0u, str, strlen(str)); + return (size_t)zix_digest64(0U, str, strlen(str)); } ZIX_PURE_FUNC static size_t @@ -102,8 +102,8 @@ string_hash32_aligned(const char* const str) { size_t length = strlen(str); - length = (length + 3u) / 4u * 4u; - return (size_t)zix_digest32_aligned(0u, str, length); + length = (length + 3U) / 4U * 4U; + return (size_t)zix_digest32_aligned(0U, str, length); } #if UINTPTR_MAX >= UINT64_MAX @@ -113,8 +113,8 @@ string_hash64_aligned(const char* const str) { size_t length = strlen(str); - length = (length + 7u) / 8u * 8u; - return (size_t)zix_digest64_aligned(0u, str, length); + length = (length + 7U) / 8U * 8U; + return (size_t)zix_digest64_aligned(0U, str, length); } #endif @@ -143,13 +143,13 @@ stress_with(ZixAllocator* const allocator, return test_fail(hash, buffer, strings, "Failed to allocate strings\n"); } - uint32_t seed = 1u; - for (size_t i = 0u; i < n_elems; ++i) { + uint32_t seed = 1U; + for (size_t i = 0U; i < n_elems; ++i) { strings[i] = buffer + i * (string_length + 1); assert((uintptr_t)strings[i] % sizeof(size_t) == 0); assert((uintptr_t)strings[i] % sizeof(uint32_t) == 0); - for (size_t j = 0u; j < string_length; ++j) { + for (size_t j = 0U; j < string_length; ++j) { seed = lcg32(seed); strings[i][j] = (char)('!' + (seed % 92)); } @@ -285,7 +285,7 @@ stress_with(ZixAllocator* const allocator, } // Check key == value (and test zix_hash_foreach) - size_t n_checked = 0u; + size_t n_checked = 0U; for (ZixHashIter i = zix_hash_begin(hash); i != zix_hash_end(hash); i = zix_hash_next(hash, i)) { const char* const string = (const char*)zix_hash_get(hash, i); @@ -366,7 +366,7 @@ test_all_tombstones(void) zix_hash_new(NULL, identity, identity_index_hash, string_equal); // Insert each element then immediately remove it - for (unsigned i = 0u; i < N_STRINGS; ++i) { + for (unsigned i = 0U; i < N_STRINGS; ++i) { const char* removed = NULL; assert(!zix_hash_insert(hash, original_strings[i])); @@ -377,7 +377,7 @@ test_all_tombstones(void) assert(zix_hash_size(hash) == 0); // Insert clashing elements which should hit the "all tombstones" case - for (unsigned i = 0u; i < N_STRINGS; ++i) { + for (unsigned i = 0U; i < N_STRINGS; ++i) { assert(!zix_hash_insert(hash, collision_strings[i])); assert(!st); } @@ -397,7 +397,7 @@ test_failed_alloc(void) // Test that each allocation failing is handled gracefully const size_t n_new_allocs = allocator.n_allocations; - for (size_t i = 0u; i < n_new_allocs; ++i) { + for (size_t i = 0U; i < n_new_allocs; ++i) { allocator.n_remaining = i; assert(stress(&allocator.base, 16)); } @@ -411,7 +411,7 @@ main(void) test_all_tombstones(); test_failed_alloc(); - static const size_t n_elems = 1024u; + static const size_t n_elems = 1024U; if (stress(NULL, n_elems)) { return 1; diff --git a/test/ring_test.c b/test/ring_test.c index af54e0e..79aa0f1 100644 --- a/test/ring_test.c +++ b/test/ring_test.c @@ -16,7 +16,7 @@ #include #include -#define MSG_SIZE 20u +#define MSG_SIZE 20U static ZixRing* ring = 0; static unsigned n_writes = 0; @@ -25,7 +25,7 @@ static bool read_error = false; static int gen_msg(int* const msg, int start) { - for (unsigned i = 0u; i < MSG_SIZE; ++i) { + for (unsigned i = 0U; i < MSG_SIZE; ++i) { msg[i] = start; start = (start + 1) % INT_MAX; } @@ -36,7 +36,7 @@ ZIX_PURE_FUNC static int cmp_msg(const int* const msg1, const int* const msg2) { - for (unsigned i = 0u; i < MSG_SIZE; ++i) { + for (unsigned i = 0U; i < MSG_SIZE; ++i) { assert(msg1[i] == msg2[i]); } @@ -103,10 +103,10 @@ test_ring(const unsigned size) zix_ring_mlock(ring); ZixThread reader_thread; // NOLINT - assert(!zix_thread_create(&reader_thread, MSG_SIZE * 4ul, reader, NULL)); + assert(!zix_thread_create(&reader_thread, MSG_SIZE * 4UL, reader, NULL)); ZixThread writer_thread; // NOLINT - assert(!zix_thread_create(&writer_thread, MSG_SIZE * 4ul, writer, NULL)); + assert(!zix_thread_create(&writer_thread, MSG_SIZE * 4UL, writer, NULL)); zix_thread_join(reader_thread, NULL); zix_thread_join(writer_thread, NULL); @@ -168,7 +168,7 @@ test_failed_alloc(void) // Test that each allocation failing is handled gracefully const size_t n_new_allocs = allocator.n_allocations; - for (size_t i = 0u; i < n_new_allocs; ++i) { + for (size_t i = 0U; i < n_new_allocs; ++i) { allocator.n_remaining = i; assert(!zix_ring_new(&allocator.base, 512)); } diff --git a/test/test_data.h b/test/test_data.h index c5eaace..603a6c2 100644 --- a/test/test_data.h +++ b/test/test_data.h @@ -11,8 +11,8 @@ static inline uint32_t lcg32(const uint32_t i) { - static const uint32_t a = 134775813u; - static const uint32_t c = 1u; + static const uint32_t a = 134775813U; + static const uint32_t c = 1U; return (a * i) + c; } @@ -21,8 +21,8 @@ lcg32(const uint32_t i) static inline uint64_t lcg64(const uint64_t i) { - static const uint64_t a = 6364136223846793005ull; - static const uint64_t c = 1ull; + static const uint64_t a = 6364136223846793005ULL; + static const uint64_t c = 1ULL; return (a * i) + c; } @@ -42,10 +42,10 @@ lcg(const uintptr_t i) static inline size_t unique_rand(size_t i) { - i ^= 0x5CA1AB1Eu; // Juggle bits to avoid linear clumps + i ^= 0x5CA1AB1EU; // Juggle bits to avoid linear clumps // Largest prime < 2^32 which satisfies (2^32 = 3 mod 4) - static const size_t prime = 4294967291u; + static const size_t prime = 4294967291U; if (i >= prime) { return i; // Values >= prime are mapped to themselves } diff --git a/test/tree_test.c b/test/tree_test.c index a68437c..7c7fcf4 100644 --- a/test/tree_test.c +++ b/test/tree_test.c @@ -34,7 +34,7 @@ ith_elem(unsigned test_num, size_t n_elems, size_t i) return n_elems - i; // Decreasing (worse case) case 2: default: - return lcg(seed + i) % 100u; // Random + return lcg(seed + i) % 100U; // Random } } @@ -47,7 +47,7 @@ test_fail(void) static int stress(unsigned test_num, size_t n_elems) { - uintptr_t r = 0u; + uintptr_t r = 0U; ZixTreeIter* ti = NULL; ZixTree* t = zix_tree_new(NULL, true, int_cmp, NULL, NULL, NULL); -- cgit v1.2.1