On Wed, 21 Jan 2015, Eliseo Martínez wrote:

> > I'm not following the goal here.
>
> I have a list of functions that I know can’t return NULL.
> I want to look for places where after invoking one of those functions, 
> returned value is (unnecessarily) checked for being null or non-null.
>
> I have a working spatch now:
> ```
> @@ identifier func =~ "^(vim_strsave|list_alloc)$"; statement S; @@
>
> (
> * if (func(...) == NULL)
>     S
> |
> * if (func(...) != NULL)
>     S
> )
>
> @@ identifier func =~ "^(vim_strsave|list_alloc)$"; identifier var; statement 
> S; expression E; @@
>
>   var = func(...);
>   ... when != var = E
> (
> * if (var == NULL)
>     S
> |
> * if (var != NULL)
>     S
> )
> ```
>
> That was basically my first approach in previous messages, but there were 2 
> minor issues:
> - The extra semicolon you warned against. This is, I had to replace “S;” with 
> “S”.
> - A second, weird thing:
>     If I put “S” on the same line as the “if”, it finds nothing.
>     If I put “S” on a separated line, then it works.
>     Is this a bug? I thought whitespace was never significant…

The difference would be whether the S is under the * or outside it.  But I
don't see why it would matter.  I will check.

If you replace your if by

if (x == NULL) S1 else S2

then it should catch everything, including the != case and the one branch
case.  This is due to various isomorphisms, as described in standard.iso.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to