cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] "already tagged token" error?
@ 2019-11-20  7:03 Ondřej Surý
  2019-11-21 20:06 ` Julia Lawall
  2019-11-21 20:42 ` [Cocci] Merging SmPL rules Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Ondřej Surý @ 2019-11-20  7:03 UTC (permalink / raw)
  To: cocci

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ý
ondrej@sury.org



_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-21 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20  7:03 [Cocci] "already tagged token" error? Ondřej Surý
2019-11-21 20:06 ` Julia Lawall
2019-11-21 20:42 ` [Cocci] Merging SmPL rules Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).