coccinelle: Extend address test from ifaddr semantic patch to test expressions
authorJérémy LEFAURE <jeremy.lefaure@netatmo.com>
Fri, 1 Jul 2022 16:01:36 +0000 (16:01 +0000)
committerJulia Lawall <Julia.Lawall@inria.fr>
Sun, 3 Jul 2022 21:45:05 +0000 (23:45 +0200)
The test of an expression's address does not necessarily represent the
whole condition, it may only be a part of it. Also, an expression's
address is likely to be non-zero in every test expression, not only in
if statements.

This change aims at detecting an address test in more complex conditions
and not only in if statements.

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@netatmo.com>
Signed-off-by: Julia Lawall <julia.lawall@inria.fr>
scripts/coccinelle/misc/ifaddr.cocci [deleted file]
scripts/coccinelle/misc/test_addr.cocci [new file with mode: 0644]

diff --git a/scripts/coccinelle/misc/ifaddr.cocci b/scripts/coccinelle/misc/ifaddr.cocci
deleted file mode 100644 (file)
index fc92e8f..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/// The address of a variable or field is likely always to be non-zero.
-///
-// Confidence: High
-// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
-// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
-// URL: http://coccinelle.lip6.fr/
-// Comments:
-// Options: --no-includes --include-headers
-
-virtual org
-virtual report
-virtual context
-
-@r@
-expression x;
-statement S1,S2;
-position p;
-@@
-
-*if@p (&x)
- S1 else S2
-
-@script:python depends on org@
-p << r.p;
-@@
-
-cocci.print_main("test of a variable/field address",p)
-
-@script:python depends on report@
-p << r.p;
-@@
-
-msg = "ERROR: test of a variable/field address"
-coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/misc/test_addr.cocci b/scripts/coccinelle/misc/test_addr.cocci
new file mode 100644 (file)
index 0000000..029db90
--- /dev/null
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// The address of a variable or field is likely always to be non-zero.
+///
+// Confidence: High
+// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
+// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual org
+virtual report
+virtual context
+
+@r@
+expression x;
+position p;
+@@
+
+*\(&x@p == NULL \| &x@p != NULL\)
+
+@script:python depends on org@
+p << r.p;
+@@
+
+cocci.print_main("test of a variable/field address",p)
+
+@script:python depends on report@
+p << r.p;
+@@
+
+msg = "ERROR: test of a variable/field address"
+coccilib.report.print_report(p[0],msg)