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

Joe Perches joe at perches.com
Fri Aug 24 02:25:51 CEST 2018


On Thu, 2018-08-23 at 20:17 -0400, Julia Lawall wrote:
> 
> 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.

People who write code do a lot of unnecessary things.
It's code I've seen in the past.
It occurs more with expressions than identifiers.

It'd be nice if coccinelle could parse arbitrarily
parenthesized code and script down to its minimal
logical requirements and match as maximally as possible.

cheers, Joe


More information about the Cocci mailing list