Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: cocci@inria.fr
Subject: Re: [cocci] Analysis challenges with SmPL for pass-through functions?
Date: Sun, 19 Oct 2025 22:10:04 +0800 (+08)	[thread overview]
Message-ID: <d1b6d33d-cfc0-ff6b-47de-7bbc28e8a7d@inria.fr> (raw)
In-Reply-To: <4afdfd37-3177-4480-9648-ab0d7f59097c@web.de>

[-- Attachment #1: Type: text/plain, Size: 2093 bytes --]



On Sun, 19 Oct 2025, Markus Elfring wrote:

> Hello,
>
> I am curious if further developers will become interested to discuss technical
> details like the following (in combination with the software “Coccinelle 1.3.0”).
>
> Another source file example:
> #include <string.h>
>
> void my_test_copy(void)
> {
>  char text[123];
>  char* target = strcpy(text, "Hello!");
>  target = strcpy(target, "Bye");
> }
>
>
> A)
> SmPL script variant:
> @display@
> constant char[] input;
> identifier x, y;
> @@
> *y = strcpy(x, input)
>
> Test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch show_selected_strcpy_calls.cocci test-copy_literal_to_buffer2.c
> …
> @@ -3,6 +3,4 @@
>  void my_test_copy(void)
>  {
>   char text[123];
> - char* target = strcpy(text, "Hello!");
> - target = strcpy(target, "Bye");
>  }
>
>
> B)
> SmPL script variant:
> @display2@
> constant char[] literal;
> identifier i;
> @@
> *i = strcpy(i, literal)
>
> Test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch show_selected_strcpy_calls2.cocci test-copy_literal_to_buffer2.c
> …
> @@ -4,5 +4,4 @@ void my_test_copy(void)
>  {
>   char text[123];
>   char* target = strcpy(text, "Hello!");
> - target = strcpy(target, "Bye");
>  }
>
>
> The variable definition was not matched by the second source code search approach
> because the used identifiers are obviously different there.
> This aspect did not hinder an additional match by the first source code search approach
> according to another assignment for the variable “target” while the same identifier
> was found by two metavariables.
>
> Will further clarifications become more interesting for corresponding case distinctions?

There is no guarantee that two metavariables don't match the same thing.
If you don't want them to match the same thing, then you need to use a
disjunction.  In the first branch, the same metavariable should be used
twice, and then in the second branch there would be the two different
metavariables.  The match should only be indicated for the second branch.

julia

  reply	other threads:[~2025-10-19 14:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-19 14:00 [cocci] Analysis challenges with SmPL for pass-through functions? Markus Elfring
2025-10-19 14:10 ` Julia Lawall [this message]
2025-10-19 14:25   ` Markus Elfring
2025-10-19 14:30     ` Julia Lawall
2025-10-19 14:37       ` Markus Elfring
2025-10-19 14:40         ` Julia Lawall
2025-10-19 14:50           ` Markus Elfring
2025-10-21  6:16   ` Markus Elfring
2025-10-21  9:12     ` Julia Lawall
2025-10-21  9:40       ` Markus Elfring
2025-10-24 19:03   ` [cocci] Terminology evolution for SmPL? Markus Elfring
2025-10-22  9:20 ` [cocci] Analysis challenges with SmPL for pass-through functions? 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=d1b6d33d-cfc0-ff6b-47de-7bbc28e8a7d@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=Markus.Elfring@web.de \
    --cc=cocci@inria.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 read-only IMAP folder(s) and NNTP newsgroup(s).