Hi, I'm trying to write a rule that checks a syntaxic coding rule we
have at work. We have this stacked allocator, that has two functions:
t_push()/t_pop() placing marks on an allocation mark.
Any t_* allocation performed since a given t_push() is deallocated after
the next t_pop().
Some of our functions use this stack to do their stuff, some leave it
untouched, some return results allocated on it (for example we have a
t_sprintf).
Our coding rule is that any function that allocates on the stack without
guarding the allocation by t_push()/t_pop() should have a name starting
with t_.
I've written the attached .cocci. Though run on the following test:
void f1(void)
{
t_push();
t_foo();
t_pop();
}
void f2(void)
{
t_foo();
}
void f3(void)
{
t_bar();
t_push();
t_foo();
t_pop();
}
void f4(void)
{
t_push();
t_foo();
t_pop();
t_bar();
}
I expected it to yield errors for f2-f4, but it only does for f2.
Further investigation shows that it doesn't even report:
void f(void) {
t_something();
t_somethingelse();
}
Any idea if I'm doing something wrong or if that's a coccinelle bug ?
--
Intersec <http://www.intersec.com>
Pierre Habouzit <[email protected]> | Chief Software Architect
Tél : +33 (0)1 5570 3346
Mob : +33 (0)6 1636 8131
Fax : +33 (0)1 5570 3332
37 Rue Pierre Lhomme
92400 Courbevoie
@r@
type t;
position p;
identifier f !~= "^t_.*$";
identifier g ~= "^t_.*$";
@@
t f...@p(...) {
(
... when != t_push()
*g(...)
...
|
...
*g(...)
... when != t_pop()
)
}
@script:python@
x << r.p;
f << r.f;
@@
print "%s:%s:%s:%s should be named t_%s" % (x[0].file, x[0].line, x[0].column,
f, f)
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)