]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic/pack: fix a bug/inconsistency
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 19 Apr 2018 12:28:22 +0000 (14:28 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 23 Apr 2018 07:53:25 +0000 (09:53 +0200)
The NULL is never tested, and it was breaking our usual iteration pattern.

lib/generic/pack.h

index 90c1b7218872e4f49f86012a6a2cdc4a2cdac32b..7d906e0bdf002be90b98806c81ae674648c6c4b4 100644 (file)
@@ -96,13 +96,17 @@ typedef array_t(uint8_t) pack_t;
 #define pack_reserve_mm(pack, objs_count, objs_len, reserve, baton) \
        array_reserve_mm((pack), (pack).len + (sizeof(pack_objlen_t)*(objs_count) + (objs_len)), (reserve), (baton))
 
-/** Return pointer to first packed object. */
+/** Return pointer to first packed object.
+ *
+ * Recommended way to iterate:
+ *   for (uint8_t *it = pack_head(pack); it != pack_tail(pack); it = pack_ob_next(it))
+ */
 #define pack_head(pack) \
-       ((pack).len > 0 ? &((pack).at[0]) : NULL)
+       (&(pack).at[0])
 
 /** Return pack end pointer. */
 #define pack_tail(pack) \
-       &((pack).at[(pack).len])
+       (&(pack).at[(pack).len])
 
 /** Return packed object length. */
 static inline pack_objlen_t pack_obj_len(uint8_t *it)