]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: fix the equals-null transformation
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 1 Oct 2020 14:13:30 +0000 (16:13 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sun, 4 Oct 2020 10:32:21 +0000 (12:32 +0200)
The original issue with this transformation was that we were replacing
the whole if statement instead of just the expression inside. That
caused the code to be weirdly formatted, as Coccinelle put a new block
around each replaced if statement.

This version replaces just the inner expression if it's in its incorrect
form, otherwise it just accepts it (to avoid recursion).

coccinelle/equals-null.cocci

index 957d828a8376abc6ad0af8cfd9842995e819cb42..3fce0f4caaee1a98029276a786b1e6288c6b23f7 100644 (file)
@@ -2,13 +2,28 @@
 expression e;
 statement s;
 @@
-- if (e == NULL)
-+ if (!e)
-s
+if (
+(
+!e
+|
+- e == NULL
++ !e
+)
+   )
+   {...}
+else s
+
 @@
 expression e;
 statement s;
 @@
-- if (e != NULL)
-+ if (e)
-s
+if (
+(
+e
+|
+- e != NULL
++ e
+)
+   )
+   {...}
+else s