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

Julia Lawall julia.lawall at lip6.fr
Fri Aug 24 02:17:16 CEST 2018



On Thu, 23 Aug 2018, Joe Perches wrote:

> 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;
>  }

I'm not sure to get the point.

If you think that people may fully parenthesize the code, then ((a * b) +
c) would be a reasonable option for the pattern.  I'm not sure why double
parentheses, ((a * b)) + c, should exist in the first place.

julia


More information about the Cocci mailing list