test/cocci: Add a patch that reports checks of variable/field addresses.
authorSascha Wildner <saw@online.de>
Tue, 12 Jun 2012 11:05:17 +0000 (13:05 +0200)
committerSascha Wildner <saw@online.de>
Tue, 12 Jun 2012 11:05:17 +0000 (13:05 +0200)
Like:

int i;
...
if (&i)
   ...

Taken-from: Linux

test/cocci/ifaddr.cocci [new file with mode: 0644]

diff --git a/test/cocci/ifaddr.cocci b/test/cocci/ifaddr.cocci
new file mode 100644 (file)
index 0000000..8644378
--- /dev/null
@@ -0,0 +1,35 @@
+/// the address of a variable or field is non-zero is likely always to be
+/// non-zero
+///
+// Confidence: High
+// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.  GPLv2.
+// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.  GPLv2.
+// 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)