> 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… 


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

Reply via email to