Coccinelle archive on lore.kernel.org
 help / color / Atom feed
From: Strace Labs <stracelabs@gmail.com>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] Changing format string usage with SmPL?
Date: Tue, 3 Dec 2019 01:30:14 -0200
Message-ID: <CABvP5W3E3zP28kUsmrvUOqv-Tu1YT3zvi6c=mqx+ahbMTycqAQ@mail.gmail.com> (raw)
In-Reply-To: <0c03f84d-a05b-2811-96aa-6f82541fb8a3@web.de>

[-- Attachment #1.1: Type: text/plain, Size: 2088 bytes --]

On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring <Markus.Elfring@web.de> wrote:

> > Basically, I intend to replace alls "%s" called with "mydata->name" by
> "%m" with "mydata" or "&mydata"
>
> How far would you get the desired source code transformation based on
> software extensions around a search pattern like the following.
> ..........
> Which algorithm will become sufficient for your data processing needs
> around the usage of functions with variadic arguments because of format
> strings?
>
>
Actually, I really didn't get why you're asking about that. because we are
talking about X and you're asking for Y. but, either way. that is not the
point. the point is because I am studying about the Coccinelle and I am
just trying to figure out if the tool could detect "%s" called with
"mydata->name" and then replace by "%m" and remove the "->name"

e.g: Once if we have:

int foo() {
  int id;
  struct mydata h1, *h2, s1, *s2;
  char *city = "Hello";
  my_printf("%s", s2->name);
  my_printf("hi hi %s gggg", h1.name);
  my_printf("1234 %d *%s* @ %d *%s* | *%s* -> city=%s", id, *s1.name
<http://s1.name>*, 12, *(*h2).name*, *h2->name*, city);
  my_printf("aaaa %s hhhhh", h2->name);
  my_printf("%s", city);
}

Then, replace by:

int foo() {
  int id;
  struct mydata h1, *h2, s1, *s2;
  char *city = "Hello";
  *my_printf("%m", s2);*
  *my_printf("hi hi %s gggg", &h1);*
  my_printf("1234 %d *%m* @ %d *%m* | *%m* -> city=%s", id, *s1.name
<http://s1.name>*, 12, *(*h2).name*, *h2->name*, city);
*  my_printf("aaaa %s hhhhh", h2);*
  my_printf("%s", city);
}

But, I've read again the other samples and the documentation. therefore, I
didn't figure out how it should be. btw, thank you Julia for the suggestion
performing the *Ocalm/make_expr/replace*. (Due to something wrong with the
Coccinelle distributed by Brew/Osx. I just rewrote your sample using Python
and the result was the same. But, I can't just replace all "%s" by "%m". As
I said, it should be only if the "%s" was declared to use "mydata->name".

so, I still fighting yet. thanks in Advance.

Regards,
> Markus
>

[-- Attachment #1.2: Type: text/html, Size: 3244 bytes --]

<div dir="ltr"><div dir="ltr">On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring &lt;<a href="mailto:Markus.Elfring@web.de">Markus.Elfring@web.de</a>&gt; wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">&gt; Basically, I intend to replace alls &quot;%s&quot; called with &quot;mydata-&gt;name&quot; by &quot;%m&quot; with &quot;mydata&quot; or &quot;&amp;mydata&quot;<br>
<br>
How far would you get the desired source code transformation based on<br>
software extensions around a search pattern like the following.<br>..........<br>
Which algorithm will become sufficient for your data processing needs<br>
around the usage of functions with variadic arguments because of format strings?<br>
<br></blockquote><div><br></div><div>Actually, I really didn&#39;t get why you&#39;re asking about that. because we are talking about X and you&#39;re asking for Y. but, either way. that is not the point. the point is because I am studying about the Coccinelle and I am just trying to figure out if the tool could detect &quot;%s&quot; called with &quot;mydata-&gt;name&quot; and then replace by &quot;%m&quot; and remove the &quot;-&gt;name&quot;</div><div><br></div><div>e.g: Once if we have:</div><div><br></div><div>int foo() {<br>  int id;<br>  struct mydata h1, *h2, s1, *s2;<br>  char *city = &quot;Hello&quot;;<br>  my_printf(&quot;%s&quot;, s2-&gt;name);<br>  my_printf(&quot;hi hi %s gggg&quot;, <a href="http://h1.name">h1.name</a>);<br>  my_printf(&quot;1234 %d <b>%s</b> @ %d <b>%s</b> | <b>%s</b> -&gt; city=%s&quot;, id, <b><a href="http://s1.name">s1.name</a></b>, 12, <b>(*h2).name</b>, <b>h2-&gt;name</b>, city);<br>  my_printf(&quot;aaaa %s hhhhh&quot;, h2-&gt;name);<br>  my_printf(&quot;%s&quot;, city);<br></div><div>}</div><div><br></div><div>Then, replace by:</div><div><br></div><div><div>int foo() {<br>  int id;<br>  struct mydata h1, *h2, s1, *s2;<br>  char *city = &quot;Hello&quot;;<br>  <b>my_printf(&quot;%m&quot;, s2);</b><br>  <b>my_printf(&quot;hi hi %s gggg&quot;, &amp;h1);</b><br>  my_printf(&quot;1234 %d <b>%m</b> @ %d <b>%m</b> | <b>%m</b> -&gt; city=%s&quot;, id, <b><a href="http://s1.name">s1.name</a></b>, 12, <b>(*h2).name</b>, <b>h2-&gt;name</b>, city);<br><b>  my_printf(&quot;aaaa %s hhhhh&quot;, h2);</b><br>  my_printf(&quot;%s&quot;, city);<br></div><div>}</div></div><div><br></div><div>But, I&#39;ve read again the other samples and the documentation. therefore, I didn&#39;t figure out how it should be. btw, thank you Julia for the suggestion performing the <i>Ocalm/make_expr/replace</i>. (Due to something wrong with the Coccinelle distributed by Brew/Osx. I just rewrote your sample using Python and the result was the same. But, I can&#39;t just replace all &quot;%s&quot; by &quot;%m&quot;. As I said, it should be only if the &quot;%s&quot; was declared to use &quot;mydata-&gt;name&quot;.</div><div><br></div><div>so, I still fighting yet. thanks in Advance.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Regards,<br>
Markus<br>
</blockquote></div></div>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

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

  reply index

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28  2:11 [Cocci] Replacing printf/format calls based on the data-type Strace Labs
2019-11-28  7:07 ` Julia Lawall
2019-11-28 17:45   ` Strace Labs
2019-11-29 14:48   ` [Cocci] Replacing printf() parameters according to used data types Markus Elfring
2019-11-28  7:50 ` Markus Elfring
2019-11-29  0:35   ` Jorge Pereira
2019-11-29  8:29     ` Markus Elfring
2019-11-29 10:57       ` Strace Labs
2019-11-29 12:33         ` Markus Elfring
2019-11-29 14:47           ` Strace Labs
2019-11-29 16:08             ` Markus Elfring
2019-11-29 17:19               ` Strace Labs
2019-11-29 17:45                 ` Markus Elfring
2019-11-29 20:55             ` Julia Lawall
2019-11-30  2:25               ` Strace Labs
2019-11-30  6:35                 ` Julia Lawall
2019-11-30  8:46                 ` Markus Elfring
2019-12-01  8:00                 ` [Cocci] Changing format string usage with SmPL? Markus Elfring
2019-12-03  3:30                   ` Strace Labs [this message]
2019-12-03  5:18                     ` Julia Lawall
2019-12-03 13:28                       ` Markus Elfring
2019-12-03 15:43                       ` [Cocci] Generation of expression lists by SmPL script rules? Markus Elfring
2019-12-03 17:28                       ` [Cocci] Changing format string usage with SmPL? Strace Labs
2019-12-04  0:21                         ` Strace Labs
2019-12-06 19:36                           ` Markus Elfring
2019-12-07  7:49                           ` Markus Elfring
2019-12-04  6:47                         ` Julia Lawall
2019-12-06 19:44                           ` Markus Elfring
2019-12-06 19:20                         ` Markus Elfring
2019-12-03 10:01                     ` Markus Elfring
2019-11-30 15:11               ` [Cocci] Replacing printf() parameters according to used data types Markus Elfring

Reply instructions:

You may reply publically 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='CABvP5W3E3zP28kUsmrvUOqv-Tu1YT3zvi6c=mqx+ahbMTycqAQ@mail.gmail.com' \
    --to=stracelabs@gmail.com \
    --cc=Markus.Elfring@web.de \
    --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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git