> Can you give an example of some code in which you find a match?
Here they are some examples of code matched by
```
@@ 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
)
```
but missed if we put S in the same line as “if”.
```
p = home_replace_save(NULL, files[i]);
* if (p != NULL) {
free(files[i]);
files[i] = p;
}
```
```
p = vim_strsave(p);
rettv->vval.v_string = p;
* if (p != NULL)
shorten_dir(p);
```
```
if (temp_result != NULL && nextcmd == NULL) {
retval = xmalloc(STRLEN(temp_result) + (expr_start - in_start)
+ (in_end - expr_end) + 1);
STRCPY(retval, in_start);
STRCAT(retval, temp_result);
STRCAT(retval, expr_end + 1);
}
free(temp_result);
*in_end = c1; /* put char back for error messages */
*expr_start = '{';
*expr_end = '}';
* if (retval != NULL) {
temp_result = find_name_end(retval, &expr_start, &expr_end, 0);
if (expr_start != NULL) {
/* Further expansion! */
temp_result = make_expanded_name(retval, expr_start,
expr_end, temp_result);
free(retval);
retval = temp_result;
}
}
```
This last case is a false positive, as retval can be null if we don’t enter the
“if” where it’s assigned. But it conforms to the specified spatch, so I add it
as an example of more complex code matched by it.
So, when S is in a separated line, everything seems to work perfectly. I have
63 matches for that in my code.
If I put S in the same line as “if”, then it finds 0 matches.
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci