[Cocci] spatch misbehavior?
Jim Meyering
jim at meyering.net
Tue Jun 2 15:42:39 CEST 2009
Julia Lawall wrote:
> I guess you expected to get: void f() { if (1) free(p); } as the output?
Precisely.
> The problem is in the position of + free(E)
> Coccinelle is not supposed to accept + code that is attached to a ( | )
> The strange thing is that it doesn't complain, and if you look at the
> semantic patch with -parse_cocci, it looks like it has distributed the +
> code to the right place. But for some reason it doesn't work in the end,
> so you are better off with the following rule:
>
> @r@
> expression E;
> @@
> (
> - if (E != NULL) free(E);
> + free(E);
> |
> - if (E != NULL) { free(E); }
> + free(E);
> )
>
> I will try to cause the original rule to work or fail in a more coherent
> way.
Thanks.
> Actually, you would be fine with the rule:
>
> @r@
> expression E;
> @@
> - if (E != NULL) { free(E); }
> + free(E);
>
> because by the braces4 isomorphism it will match a case where the braces
> are not there
Nice. That's even simpler.
Thank you!
More information about the Cocci
mailing list