]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't bother with return codes
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 20 Jul 2018 17:26:12 +0000 (13:26 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 20 Jul 2018 17:26:17 +0000 (13:26 -0400)
src/lib/util/trie.c

index 11863e4405029a14ff7a2984b2d9772e6eda7374..304827bb686235af8ebb397cbae8efb242c54a87 100644 (file)
@@ -213,7 +213,7 @@ static void *reparent(TALLOC_CTX *ctx, void *trie)
        }
 #endif
 
-       if (!fr_cond_assert(IS_NODE(trie))) return NULL;
+       fr_cond_assert(IS_NODE(trie));
        (void) talloc_steal(ctx, trie);
        return trie;
 }
@@ -272,7 +272,7 @@ static void *trie_parent(void *trie)
        }
 #endif
 
-       if (!fr_cond_assert(IS_NODE(trie))) return NULL;
+       fr_cond_assert(IS_NODE(trie));
        return talloc_parent(trie);
 }
 #endif
@@ -286,10 +286,10 @@ static void fr_trie_node_verify(fr_trie_node_t const *node)
 
        (void) talloc_get_type_abort_const(node, fr_trie_node_t);
 
-       if (!fr_cond_assert(node->size > 0)) return;
-       if (!fr_cond_assert(node->size <= 8)) return;
-       if (!fr_cond_assert(node->used >= 0)) return;
-       if (!fr_cond_assert(node->used <= (1 << node->size))) return;
+       fr_cond_assert(node->size > 0);
+       fr_cond_assert(node->size <= 8);
+       fr_cond_assert(node->used >= 0);
+       fr_cond_assert(node->used <= (1 << node->size));
 
        used = 0;
        for (i = 0; i < (1 << node->size); i++) {
@@ -298,7 +298,7 @@ static void fr_trie_node_verify(fr_trie_node_t const *node)
                used++;
        }
 
-       if (!fr_cond_assert(used == node->used)) return;
+       fr_cond_assert(used == node->used);
 }
 
 #ifdef WITH_PATH_COMPRESSION
@@ -309,20 +309,20 @@ static void fr_trie_path_verify(fr_trie_path_t const *path)
 {
        (void) talloc_get_type_abort_const(path, fr_trie_path_t);
 
-       if (!fr_cond_assert(path->start_bit >= 0)) return;
-       if (!fr_cond_assert(path->start_bit < 8)) return;
-       if (!fr_cond_assert(path->length > 0)) return;
-       if (!fr_cond_assert(path->length < (1 << 20))) return;
-       if (!fr_cond_assert(path->end_bit > 0)) return;
-       if (!fr_cond_assert(path->length < (1 << 20))) return;
-       if (!fr_cond_assert((path->start_bit + path->length) == path->end_bit)) return;
+       fr_cond_assert(path->start_bit >= 0);
+       fr_cond_assert(path->start_bit < 8);
+       fr_cond_assert(path->length > 0);
+       fr_cond_assert(path->length < (1 << 20));
+       fr_cond_assert(path->end_bit > 0);
+       fr_cond_assert(path->length < (1 << 20));
+       fr_cond_assert((path->start_bit + path->length) == path->end_bit);
 
-       if (!fr_cond_assert(path->key != NULL)) return;
-       if (!fr_cond_assert(talloc_parent(path->key) == path)) return;
+       fr_cond_assert(path->key != NULL);
+       fr_cond_assert(talloc_parent(path->key) == path);
 
        if ((path->start_bit == 0) && (path->length >= 8)) {
-               if (!fr_cond_assert(path->key[0] > ' ')) return;
-               if (!fr_cond_assert(path->key[0] < 0x7f)) return;
+               fr_cond_assert(path->key[0] > ' ');
+               fr_cond_assert(path->key[0] < 0x7f);
        }
 
        /*
@@ -332,12 +332,12 @@ static void fr_trie_path_verify(fr_trie_path_t const *path)
                int i;
 
                for (i = 1; i < BYTEOF(path->end_bit); i++) {
-                       if (!fr_cond_assert(path->key[i] > ' ')) return;
-                       if (!fr_cond_assert(path->key[i] < 0x7f)) return;
+                       fr_cond_assert(path->key[i] > ' ');
+                       fr_cond_assert(path->key[i] < 0x7f);
                }
        }
 
-       if (!fr_cond_assert(trie_parent(path->trie) == path)) return;
+       fr_cond_assert(trie_parent(path->trie) == path);
 }
 #endif /* WITH_PATH_COMPRESSION */
 
@@ -358,7 +358,7 @@ static void fr_trie_verify(void *trie)
 
                fr_trie_path_verify(path);
 
-               if (!fr_cond_assert(trie_parent(path->trie) == path)) return;
+               fr_cond_assert(trie_parent(path->trie) == path);
                fr_trie_verify(path->trie);
                return;
        }
@@ -370,7 +370,7 @@ static void fr_trie_verify(void *trie)
        for (i = 0; i < (1 << node->size); i++) {
                if (!node->trie[i]) continue;
 
-               if (!fr_cond_assert(trie_parent(node->trie[i]) == node)) return;
+               fr_cond_assert(trie_parent(node->trie[i]) == node);
 
                fr_trie_verify(node->trie[i]);
        }
@@ -463,7 +463,7 @@ static int fr_trie_path_lcp(uint8_t const *key1, int keylen1, uint8_t const *key
        int start_byte, end_byte;
 
        if (!keylen1 || !keylen2) return 0;
-       if (!fr_cond_assert((start_bit & 0x07) == start_bit)) return 0;
+       fr_cond_assert((start_bit & 0x07) == start_bit);
 
        end_bit = keylen1;
        if (end_bit > keylen2) end_bit = keylen2;
@@ -481,7 +481,7 @@ static int fr_trie_path_lcp(uint8_t const *key1, int keylen1, uint8_t const *key
                }
 
                s2 = start_bit;
-               if (!fr_cond_assert(s2 <= e2)) return 0;
+               fr_cond_assert(s2 <= e2);
 
                xor = key1[0] ^ key2[0];
 
@@ -522,7 +522,7 @@ static int fr_trie_path_lcp(uint8_t const *key1, int keylen1, uint8_t const *key
         *      do a separate bit check for the last byte.
         */
        end_byte = BYTEOF(end_bit);
-       if (!fr_cond_assert(start_byte <= end_byte)) return 0;
+       fr_cond_assert(start_byte <= end_byte);
 
        bytes = 0;
 
@@ -570,7 +570,7 @@ static int fr_trie_path_lcp(uint8_t const *key1, int keylen1, uint8_t const *key
                s2 = 0;
                e2 = 8;
        } else {
-               if (!fr_cond_assert(end_bit > s2)) return 0;
+               fr_cond_assert(end_bit > s2);
                e2 = end_bit - s2;
                s2 = 0;
        }
@@ -581,8 +581,8 @@ static int fr_trie_path_lcp(uint8_t const *key1, int keylen1, uint8_t const *key
        lcp += xor2lcp[xor];
 
 done:
-       if (!fr_cond_assert(lcp <= keylen1)) return 0;
-       if (!fr_cond_assert(lcp <= keylen2)) return 0;
+       fr_cond_assert(lcp <= keylen1);
+       fr_cond_assert(lcp <= keylen2);
        return lcp;
 }
 
@@ -596,10 +596,10 @@ static CC_HINT(nonnull) fr_trie_path_t *fr_trie_path_alloc(fr_trie_t *ft, TALLOC
        fr_trie_path_t *path;
        uint8_t *p;
 
-       if (!fr_cond_assert(end_bit < MAX_KEY_BITS)) return NULL;
-       if (!fr_cond_assert(end_bit > 0)) return NULL;
-       if (!fr_cond_assert(start_bit < end_bit)) return NULL;
-       if (!fr_cond_assert(!IS_PATH(trie))) return NULL;
+       fr_cond_assert(end_bit < MAX_KEY_BITS);
+       fr_cond_assert(end_bit > 0);
+       fr_cond_assert(start_bit < end_bit);
+       fr_cond_assert(!IS_PATH(trie));
 
        path = talloc_zero(ctx, fr_trie_path_t);
        if (!path) return NULL;
@@ -607,7 +607,7 @@ static CC_HINT(nonnull) fr_trie_path_t *fr_trie_path_alloc(fr_trie_t *ft, TALLOC
        path->start_bit = start_bit & 0x07;
        path->length = end_bit - start_bit;
        path->end_bit = path->start_bit + path->length;
-       if (!fr_cond_assert(path->length > 0)) return NULL;
+       fr_cond_assert(path->length > 0);
        path->number = ft->number++;
 
        path->key = p = talloc_memdup(path, key + BYTEOF(start_bit), BYTES(path->end_bit));
@@ -692,7 +692,7 @@ static int fr_trie_path_merge(fr_trie_t *ft, TALLOC_CTX *ctx, fr_trie_node_t **n
                        return -1;
                }
 
-               if (!fr_cond_assert(trie == small)) return -1;
+               fr_cond_assert(trie == small);
                fr_trie_node_verify(small);
 
                if (fr_trie_merge(ft, ctx, &trie, small, node, depth) < 0) {
@@ -700,7 +700,7 @@ static int fr_trie_path_merge(fr_trie_t *ft, TALLOC_CTX *ctx, fr_trie_node_t **n
                        return -1;
                }
 
-               if (!fr_cond_assert(trie == small)) return -1;
+               fr_cond_assert(trie == small);
                fr_trie_node_verify(small);
                *node_p = small;
 
@@ -733,7 +733,7 @@ static fr_trie_node_t *fr_trie_path_merge_disjoint(fr_trie_t *ft, TALLOC_CTX *ct
        fr_trie_path_verify(path1);
        fr_trie_path_verify(path2);
 
-       if (!fr_cond_assert(path1->start_bit == path2->start_bit)) return NULL;
+       fr_cond_assert(path1->start_bit == path2->start_bit);
 
        /*
         *      Figure out which is the shorter of the two paths.
@@ -752,8 +752,8 @@ static fr_trie_node_t *fr_trie_path_merge_disjoint(fr_trie_t *ft, TALLOC_CTX *ct
         */
        size = DEFAULT_SIZE;
        if (size > td_short->length) size = td_short->length;
-       if (!fr_cond_assert(size > 0)) return NULL;
-       if (!fr_cond_assert(size <= 8)) return NULL;
+       fr_cond_assert(size > 0);
+       fr_cond_assert(size <= 8);
 
        node = fr_trie_node_alloc(ft, ctx, size);
        if (!node) {
@@ -809,13 +809,13 @@ static void *fr_trie_path_merge_paths(fr_trie_t *ft, TALLOC_CTX *ctx, fr_trie_pa
        fr_trie_path_verify(path1);
        fr_trie_path_verify(path2);
 
-       if (!fr_cond_assert(path2->length > 0)) return NULL;
-       if (!fr_cond_assert(path1->start_bit == path2->start_bit)) return NULL;
+       fr_cond_assert(path2->length > 0);
+       fr_cond_assert(path1->start_bit == path2->start_bit);
 
        /*
         *      path1 is from the existing trie.  path2 is the path we're trying to insert.
         */
-       if (!fr_cond_assert(IS_USER(path2->trie))) return NULL;
+       fr_cond_assert(IS_USER(path2->trie));
 
        (void) talloc_get_type_abort(path1, fr_trie_path_t);
 
@@ -873,7 +873,7 @@ static void *fr_trie_path_merge_paths(fr_trie_t *ft, TALLOC_CTX *ctx, fr_trie_pa
        }
 
        if (!suffix1) {
-               if (!fr_cond_assert(!IS_PATH(path1->trie))) return NULL;
+               fr_cond_assert(!IS_PATH(path1->trie));
 
                if (fr_trie_merge(ft, prefix, &prefix->trie, path1->trie, PUT_PATH(suffix2), depth + prefix->length) < 0) {
                        talloc_free(prefix);
@@ -927,7 +927,7 @@ static int fr_trie_path_concatenate(fr_trie_path_t *path,
 {
        uint8_t *p, *q;
 
-       if (!fr_cond_assert(((start_bit1 + keylen1) & 0x07) == start_bit2)) return -1;
+       fr_cond_assert(((start_bit1 + keylen1) & 0x07) == start_bit2);
 
        p = talloc_array(path, uint8_t, BYTES(start_bit1 + keylen1 + keylen2));
        if (!p) return -1;
@@ -998,7 +998,7 @@ static void *fr_trie_path_prefix_add(fr_trie_t *ft, TALLOC_CTX *ctx, void *trie,
                return PUT_PATH(path);
        }
 
-       if (!fr_cond_assert(IS_PATH(trie))) return NULL;
+       fr_cond_assert(IS_PATH(trie));
        path = GET_PATH(trie);
 
        fr_trie_path_verify(path);
@@ -1017,9 +1017,9 @@ static uint16_t get_chunk(uint8_t const *key, int num_bits, int start_bit, int e
 {
        uint16_t chunk;
 
-       if (!fr_cond_assert(num_bits > 0)) return 0;
-       if (!fr_cond_assert(num_bits <= 8)) return 0;
-       if (!fr_cond_assert(start_bit < end_bit)) return 0;
+       fr_cond_assert(num_bits > 0);
+       fr_cond_assert(num_bits <= 8);
+       fr_cond_assert(start_bit < end_bit);
 
        /*
         *      Load the byte
@@ -1196,7 +1196,7 @@ static int fr_trie_merge(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p, void *
                for (i = 0; i < (1 << node1->size); i++) {
                        uint16_t j;
 
-                       if (!fr_cond_assert(bits < 8)) return -1;
+                       fr_cond_assert(bits < 8);
 
                        for (j = 0; j < (1 << bits); j++) {
                                void *subtrie;
@@ -1216,7 +1216,7 @@ static int fr_trie_merge(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p, void *
                                 */
                                subtrie = fr_trie_path_prefix_add(ft, node1, node2->trie[(i << bits) | j],
                                                                  bits, j, depth);
-                               if (!fr_cond_assert(subtrie != NULL)) return -1;
+                               fr_cond_assert(subtrie != NULL);
 
                                if (fr_trie_merge(ft, node1, &node1->trie[i],
                                                  node1->trie[i], subtrie, depth) < 0) {
@@ -1231,30 +1231,30 @@ static int fr_trie_merge(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p, void *
                                 */
                                if (!node1->trie[i]) {
                                        subnode = node1->trie[i] = fr_trie_node_alloc(ft, node1, bits);
-                                       if (!fr_cond_assert(subnode != NULL)) return -1;
+                                       fr_cond_assert(subnode != NULL);
 
                                } else if (IS_NODE(node1->trie[i])) {
                                        subnode = node1->trie[i];
-                                       if (!fr_cond_assert(IS_NODE(subnode))) return -1;
+                                       fr_cond_assert(IS_NODE(subnode));
 
                                } else {
                                        fr_trie_user_t *user;
 
-                                       if (!fr_cond_assert(IS_USER(node1->trie[i]))) return -1;
+                                       fr_cond_assert(IS_USER(node1->trie[i]));
                                        user = GET_USER(node1->trie[i]);
 
                                        subtrie = user->trie;
                                        if (!subtrie) {
                                                subnode = user->trie = fr_trie_node_alloc(ft, user, bits);
-                                               if (!fr_cond_assert(subnode != NULL)) return -1;
+                                               fr_cond_assert(subnode != NULL);
 
                                        } else {
                                                /*
                                                 *      No path compression here.
                                                 */
-                                               if (!fr_cond_assert(IS_NODE(subtrie))) return -1;
+                                               fr_cond_assert(IS_NODE(subtrie));
                                                subnode = subtrie;
-                                               if (!fr_cond_assert(subnode->size == bits)) return -1;
+                                               fr_cond_assert(subnode->size == bits);
                                        }
                                }
 
@@ -1272,7 +1272,9 @@ static int fr_trie_merge(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p, void *
                return 0;
        }
 
-       if (!fr_cond_assert(0 == 1)) return -1;
+       fr_cond_assert(0 == 1);
+
+       return -1;
 }
 
 
@@ -1543,7 +1545,7 @@ static int fr_trie_key_insert(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p,
 
                path = GET_PATH(trie);
 
-               if (!fr_cond_assert((start_bit & 0x07) == path->start_bit)) return -1;
+               fr_cond_assert((start_bit & 0x07) == path->start_bit);
 
                /*
                 *      See how long the common prefix is.
@@ -1558,7 +1560,7 @@ static int fr_trie_key_insert(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p,
                 *      path, and insert the key into it's child.
                 */
                if (lcp == path->length) {
-                       if (!fr_cond_assert(!IS_PATH(path->trie))) return -1;
+                       fr_cond_assert(!IS_PATH(path->trie));
 
                        return fr_trie_key_insert(ft, path, &path->trie,
                                                  key, start_bit + lcp, end_bit, subtrie);
@@ -1585,7 +1587,7 @@ static int fr_trie_key_insert(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p,
 insert_node:
 #endif
 
-       if (!fr_cond_assert(IS_NODE(trie))) return -1;
+       fr_cond_assert(IS_NODE(trie));
        node = trie;
        fr_trie_node_verify(node);
 
@@ -1605,9 +1607,9 @@ insert_node:
 
                node2 = fr_trie_node_alloc(ft, node, size);
                if (!node2) {
+                       fr_cond_assert(0 == 1);
                        MPRINT("FAILED %d\n", __LINE__);
-
-                       if (!fr_cond_assert(0 == 1)) return -1;
+                       return -1;
                }
 
                chunk = get_chunk(key, size, start_bit, end_bit);
@@ -1625,14 +1627,14 @@ insert_node:
        }
 
        chunk = get_chunk(key, node->size, start_bit, end_bit);
-       if (!fr_cond_assert(chunk < (1 << node->size))) return -1;
+       fr_cond_assert(chunk < (1 << node->size));
 
        incr = (node->trie[chunk] == NULL);
 
        rcode = fr_trie_key_insert(ft, node, &node->trie[chunk], key, next, end_bit, subtrie);
        if (rcode < 0) return rcode;
 
-       if (!fr_cond_assert(node->trie[chunk] != NULL)) return -1;
+       fr_cond_assert(node->trie[chunk] != NULL);
        node->used += incr;
 
        return 0;
@@ -1764,7 +1766,7 @@ static void *fr_trie_key_remove(fr_trie_t *ft, TALLOC_CTX *ctx, void **parent_p,
                                }
                        }
 
-                       if (!fr_cond_assert(i < (1 << node->size))) return NULL;
+                       fr_cond_assert(i < (1 << node->size));
 
                        /*
                         *      Convert the node to a PATH.
@@ -2027,7 +2029,8 @@ static int fr_trie_key_walk(void *trie, fr_trie_callback_t *cb, int depth, bool
         *      Nothing more to do, retun.
         */
        if (!trie) {
-               if (!fr_cond_assert(depth == 0)) return 0;
+               fr_cond_assert(depth == 0);
+               return 0;
        }
 
        /*
@@ -2084,7 +2087,7 @@ static int fr_trie_key_walk(void *trie, fr_trie_callback_t *cb, int depth, bool
                fr_trie_path_verify(path);
 
                if (path->start_bit == 0) {
-                       if (!fr_cond_assert((depth & 0x07) == 0)) return -1;
+                       fr_cond_assert((depth & 0x07) == 0);
                        memcpy(out, path->key, BYTES(path->length));
 
                } else {
@@ -2471,7 +2474,7 @@ static int command_verify(fr_trie_t *ft, UNUSED int argc, UNUSED char **argv, UN
 #ifdef WITH_TRIE_VERIFY
        fr_trie_verify(ft->trie);
 #else
-       rad_assert(ft != NULL);
+       fr_cond_assert(ft != NULL);
 #endif
        return 0;
 }