[Cocci] [Fwd: Re: [PATCH] rtc: sun6i: Use struct_size() in kzalloc()]

Joe Perches joe at perches.com
Fri Aug 24 00:59:39 CEST 2018


On Thu, 2018-08-23 at 15:27 -0700, Kees Cook wrote:
> On Thu, Aug 23, 2018 at 3:21 PM, Joe Perches <joe at perches.com> wrote:
> > On Thu, 2018-08-23 at 18:13 -0400, Julia Lawall wrote:
> > > 
> > > On Thu, 23 Aug 2018, Kees Cook wrote:
> > > 
> > > (a + b) * c
> > > 
> > > It will consider a pattern with the parentheses removed, but that pattern
> > > won't match anything, because real trees that consist of a + b * c are
> > > parsed in a different way.
> > 
> > spatch 1.0.4 doesn't seem to:
> > 
> > $ spatch --version
> > spatch version 1.0.4 with Python support and with PCRE support
> > $ cat match_mul.cocci
> > @@
> > expression a, b, c;
> > int d;
> > @@
> > 
> > *       d = a * b + c;
> 
> But "(a * b) + c" for the rule does:

Yes, but not for other valid uses like below:

$ cat match_mul.cocci
@@
expression a, b, c;
int d;
@@

*	d = (a * b) + c;
$ cat test_mul.c 
int a, b, c, d;

void foo(void)
{
	d = ((a * b) + c);
	d = ((a * b)) + c;
	d = (a * b) + c;
	d = a * b + c;
}
$ spatch -sp-file match_mul.cocci test_mul.c
init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: test_mul.c
diff = 
--- test_mul.c
+++ /tmp/cocci-output-23856-7e83f7-test_mul.c
@@ -4,6 +4,4 @@ void foo(void)
 {
 	d = ((a * b) + c);
 	d = ((a * b)) + c;
-	d = (a * b) + c;
-	d = a * b + c;
 }


More information about the Cocci mailing list