From 38857318692acd02353b47129bb06326528a47c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20LEFAURE?= Date: Fri, 1 Jul 2022 16:01:36 +0000 Subject: coccinelle: Extend address test from ifaddr semantic patch to test expressions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Julia Lawall --- scripts/coccinelle/misc/ifaddr.cocci | 35 --------------------------------- scripts/coccinelle/misc/test_addr.cocci | 33 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 scripts/coccinelle/misc/ifaddr.cocci create mode 100644 scripts/coccinelle/misc/test_addr.cocci diff --git a/scripts/coccinelle/misc/ifaddr.cocci b/scripts/coccinelle/misc/ifaddr.cocci deleted file mode 100644 index fc92e8fcbfcb..000000000000 --- a/scripts/coccinelle/misc/ifaddr.cocci +++ /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 index 000000000000..029db9069c44 --- /dev/null +++ b/scripts/coccinelle/misc/test_addr.cocci @@ -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) -- cgit v1.2.3