cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: "Ondřej Surý" <ondrej@sury.org>
To: cocci@systeme.lip6.fr
Subject: [Cocci] "already tagged token" error?
Date: Wed, 20 Nov 2019 15:03:39 +0800	[thread overview]
Message-ID: <7FB3DF60-DEFB-434B-9A84-33575D34576E@sury.org> (raw)

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

             reply	other threads:[~2019-11-21 19:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20  7:03 Ondřej Surý [this message]
2019-11-21 20:06 ` [Cocci] "already tagged token" error? Julia Lawall
2019-11-21 20:42 ` [Cocci] Merging SmPL rules Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7FB3DF60-DEFB-434B-9A84-33575D34576E@sury.org \
    --to=ondrej@sury.org \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).