]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tools: run check-coccinelle.sh with (updated) parsing_hacks.h
authorMichael Vogt <michael@amutable.com>
Tue, 31 Mar 2026 17:01:28 +0000 (19:01 +0200)
committerMichael Vogt <michael@amutable.com>
Sat, 11 Apr 2026 19:15:12 +0000 (21:15 +0200)
This commit runs the check-coccinelle checker scripts with the
parsing_hacks.h. Because this was missing before there were some
issues that did not get flagged.

While at it it also adds some missing cleanup attributes and
iterators to get better results. Its a bit sad that there is no
(easy/obvious) way to detect when new things are needed for
parsing_hacks.h

coccinelle/parsing_hacks.h
tools/check-coccinelle.sh

index 24a9f1be5ecabe8ce5602db6ba3ee5562563aa61..774dbb1e6a1024454d4e2dd35d6d07aa037c70a7 100644 (file)
 /* Coccinelle doesn't know this keyword, so just drop it, since it's not important for any of our rules. */
 #define thread_local
 
+/* Coccinelle can't handle the __attribute__((__cleanup__(x))) GCC extension used by our _cleanup_*
+ * macros. Without this, any variable declared with _cleanup_free_ or _cleanup_(foo) makes the whole
+ * function unparsable. Drop the attribute since it's not relevant for semantic checks. */
+#define _cleanup_free_
+#define _cleanup_(x)
+
 /* Coccinelle fails to parse these from the included headers, so let's just drop them. */
 #define PAM_EXTERN
 #define STACK_OF(x)
 
 /* Mark a couple of iterator explicitly as iterators, otherwise Coccinelle gets a bit confused. Coccinelle
  * can usually infer this information automagically, but in these specific cases it needs a bit of help. */
+#define FOREACH_ARGUMENT(entry, ...) YACFE_ITERATOR
 #define FOREACH_ARRAY(i, array, num) YACFE_ITERATOR
-#define FOREACH_ELEMENT(i, array) YACFE_ITERATOR
+#define FOREACH_DIRENT(de, d, on_error) YACFE_ITERATOR
 #define FOREACH_DIRENT_ALL(de, d, on_error) YACFE_ITERATOR
+#define FOREACH_DIRENT_IN_BUFFER(de, buf, sz) YACFE_ITERATOR
+#define FOREACH_ELEMENT(i, array) YACFE_ITERATOR
 #define FOREACH_STRING(x, y, ...) YACFE_ITERATOR
 #define HASHMAP_FOREACH(e, h) YACFE_ITERATOR
+#define HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
 #define LIST_FOREACH(name, i, head) YACFE_ITERATOR
+#define LIST_FOREACH_BACKWARDS(name, i, start) YACFE_ITERATOR
+#define NULSTR_FOREACH(s, l) YACFE_ITERATOR
+#define NULSTR_FOREACH_PAIR(i, j, l) YACFE_ITERATOR
 #define ORDERED_HASHMAP_FOREACH(e, h) YACFE_ITERATOR
+#define ORDERED_HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
 #define SET_FOREACH(e, s) YACFE_ITERATOR
-#define STRV_FOREACH_BACKWARDS YACFE_ITERATOR
+#define SET_FOREACH_MOVE(e, d, s) YACFE_ITERATOR
+#define STRV_FOREACH(s, l) YACFE_ITERATOR
+#define STRV_FOREACH_BACKWARDS(s, l) YACFE_ITERATOR
+#define STRV_FOREACH_PAIR(x, y, l) YACFE_ITERATOR
 
 /* Coccinelle really doesn't like multiline macros that are not in the "usual" do { ... } while(0) format, so
  * let's help it a little here by providing simplified one-line versions. */
index c7d1f6f6da0d58527ad2b8f207e4527193e37de8..8a436624c97e7a9e838a87e99b5eb08a00263f43 100755 (executable)
@@ -10,7 +10,7 @@ FOUND=0
 
 for cocci in "$COCCI_DIR"/check-*.cocci; do
     [[ -f "$cocci" ]] || continue
-    output=$(spatch --very-quiet --sp-file "$cocci" --dir "$SRC_DIR" 2>&1)
+    output=$(spatch --very-quiet --macro-file-builtins "$COCCI_DIR/parsing_hacks.h" --sp-file "$cocci" --dir "$SRC_DIR" 2>&1)
     if [[ -n "$output" ]]; then
         echo "FAIL: $(basename "$cocci") found issues in $SRC_DIR:"
         echo "$output"