Hi all, I do have a problem for writing a python scripts in a cocci semantic patch. I don't really know if it's a "feature" or a bug, the context is the following.
A cocci file (rule1and2.cocci) contains several rules (say 2 for the example),
and a single python script (at the end).
The python script is using matches of the rules:
@script:python@
rule1_matches << rule_1.p;
rule2_matches << rule_2.p;
@@
if (len(rule1_matches)>0):
for m in rule1_matches:
print "File <%s>, line %s" % (m.file,m.line)
if (len(rule2_matches)>0):
for m in rule1_matches:
print "File <%s>, line %s" % (m.file,m.line)
it looks like the script is executed iff both rules (1 & 2) matches.
Find attached the files to reproduce the "problem":
Commands giving no output
spatch -sp rule1and2.cocci -no_show_diff 1-1-2.c
spatch -sp rule1and2.cocci -no_show_diff 1-1-1.c
Command giving output
spatch -sp rule1and2.cocci -no_show_diff 1-1-1.c 1-1-2.c
Is this an expected behavior?
Should I write a python script for EACH rules?
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
#include <stdio.h>
void foo() {
}
int
main(void) {
int x;
int y;
if ( (x = y) != 0 )
{
foo() ;
}
if ( (y = 1) > 0) {
return 1;
}
}
#include <stdio.h>
int
main(void) {
int i;
int flag;
flag = 1;
for ( i = 0 ; (i < 5 ) && (flag == 1) ; i++)
{
printf("blah\n");
if (i>3)
{
flag = 0 ;
}
}
}
rule1and2.cocci
Description: Binary data
_______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
