]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils/kr_cache_gc: minor nitpicks
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 14 Jun 2019 12:59:07 +0000 (14:59 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:22 +0000 (15:59 +0200)
It should be no real change, just better readability, hopefully.

utils/kr_cache_gc/db.c
utils/kr_cache_gc/kr_cache_gc.c

index cb82ba646e96a116f653fcdd07ae2a7ea5ed857c..16f287b816458efc9a7e216c6fc560d8f30863bc 100644 (file)
@@ -90,20 +90,20 @@ const uint16_t *kr_gc_key_consistent(knot_db_val_t key)
 {
        const static uint16_t NSEC1 = KNOT_RRTYPE_NSEC;
        const static uint16_t NSEC3 = KNOT_RRTYPE_NSEC3;
-       uint8_t *p = key.data;
-       while(*p != 0) {
-               while(*p++ != 0) {
-                       if (p - (uint8_t *)key.data >= key.len) {
-                               return NULL;
-                       }
-               }
+       // find the first double zero in the key; CACHE_KEY_DEF
+       const uint8_t *kd = key.data;
+       ssize_t i;
+       for (i = 2; !(kd[i - 1] == 0 && kd[i - 2] == 0); ++i) {
+               if (i >= key.len) return NULL;
        }
-       if (p - (uint8_t *)key.data >= key.len) {
-               return NULL;
-       }
-       switch (*++p) {
+       // the next character can be used for classification
+       switch (kd[i]) {
        case 'E':
-               return (p + 2 - (uint8_t *)key.data >= key.len ? NULL : (uint16_t *)(p + 1));
+               if (i + 1 + sizeof(uint16_t) > key.len) {
+                       assert(!EINVAL);
+                       return NULL;
+               }
+               return (uint16_t *)&kd[i + 1];
        case '1':
                return &NSEC1;
        case '3':
index 3e848d6b6ba47c954effb933121a847558b8268b..e74ff332acdb9613319239590709d8454ec36ff6 100644 (file)
@@ -216,7 +216,7 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg)
                switch (ret) {
                case KNOT_EOK:
                        deleted_records++;
-                       const uint16_t *entry_type = ret == KNOT_EOK ? kr_gc_key_consistent(**i) : NULL;
+                       const uint16_t *entry_type = kr_gc_key_consistent(**i);
                        assert(entry_type != NULL);
                        rrtypelist_add(&deleted_rrtypes, *entry_type);
                        break;