From: Frantisek Sumsal Date: Thu, 1 Oct 2020 14:13:30 +0000 (+0200) Subject: coccinelle: fix the equals-null transformation X-Git-Tag: v247-rc1~130^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=473de9b7086d4de122283f68e554ac4357369e34;p=thirdparty%2Fsystemd.git 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). --- diff --git a/coccinelle/equals-null.cocci b/coccinelle/equals-null.cocci index 957d828a837..3fce0f4caae 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