summaryrefslogtreecommitdiff
path: root/coccinelle
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2020-10-01 16:13:30 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2020-10-04 12:32:21 +0200
commit473de9b7086d4de122283f68e554ac4357369e34 (patch)
tree4434a0105dc5e48fe556a2e8ba38f41c2ace3bc1 /coccinelle
parent3bc3c734c63450bbcb1f8182e32a5dbc2eabe5b8 (diff)
downloadsystemd-473de9b7086d4de122283f68e554ac4357369e34.tar.gz
coccinelle: fix the equals-null transformation
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).
Diffstat (limited to 'coccinelle')
-rw-r--r--coccinelle/equals-null.cocci27
1 files changed, 21 insertions, 6 deletions
diff --git a/coccinelle/equals-null.cocci b/coccinelle/equals-null.cocci
index 957d828a83..3fce0f4caa 100644
--- a/coccinelle/equals-null.cocci
+++ b/coccinelle/equals-null.cocci
@@ -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