What is the correct type to use for declaring a metavariable that
possibly could match either variables or members in a struct?
Take for instance the following example source code:
--------------------------------
#include <stdio.h>
#include <stdlib.h>
struct some_struct {
int i;
char *s;
};
void test(void)
{
struct some_struct *ptr;
char *s;
s = malloc(100);
ptr = malloc(sizeof(struct some_struct));
ptr->s = malloc(100);
puts("done");
}
--------------------------------
With the following semantic patch:
--------------------------------
@@
identifier ptr;
//idexpression ptr;
//expression ptr;
expression E;
@@
ptr = malloc(E);
+if (ptr == NULL)
+ return;
--------------------------------
the "ptr->s" allocation is not matched unless "expression ptr" is
used. To use expression for this seems a bit too broadly to me. Is
this correct and the only way to do it? The SmPL Grammar document does
not go very deep in explaining the different types.
I have also asked this question on
http://stackoverflow.com/questions/2043787/what-is-the-correct-type-to-use-for-declaring-a-metavariable-that-possibly-could.
I will write up answers from any discussion here on the mailing list, but
think I would prefer to have answers there directly.
BR Håkon Løvdal
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)