Hi,
this is the error we started getting with upgrade to 1.0.7 (from 1.0.6).
EXN: Failure("rule starting on line 1: already tagged token:\nC code
context\nFile \"./lib/dns/client.c\", line 1342, column 1, charpos = 33224\n
around = 'if',\n whole content = \tif (rctx == NULL)“)
EXN: Failure("rule starting on line 1: already tagged token:\nC code
context\nFile \"./lib/ns/tests/nstest.c\", line 704, column 1, charpos =
15998\n around = 'if',\n whole content = \tif (qctx != NULL) {")
The minimal reproducer is:
@@
statement S1, S2;
expression V;
@@
V = isc_mem_get(...);
- if (V == NULL) S1 else { S2 }
+ S2
--
On related note, what would be the correct way to write a rule for:
foo = isc_mem_get(…);
bar = isc_mem_get(…);
if (foo == NULL || bar == NULL) { … };
my naive approach:
@@
statement S;
expression V, E;
@@
V = isc_mem_get(...);
...
- if (V == NULL || E) S
+ if (E) S
doesn’t really work (it matches only a simple case, but not when there’s more
than two memory allocations).
I thought something like this might work:
@@
statement S;
expression V, E;
@@
V = isc_mem_get(...);
...
if (...
-|| V == NULL
...) S
@@
statement S;
expression V, E;
@@
V = isc_mem_get(...);
...
if (...
- V == NULL ||
...) S
would work, but it says:
minus: parse error:
File "x", line 10, column 0, charpos = 86
around = '...',
whole content = ...) S
--
And one last question:
Is there a simple way how to merge these these rules together? It seems like
it should be possible, but I wasn’t able to decipher the syntax for making
parts of the match to be remove to be optional (but if you point me to an
example in the base files or coccinellery, I would try harder).
@@
statement S1, S2;
expression V;
@@
V = isc_mem_get(...);
- if (V == NULL) S1 else { S2 }
+ S2
@@
statement S;
expression V;
@@
V = isc_mem_get(...);
- if (V == NULL) S
@@
type T;
statement S;
expression V;
@@
V = (T *)isc_mem_get(...);
- if (V == NULL) S
@@
statement S;
expression V;
@@
if (V == NULL) V = isc_mem_get(...);
- if (V == NULL) S
@@
type T;
expression V, E1, E2;
@@
- V = (T)isc_mem_get(E1, E2);
+ V = isc_mem_get(E1, E2);
Thank you,
--
Ondřej Surý
[email protected]
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci