I want to change my code using a Coccinelle script:
// Before modification
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int *p;
*p=i;
return 0;
}
The expected result is:
// After modification
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int *p;
if (p!=NULL)
*p=i;
return 0;
}
My Coccinelle script is as follows:
@rule1@
type T;
T* ptr;
expression E;
@@
-*ptr= E;
+ if (ptr!=NULL)
+ptr=E;
My script is wrong because the "star" operator is used by Coccinelle. Could anyone help me to know for what the "star" operator is useful because I am a little bit confused about this operator. How can I modify my script to get the expected result?