tools: run check-coccinelle.sh with (updated) parsing_hacks.h

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
This commit is contained in:
Michael Vogt
2026-04-11 21:15:12 +02:00
parent 53c87c096c
commit 3c6a713836
2 changed files with 20 additions and 3 deletions
+19 -2
View File
@@ -61,21 +61,38 @@
/* Coccinelle doesn't know this keyword, so just drop it, since it's not important for any of our rules. */ /* Coccinelle doesn't know this keyword, so just drop it, since it's not important for any of our rules. */
#define thread_local #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. */ /* Coccinelle fails to parse these from the included headers, so let's just drop them. */
#define PAM_EXTERN #define PAM_EXTERN
#define STACK_OF(x) #define STACK_OF(x)
/* Mark a couple of iterator explicitly as iterators, otherwise Coccinelle gets a bit confused. Coccinelle /* 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. */ * 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_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_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 FOREACH_STRING(x, y, ...) YACFE_ITERATOR
#define HASHMAP_FOREACH(e, h) 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(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(e, h) YACFE_ITERATOR
#define ORDERED_HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
#define SET_FOREACH(e, s) 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 /* 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. */ * let's help it a little here by providing simplified one-line versions. */
+1 -1
View File
@@ -10,7 +10,7 @@ FOUND=0
for cocci in "$COCCI_DIR"/check-*.cocci; do for cocci in "$COCCI_DIR"/check-*.cocci; do
[[ -f "$cocci" ]] || continue [[ -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 if [[ -n "$output" ]]; then
echo "FAIL: $(basename "$cocci") found issues in $SRC_DIR:" echo "FAIL: $(basename "$cocci") found issues in $SRC_DIR:"
echo "$output" echo "$output"