2

I want to match

*ptr=value;

in a C code and then replace it by

CHECK_PTR(ptr)
*ptr=value;

CHECK_PTR() is a macro that check if ptr is not null

I write a Coccinelle script to do the work

@rule1@
type T;
T* ptr;
expression E;
@@
-\*ptr=E;
+CHECK_PTR(ptr)
+*ptr=E;

But this doesn't work because of the star operator. Here i used the backslash to escape the * however this didn't give any result

Could you help me please

fedi
  • 368
  • 3
  • 7
  • 18

1 Answers1

1

I faced the same problem few days ago and this is the answer to your problem

"Column 0 is different than the others. Just pu a space in front of your * and everything will be fine.

This problem commonly arises for parentheses. For example if you want to add a new last argument for a function, you might say:

f(27
+ , 145
)

In this case, Coccinelle can detect the potential problem and will complain. Because ( | and ) in column 0 are used for a disjunction (a set oo different possible matches and transformations. For *, though it doesn't know which you want." Julia Lawall

Bou6
  • 84
  • 2
  • 10