]> git.ipfire.org Git - thirdparty/git.git/commitdiff
contrib/coccinnelle: add equals-null.cocci
authorElia Pinto <gitter.spiros@gmail.com>
Sat, 30 Apr 2022 04:13:44 +0000 (04:13 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 May 2022 16:47:55 +0000 (09:47 -0700)
Add a coccinelle semantic patch necessary to reinforce the git coding style
guideline:

"Do not explicitly compute an integral value with constant 0 or '\ 0', or a
pointer value with constant NULL."

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/coccinelle/equals-null.cocci [new file with mode: 0644]

diff --git a/contrib/coccinelle/equals-null.cocci b/contrib/coccinelle/equals-null.cocci
new file mode 100644 (file)
index 0000000..92c7054
--- /dev/null
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+@@
+expression e;
+statement s;
+@@
+if (
+(
+!e
+|
+- e == NULL
++ !e
+)
+   )
+   {...}
+else s
+
+@@
+expression e;
+statement s;
+@@
+if (
+(
+e
+|
+- e != NULL
++ e
+)
+   )
+   {...}
+else s