You need to leave the semicolon off the assignment in your rule.
I am still not convinced by this recommendation.
y = x(...); is a complete statement.
Should I change my filter pattern in any way if I want to check "a complete
statement"?
y = x(...) is an assignment term that is part of some bigger statement,
This is another filter approach to consider for improvement.
http://lists.diku.dk/pipermail/cocci/2011-December/002371.html
elfring@Sonne:~/Projekte/Coccinelle/Probe> PAT=../assignment_pattern2.cocci &&
cat $PAT && LINE='-----' && echo $LINE && SRC=Cstdlib-test1.c && cat $SRC &&
echo $LINE && spatch -sp_file $PAT $SRC -I /usr/include
@is_assigned@
position p;
expression x, y;
expression f != {strcpy, strcat, fread, fclose, realloc};
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(...)
-----
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
sig_atomic_t termination = 0;
static void action(int ID)
{
termination = ID;
}
int main(void)
{
static char const name[] = "check.txt";
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;
}
-----
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: Cstdlib-test1.c
diff =
--- Cstdlib-test1.c
+++ /tmp/cocci-output-24241-8bed1e-Cstdlib-test1.c
@@ -19,7 +19,6 @@ int main(void)
signal(SIGTERM, action);
{
- FILE* c = fopen(x, "r");
{
printf("file: %s\npointer: %p\n", x, c);
Which adjustments are still needed to get also the function call "malloc" marked
by this source code analysis?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)