Could you make a simpler example?
I hope so ...
The parts that work are not useful to me here because they don have any impact
on the parts that don work.
I was not sure. I imagine that usable parts might influence others in unexpected
ways eventually.
elfring@Sonne:~/Projekte/Coccinelle/Probe> SRC=f-ptr-test1.c && cat $SRC && echo
'-----' && PAT=assignment_pattern5.cocci && cat $PAT && echo '-----' && spatch
-sp_file $PAT $SRC
void my_log(char const * text)
{
/* Write something ... */
}
int my_safe_log(char const * text)
{
if (!text)
return 1;
my_log(text);
return 0;
}
char const * const my_message(void)
{
return "Surprise!";
}
int my_status(void)
{
return 1;
}
int my_addition(char a, char b)
{
return a + b;
}
int main(void)
{
struct my_operations
{
void (*log)(char const * t);
int (*safe_log)(char const * t);
char const * const (*get_message)(void);
int (*is_ready)(void);
int (*add)(char a, char b);
} mo = {my_log, my_safe_log, my_message, my_status, my_addition}, * mop = &mo;
char const * const x = mo.get_message();
int y = mop->is_ready();
y = mop->add(1, 2);
y = mo.add(3, 4);
mo.log(mo.get_message());
mo.is_ready();
my_safe_log(0);
mo.safe_log(0);
mop->safe_log(0);
}
-----
@is_assigned@
position p;
expression a, b, v, w, x, y;
expression f != {strcpy, strcat, fread, fclose};
identifier g != {my_strcpy, my_strcat, my_fread, my_fclose, log, add};
identifier h != {my_strcpy, my_strcat, my_fread, my_fclose, log, add};
identifier c, d;
statement S1, S2, S3, S4;
type t;
@@
(
y@p = (t) (x)(...)
|
y@p = (t) (a)->c(...)
|
y@p = (t) (b).d(...)
)
... when != if (<+...y...+>) S1 else S2
when != (f)(...,<+...y...+>,...)
when != (v)->g(...,<+...y...+>,...)
when != (w).h(...,<+...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 a, b, x, y;
identifier is_assigned.c, is_assigned.d;
type t;
@@
(
*y@p = (t) (x)(...)
|
*y@p = (t) (a)->c(...)
|
*y@p = (t) (b).d(...)
)
-----
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: f-ptr-test1.c
diff =
--- f-ptr-test1.c
+++ /tmp/cocci-output-16268-d16e2c-f-ptr-test1.c
@@ -39,8 +39,6 @@ int main(void)
} mo = {my_log, my_safe_log, my_message, my_status, my_addition}, * mop =
&mo;
char const * const x = mo.get_message();
- int y = mop->is_ready();
- y = mop->add(1, 2);
y = mo.add(3, 4);
mo.log(mo.get_message());
mo.is_ready();
Now I wonder why the line "y = mo.add(3, 4);" is not marked in the promising
analysis result.
Is this approach above small enough for further checks?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)