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

Julia Lawall julia.lawall at lip6.fr
Fri Aug 24 00:45:18 CEST 2018



On Thu, 23 Aug 2018, 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:
>
>
> $ cat isomorphisms.c
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
>         int a, b, c;
>
>         a = atoi(argv[1]);
>         b = atoi(argv[2]);
>         c = atoi(argv[3]);
>
>         printf("%d\n", a + b * c);
>         printf("%d\n", (a + b) * c);
>         printf("%d\n", a + (b * c));
>         printf("%d\n", b * c + a);
>         printf("%d\n", b * (c + a));
>         printf("%d\n", (b * c) + a);
>
>         return 0;
> }
> $ cat match.cocci
> @@
> identifier A, B, C;
> @@
>
> * (A * B) + C
>
> $ spatch -sp-file match.cocci isomorphisms.c
> init_defs_builtins: /usr/lib/coccinelle/standard.h
> HANDLING: isomorphisms.c
> diff =
> --- isomorphisms.c
> +++ /tmp/cocci-output-8402-870fd6-isomorphisms.c
> @@ -9,12 +9,8 @@ int main(int argc, char *argv[])
>         b = atoi(argv[2]);
>         c = atoi(argv[3]);
>
> -       printf("%d\n", a + b * c);
>         printf("%d\n", (a + b) * c);
> -       printf("%d\n", a + (b * c));
> -       printf("%d\n", b * c + a);
>         printf("%d\n", b * (c + a));
> -       printf("%d\n", (b * c) + a);
>
>         return 0;
>  }
>
>
> So it sounds like I should put parens around all kinds of things in my rules...

If you think someone might reasonably use parentheses somewhere, you
should put them.

julia


More information about the Cocci mailing list