]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils/cache_gc/db.c: replace asserts
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 24 Mar 2021 16:44:48 +0000 (17:44 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 25 May 2021 12:39:43 +0000 (14:39 +0200)
utils/cache_gc/db.c

index b6bfaacab6a82dbd142d2665691b903fd0517a0d..d164ea7b36d2cfffe91d828e0d707e50a23d2f2f 100644 (file)
@@ -76,20 +76,17 @@ int kr_gc_key_consistent(knot_db_val_t key)
        } else {
                /* find the first double zero in the key */
                for (i = 2; kd[i - 1] || kd[i - 2]; ++i) {
-                       if (i >= key.len) {
-                               // TODO: assert(!EINVAL) -> kr_assume()
+                       if (!kr_assume(i < key.len))
                                return kr_error(EINVAL);
-                       }
                }
        }
        // the next character can be used for classification
        switch (kd[i]) {
        case 'E':
-               if (i + 1 + sizeof(uint16_t) > key.len) {
-                       assert(!EINVAL);
-                       return kr_error(EINVAL);
-               }
+               (void)0; // C can't have a variable definition following a label
                uint16_t type;
+               if (!kr_assume(i + 1 + sizeof(type) <= key.len))
+                       return kr_error(EINVAL);
                memcpy(&type, kd + i + 1, sizeof(type));
                return type;
        case '1':
@@ -99,7 +96,7 @@ int kr_gc_key_consistent(knot_db_val_t key)
        case 'S': // the rtt_state entries are considered inconsistent, at least for now
                return -1;
        default:
-               assert(!EINVAL);
+               (void)!kr_assume(!EINVAL);
                return kr_error(EINVAL);
        }
 }