Expression is the only option. It is more general than you might expect,
but valid C code shouldn't have that extra generality. On the other hand,
there could be a macro call to the left of the assignment, and perhaps
you would like to match that too.
julia
On Mon, 11 Jan 2010, Håkon Løvdal wrote:
> 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)
> _______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)