[master] e15af112d cocci: Masquerade foreach loops as if statements

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Thu Jul 13 09:50:12 UTC 2023


commit e15af112d54008024a9ee09b0c2da91746505d8a
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Jul 13 11:45:52 2023 +0200

    cocci: Masquerade foreach loops as if statements
    
    Inside the loop the element is in fact, not null. Only one occurrence
    was caught by check_obj.cocci, which shows that more code is still not
    understood by Coccinelle. For example, it doesn't seem to enjoy #undef
    directives inside functions.

diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index dbf10fec1..ce7cf6630 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -320,7 +320,7 @@ hcb_cleaner(struct worker *wrk, void *priv)
 			FREE_OBJ(y);
 		}
 		VTAILQ_FOREACH_SAFE(oh, &dead_h, hoh_list, oh2) {
-			CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
+			CHECK_OBJ(oh, OBJHEAD_MAGIC);
 			VTAILQ_REMOVE(&dead_h, oh, hoh_list);
 			HSH_DeleteObjHead(wrk, oh);
 		}
diff --git a/tools/coccinelle/vdef.h b/tools/coccinelle/vdef.h
index b78f0d310..43ca64595 100644
--- a/tools/coccinelle/vdef.h
+++ b/tools/coccinelle/vdef.h
@@ -24,6 +24,10 @@
 #define VTAILQ_HEAD_INITIALIZER(t)	0
 #define VSTAILQ_HEAD_INITIALIZER(t)	0
 
+#define VTAILQ_FOREACH(o, h, l)			if (o != NULL)
+#define VTAILQ_FOREACH_SAFE(o, h, l, o2)	if (o != NULL)
+#define VTAILQ_FOREACH_REVERSE(o, h, t, l)	if (o != NULL)
+
 /* include/vtree.h */
 #define VRBT_ENTRY(x)		unsigned
 #define VRBT_HEAD(x, y)		unsigned


More information about the varnish-commit mailing list