On Wed, 14 Dec 2011, SF Markus Elfring wrote:
I'm a bit surprised, because the grammar was (manually) derived from
the implementation, but maybe it was put there in hopes that it would be
implemented soon.
I hope that the control flow construct "do ... while" will be supported by
the Coccinelle software in the future. ;-)
Perhaps you could put it in the pattern matching part as well. It depends
on
what you are trying to do.
I do not get my example to filter the source code completely as expected so
far.
elfring@Sonne:~/Projekte/Coccinelle/Probe> P=../my_pattern.cocci && cat $P &&
echo '-----' && spatch -sp_file $P Cstdlib-test1.c -I /usr/include
@r@
identifier f;
@@
f(...);
@is_void@
identifier r.f;
@@
void f(...);
@is_assigned@
position p;
expression x, y;
expression f != {strcpy, strcat};
statement S1, S2, S3, S4;
@@
y@p = x(...);
... when != if (<+...y...+>) S1 else S2
when != f(...,(<+...y...+>),...)
when != for (...;<+...y...+>;...) S3
when != while (<+...y...+>) S4
when != switch (<+...y...+>) { case ... : ... }
when != (<+...y...+>) ? ... : ...
@is_assigned_without_when_filters@
position p != is_assigned.p;
expression x, y;
@@
*y@p = x(...);
@depends on !is_void@
identifier r.f != {strcpy, strcat};
identifier g;
@@
g(...)
{<+...
* f(...);
...+>}
Here, in the place of *f(...); you could write
(
\(strcpy\|strcat\|printf\|signal\)(...);
|
*f(...);
)
Where the first list could be extended with other function names. Perhaps
that is what tyou are sking for below.
julia
-----
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: Cstdlib-test1.c
diff =
--- Cstdlib-test1.c
+++ /tmp/cocci-output-8360-856b7c-Cstdlib-test1.c
@@ -16,22 +16,15 @@ int main(void)
char* x = (char*) malloc(123);
strcpy(x, name);
- signal(SIGTERM, action);
{
FILE* c = fopen(x, "r");
{
- printf("file: %s\npointer: %p\n", x, c);
- fflush(stdout);
- fread(x, 1, 12, c);
- fclose(c);
}
- realloc(x, 456);
}
- fprintf(stderr, "terminated: %d", (int) termination);
return EXIT_SUCCESS;
}
Have you got another idea for improvement?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)