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?