cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Replacing printf/format calls based on the data-type
@ 2019-11-28  2:11 Strace Labs
  2019-11-28  7:07 ` Julia Lawall
  2019-11-28  7:50 ` Markus Elfring
  0 siblings, 2 replies; 31+ messages in thread
From: Strace Labs @ 2019-11-28  2:11 UTC (permalink / raw)
  To: cocci


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

Hi,

I am working on a semantic patch for replacing specific format string token
based on the used data-type.
so, I have several calls of my_printf() and some special macros pointing to
them around my code.

e.g: part of my code.
.....
struct mydata *m;
struct mydata h;
.....
my_printf("%s", m->name);
.....
my_printf("%s", h.name);
.....
my_printf("whatever id %d following the string %s\n", id, m->name);
....
Macro_to_my_printf("Hey id %d, let's see %s\n", id, h.name);
.....
Macro2_to_my_printf(fd, "Hey id %d, let's see %s\n", id, m->name);
.....

My current humble *.cocci

$ cat fix-my_printf.cocci
@r1_heap@
struct mydata *SMD;
format F =~ "s";
@@
-my_printf("%@F@", SMD->name);
+my_printf("%m", SMD);

@r1_stack@
struct mydata SMD;
format F =~ "s";
@@
-my_printf("%@F@", SMD.name);
+my_printf("%m", &SMD);
$

But, I can match only with partial content as can be seen below.

$ spatch --partial-match --sp-file fix-my_printf.cocci
sample-format-string.c | egrep "^(\+|-)"
HANDLING: sample-format-string.c
diff =
HANDLING: /Volumes/Users/jpereira/Devel/Sandbox/sample-format-string.c
diff =
--- /Volumes/Users/jpereira/Devel/Sandbox/sample-format-string.c
+++
/var/folders/ld/6tg9c6qj4fx4c85q26mcqrsh0000gn/T/cocci-output-24659-130f86-sample-format-string.c
- my_printf("%s", m->name);
+ my_printf("%m", m);
- my_printf("%s", h.name);
+ my_printf("%m", &h);
$

Anyone could give me a light about how to proceed to match the entire
".....string format..." ?

Thanks in advance,

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

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

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

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

* Re: [Cocci] Replacing printf/format calls based on the data-type
  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
  1 sibling, 2 replies; 31+ messages in thread
From: Julia Lawall @ 2019-11-28  7:07 UTC (permalink / raw)
  To: Strace Labs; +Cc: cocci

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



--- Please note the new email address ---


On Thu, 28 Nov 2019, Strace Labs wrote:

> Hi,
> I am working on a semantic patch for replacing specific format string token based on the used data-type.
> so, I have several calls of my_printf() and some special macros pointing to them around my code.
>
> e.g: part of my code.
> .....
> struct mydata *m;
> struct mydata h;
> .....
> my_printf("%s", m->name);
> .....
> my_printf("%s", h.name);
> .....
> my_printf("whatever id %d following the string %s\n", id, m->name);
> ....
> Macro_to_my_printf("Hey id %d, let's see %s\n", id, h.name);
> .....
> Macro2_to_my_printf(fd, "Hey id %d, let's see %s\n", id, m->name);
> .....
>
> My current humble *.cocci
>
> $ cat fix-my_printf.cocci
> @r1_heap@
> struct mydata *SMD;
> format F =~ "s";
> @@
> -my_printf("%@F@", SMD->name);
> +my_printf("%m", SMD);
>
> @r1_stack@
> struct mydata SMD;
> format F =~ "s";
> @@
> -my_printf("%@F@", SMD.name);
> +my_printf("%m", &SMD);
> $
>
> But, I can match only with partial content as can be seen below.
>
> $ spatch --partial-match --sp-file fix-my_printf.cocci sample-format-string.c | egrep "^(\+|-)"
> HANDLING: sample-format-string.c
> diff =
> HANDLING: /Volumes/Users/jpereira/Devel/Sandbox/sample-format-string.c
> diff =
> --- /Volumes/Users/jpereira/Devel/Sandbox/sample-format-string.c
> +++ /var/folders/ld/6tg9c6qj4fx4c85q26mcqrsh0000gn/T/cocci-output-24659-130f86-sample-format-string.c
> - my_printf("%s", m->name);
> + my_printf("%m", m);
> - my_printf("%s", h.name);
> + my_printf("%m", &h);
> $
>
> Anyone could give me a light about how to proceed to match the entire ".....string format..." ?

I think that what you are asking is why you can't write a pattern like:

foo("...
-%@d@
+%x
  ...")

At the moment, there seems to be a bug.  I will check on that.

julia

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  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  7:50 ` Markus Elfring
  2019-11-29  0:35   ` Jorge Pereira
  1 sibling, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-11-28  7:50 UTC (permalink / raw)
  To: stracelabs; +Cc: cocci

> @r1_stack@
> struct mydata SMD;
> format F =~ "s";
> @@
> -my_printf("%@F@", SMD.name);
> +my_printf("%m", &SMD);
> $
>
> But, I can match only with partial content as can be seen below.

I find this information for “partial content” unclear at the moment.

* Would you like to transform any more source code variants by using
  additional SmPL ellipses and disjunctions?

* How do you think about to extend and improve the shown change specifications?

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

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

* Re: [Cocci] Replacing printf/format calls based on the data-type
  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
  1 sibling, 0 replies; 31+ messages in thread
From: Strace Labs @ 2019-11-28 17:45 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci


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

Hi Julia,

I am not sure if I was clear. but, let me try to explain again.

1. I have the code.

$ cat sample.c
int foo() {
int id;
struct mydata h1, *h2, s1, *s2;

// works fine
  my_printf("%s", h1.name);
  my_printf("%s", h2->name);

// don't work
my_printf("%d it would work but dunno mydata=%m\n", id, h2);
my_printf("%d here also, tt=%s and %m\n", id, h2->name, s2);
}
$

2. My fix-format.cocci

$ cat fix-format.cocci
@r1_heap@
struct mydata *SMD;
format F =~ "s";
expression f;
@@
-f("%@F@", SMD->name);
+f("%m", SMD);

@r1_stack@
struct mydata SMD;
format F =~ "s";
expression f;
@@
-f("%@F@", SMD.name);
+f("%m", &SMD);

$

3. therefore, It is not matching with *my_printf("%d it would work but
dunno mydata=%m\n", id, h2);*

e.g:

$ spatch --sp-file fix-format.cocci sample.c
HANDLING: /tmp/sample.c
diff =
--- /tmp/sample.c
+++ /tmp/T/cocci-output-92962-556a08-sample.c
@@ -4,8 +4,8 @@ int foo() {
  struct mydata h1, *h2, s1, *s2;

  // works fine
- my_printf("%s", h1.name);
- my_printf("%s", h2->name);
+ my_printf("%m", &h1);
+ my_printf("%m", h2);

  // don't work
  my_printf("%d it would work but dunno mydata=%m\n", id, h2);
$

so, is it possible to fix my format-string?

On Thu, Nov 28, 2019 at 5:08 AM Julia Lawall <julia.lawall@inria.fr> wrote:

>
>
> --- Please note the new email address ---
>
>
> On Thu, 28 Nov 2019, Strace Labs wrote:
>
> > Hi,
> > I am working on a semantic patch for replacing specific format string
> token based on the used data-type.
> > so, I have several calls of my_printf() and some special macros pointing
> to them around my code.
> >
> > e.g: part of my code.
> > .....
> > struct mydata *m;
> > struct mydata h;
> > .....
> > my_printf("%s", m->name);
> > .....
> > my_printf("%s", h.name);
> > .....
> > my_printf("whatever id %d following the string %s\n", id, m->name);
> > ....
> > Macro_to_my_printf("Hey id %d, let's see %s\n", id, h.name);
> > .....
> > Macro2_to_my_printf(fd, "Hey id %d, let's see %s\n", id, m->name);
> > .....
> >
> > My current humble *.cocci
> >
> > $ cat fix-my_printf.cocci
> > @r1_heap@
> > struct mydata *SMD;
> > format F =~ "s";
> > @@
> > -my_printf("%@F@", SMD->name);
> > +my_printf("%m", SMD);
> >
> > @r1_stack@
> > struct mydata SMD;
> > format F =~ "s";
> > @@
> > -my_printf("%@F@", SMD.name);
> > +my_printf("%m", &SMD);
> > $
> >
> > But, I can match only with partial content as can be seen below.
> >
> > $ spatch --partial-match --sp-file fix-my_printf.cocci
> sample-format-string.c | egrep "^(\+|-)"
> > HANDLING: sample-format-string.c
> > diff =
> > HANDLING: /Volumes/Users/jpereira/Devel/Sandbox/sample-format-string.c
> > diff =
> > --- /Volumes/Users/jpereira/Devel/Sandbox/sample-format-string.c
> > +++
> /var/folders/ld/6tg9c6qj4fx4c85q26mcqrsh0000gn/T/cocci-output-24659-130f86-sample-format-string.c
> > - my_printf("%s", m->name);
> > + my_printf("%m", m);
> > - my_printf("%s", h.name);
> > + my_printf("%m", &h);
> > $
> >
> > Anyone could give me a light about how to proceed to match the entire
> ".....string format..." ?
>
> I think that what you are asking is why you can't write a pattern like:
>
> foo("...
> -%@d@
> +%x
>   ...")
>
> At the moment, there seems to be a bug.  I will check on that.
>
> julia

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

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-28  7:50 ` Markus Elfring
@ 2019-11-29  0:35   ` Jorge Pereira
  2019-11-29  8:29     ` Markus Elfring
  0 siblings, 1 reply; 31+ messages in thread
From: Jorge Pereira @ 2019-11-29  0:35 UTC (permalink / raw)
  To: stracelabs, Markus Elfring; +Cc: cocci


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

For now, I just would like to detect and patch the mentioned example. I could imagine that could be possible do using Python,.

Get Outlook for Android<https://aka.ms/ghei36>

________________________________
From: Markus Elfring <Markus.Elfring@web.de>
Sent: Thursday, November 28, 2019 4:50:55 AM
To: stracelabs@gmail.com <stracelabs@gmail.com>
Cc: cocci@systeme.lip6.fr <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] Replacing printf() parameters according to used data types

> @r1_stack@
> struct mydata SMD;
> format F =~ "s";
> @@
> -my_printf("%@F@", SMD.name);
> +my_printf("%m", &SMD);
> $
>
> But, I can match only with partial content as can be seen below.

I find this information for “partial content” unclear at the moment.

* Would you like to transform any more source code variants by using
  additional SmPL ellipses and disjunctions?

* How do you think about to extend and improve the shown change specifications?

Regards,
Markus

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

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29  0:35   ` Jorge Pereira
@ 2019-11-29  8:29     ` Markus Elfring
  2019-11-29 10:57       ` Strace Labs
  0 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-11-29  8:29 UTC (permalink / raw)
  To: Jorge Pereira; +Cc: cocci

> For now, I just would like to detect and patch the mentioned example.

Did you try out to work with SmPL ellipses and disjunctions for this purpose?


> I could imagine that could be possible do using Python,.

The application of the semantic patch language (Coccinelle software) should be safer here,
shouldn't it?

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29  8:29     ` Markus Elfring
@ 2019-11-29 10:57       ` Strace Labs
  2019-11-29 12:33         ` Markus Elfring
  0 siblings, 1 reply; 31+ messages in thread
From: Strace Labs @ 2019-11-29 10:57 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci


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

>. Did you try out to work with SmPL ellipses and disjunctions for this
purpose?

I didn't it, do you have any suggestions or sample that is it possible to
solve my problem? something to based on.

 >> II could imagine that could be possible do using Python,.

> The application of the semantic patch language (Coccinelle software)
should be safer here, shouldn't it?

I mean, the Coccinelle/Python support.


-- 
Sent from my iPowerBall®

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

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 10:57       ` Strace Labs
@ 2019-11-29 12:33         ` Markus Elfring
  2019-11-29 14:47           ` Strace Labs
  0 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-11-29 12:33 UTC (permalink / raw)
  To: stracelabs; +Cc: Jorge Pereira, cocci

>>. Did you try out to work with SmPL ellipses and disjunctions for this purpose? 
>  
> I didn't it, do you have any suggestions or sample that is it possible
> to solve my problem? something to based on.

Can you get further development ideas from a transformation approach
like the following?

@replacement@
struct mydata SMD;
struct mydata* SMDP;
format F =~ "s";
@@
 my_printf(
-          "%@F@"
+          "%m"
           ,
(
+           &
             SMD
-               .name
|
            SMDP
-               ->name
)
          );



> I mean, the Coccinelle/Python support.

This programming interface contains also open issues for further considerations
as you can see from a topic like “Propagating values back from Python script
to SmPL rule with other metavariable type than “identifier””.
https://github.com/coccinelle/coccinelle/issues/86

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 12:33         ` Markus Elfring
@ 2019-11-29 14:47           ` Strace Labs
  2019-11-29 16:08             ` Markus Elfring
  2019-11-29 20:55             ` Julia Lawall
  0 siblings, 2 replies; 31+ messages in thread
From: Strace Labs @ 2019-11-29 14:47 UTC (permalink / raw)
  To: Markus Elfring, Julia Lawall; +Cc: cocci


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

Markus,

so, that suggestion works the same as my previous shared statement. but,
only for calls like: *my_printf("%s", h1.name <http://h1.name>);*,
not for *my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name,
h2->name, s2);*

e.g:

Code sample

int foo() {
int id;
struct mydata h1, *h2, s1, *s2;

// works fine
my_printf("%s", h1.name);
my_printf("%s", h2->name);
my_printf("%s");

// don't match.
my_printf("%s %d", h2->name, id);
my_printf("%s %s", h2->name, h2->name);
my_printf("%d it would work but dunno mydata=%m\n", id, h2);
my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name, h2->name, s2);
}

so, I am not sure if Coccinelle is able to do that. I've read all samples
available in the Kernel and Coccinelle repo's and I didn't see any similar
case.

I think that if @Julia Lawall <julia.lawall@inria.fr> don't know, No one in
the world knows. 😂



On Fri, Nov 29, 2019 at 10:33 AM Markus Elfring <Markus.Elfring@web.de>
wrote:

> >>. Did you try out to work with SmPL ellipses and disjunctions for this
> purpose?
> >
> > I didn't it, do you have any suggestions or sample that is it possible
> > to solve my problem? something to based on.
>
> Can you get further development ideas from a transformation approach
> like the following?
>
> @replacement@
> struct mydata SMD;
> struct mydata* SMDP;
> format F =~ "s";
> @@
>  my_printf(
> -          "%@F@"
> +          "%m"
>            ,
> (
> +           &
>              SMD
> -               .name
> |
>             SMDP
> -               ->name
> )
>           );
>
>
>
> > I mean, the Coccinelle/Python support.
>
> This programming interface contains also open issues for further
> considerations
> as you can see from a topic like “Propagating values back from Python
> script
> to SmPL rule with other metavariable type than “identifier””.
> https://github.com/coccinelle/coccinelle/issues/86
>
> Regards,
> Markus
>

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

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-28  7:07 ` Julia Lawall
  2019-11-28 17:45   ` Strace Labs
@ 2019-11-29 14:48   ` Markus Elfring
  1 sibling, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-11-29 14:48 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

> At the moment, there seems to be a bug.  I will check on that.

I am also curious how the support will evolve further around
advanced data processing for format strings with the semantic
patch language.

Can another transformation approach become interesting for
a corresponding clarification?

@replacement@
struct mydata SMD;
format F =~ "s";
@@
 my_printf("%
-           @F@
+           m
           ",
+          &
           SMD
-             .name
          );

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci Strace_Labs2.cocci
…
warning: replacement: metavariable F not used in the - or context code
warning: iso fld_to_ptr does not match the code below on line 10
…

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 14:47           ` Strace Labs
@ 2019-11-29 16:08             ` Markus Elfring
  2019-11-29 17:19               ` Strace Labs
  2019-11-29 20:55             ` Julia Lawall
  1 sibling, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-11-29 16:08 UTC (permalink / raw)
  To: stracelabs, Julia Lawall; +Cc: cocci

> so, that suggestion works the same as my previous shared statement.

I suggest to take another look at presented implementation details.


> but, only for calls like: *my_printf("%s", h1.name);*,

I limited my suggestion intentionally.


> not for *my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name, h2->name, s2);*

Such a function call is using more parameters. Would you get into
the mood then to specify additional metavariables in SmPL script variants?


> so, I am not sure if Coccinelle is able to do that.

I hope that more useful data processing for format strings will become
supported by the semantic patch language.
Yesterday an information was given that another functionality is also
work in progress.


> I've read all samples available in the Kernel and Coccinelle repo's

I find such information interesting and promising.


> and I didn't see any similar case.

This observation can be fine.
How often do you fiddle with source code transformations around
format strings?


> I think that if Julia Lawall don't know, No one in the world knows.

Such an impression can occur. - But I would like to point further
possibilities out for desired knowledge distribution.

* Would you like to contact any more related developers?

* How do you think about to improve your own expertise
  (around the discussed free software) in any ways?

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 16:08             ` Markus Elfring
@ 2019-11-29 17:19               ` Strace Labs
  2019-11-29 17:45                 ` Markus Elfring
  0 siblings, 1 reply; 31+ messages in thread
From: Strace Labs @ 2019-11-29 17:19 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci


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

On Fri, Nov 29, 2019 at 2:09 PM Markus Elfring <Markus.Elfring@web.de>
wrote:

> > so, that suggestion works the same as my previous shared statement.
>
> I suggest to take another look at presented implementation details.
>
>
I did it, even digging the grammar and ALL samples and didn't find anything
similar to handle format strings with multiple parameters as mentioned.


>
> > but, only for calls like: *my_printf("%s", h1.name);*,
>
> I limited my suggestion intentionally.
>
>
> > not for *my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name,
> h2->name, s2);*
>
> Such a function call is using more parameters. Would you get into
> the mood then to specify additional metavariables in SmPL script variants?
>
>

I can't because the calls around the code have different uses with
different variants.



> > so, I am not sure if Coccinelle is able to do that.
>
> I hope that more useful data processing for format strings will become
> supported by the semantic patch language.
> Yesterday an information was given that another functionality is also
> work in progress.
>



Interesting.



>
> > I've read all samples available in the Kernel and Coccinelle repo's
>
> I find such information interesting and promising.
>
>
> > and I didn't see any similar case.
>
> This observation can be fine.
> How often do you fiddle with source code transformations around
> format strings?
>
>


Well, I've used it before but for me, it is the first "complex" case that I
am working on. even I still digging trying to figure out how to do that but
I still not sure if the Coccelinne is capable to do that yes or no.




>
> > I think that if Julia Lawall don't know, No one in the world knows.
>
> Such an impression can occur. - But I would like to point further
> possibilities out for desired knowledge distribution.
>
> * Would you like to contact any more related developers?

* How do you think about to improve your own expertise
>   (around the discussed free software) in any ways?
>
> Regards,
> Markus
>

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

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 17:19               ` Strace Labs
@ 2019-11-29 17:45                 ` Markus Elfring
  0 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-11-29 17:45 UTC (permalink / raw)
  To: stracelabs; +Cc: cocci

>     I suggest to take another look at presented implementation details.
>
> I did it,

Such a try is generally nice.


> even digging the grammar and ALL samples and didn't find anything similar
> to handle format strings with multiple parameters as mentioned.

Can this view trigger opportunities to improve corresponding clarification attempts?


>     > not for *my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name, h2->name, s2);*
>
>     Such a function call is using more parameters. Would you get into
>     the mood then to specify additional metavariables in SmPL script variants?
>
> I can't because the calls around the code have different uses with different variants. 

I suggest to reconsider your conclusion.
How will corresponding software development experiments evolve?


>     How often do you fiddle with source code transformations around
>     format strings?
>
> Well, I've used it before but for me, it is the first "complex" case
> that I am working on.

I hope that such information can help also in our communication.
Are you looking for further help according to an usual learning experience?


> even I still digging trying to figure out how to do that

Do you find the available software documentation helpful?
https://github.com/coccinelle/coccinelle/blob/ed1eb8e06f800739d3992158d36945c0c4c6f0c7/docs/manual/cocci_syntax.tex#L337


> but I still not sure if the Coccelinne is capable to do that yes or no.

How would you like to reduce involved uncertainty?

Which level of understanding did you achieve for the following functionality
so far?
* SmPL ellipsis
* SmPL disjunction

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 14:47           ` Strace Labs
  2019-11-29 16:08             ` Markus Elfring
@ 2019-11-29 20:55             ` Julia Lawall
  2019-11-30  2:25               ` Strace Labs
  2019-11-30 15:11               ` [Cocci] Replacing printf() parameters according to used data types Markus Elfring
  1 sibling, 2 replies; 31+ messages in thread
From: Julia Lawall @ 2019-11-29 20:55 UTC (permalink / raw)
  To: Strace Labs; +Cc: Markus Elfring, cocci

Maybe this will help you:

@r@
format list d;
@@

"%@d@"

@script:ocaml s@
d << r.d;
res;
@@
res := make_expr ("\""^(String.concat "%s" (Str.split_delim
(Str.regexp_string "%d") d))^"\"")


@@
format list r.d;
expression s.res;
@@

-"%@d@"
+res

---------------

Example:

int main() {
  printf("some %d more\n", 12);
}

int main() {
  printf("%d more\n", 12);
}

int main() {
  printf("more %d\n", 12);
}

int main() {
  printf("%d more %d\n", 12);
}

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 20:55             ` Julia Lawall
@ 2019-11-30  2:25               ` Strace Labs
  2019-11-30  6:35                 ` Julia Lawall
                                   ` (2 more replies)
  2019-11-30 15:11               ` [Cocci] Replacing printf() parameters according to used data types Markus Elfring
  1 sibling, 3 replies; 31+ messages in thread
From: Strace Labs @ 2019-11-30  2:25 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Markus Elfring, cocci


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

Hi Julia,

Thanks for the suggestion. But, It is working partially... I am not sure if
Coccinelle is able to filter the %fmt e.g: %s only called with a parameter
of specific data-type. In my case, *{struct mydata }.name* and *{ struct
mydata *}->name*.

##### * Cocci*
@r1@
format list d;
identifier fn;
@@

fn("%@d@", ...)

@script:ocaml s1@
d << r1.d;
res;
@@
res := make_expr ("\""^(String.concat "%m"
(Str.split_delim(Str.regexp_string "%s") d))^"\"")

@main depends on s1 && r1@
format list r1.d;
expression s1.res;
identifier r1.fn;
struct mydata SMD;
struct mydata* SMDP;
@@

 fn(
-"%@d@"
+res
,
(
+ &
  SMD
- .name
|
  SMDP
- ->name
)
 );

*#####  .c Code sample*
int foo() {
int id;
struct mydata h1, *h2, s1, *s2;
char *city;

// works fine
my_printf("%s", s2->name);

// works without any criterions about the data type of %fmt
my_printf("sss %s gggg", h1.name);
my_printf("33131231313 %d %s %d %s hhhhh", id, s1.name, (*h2)->name,
h2->name);
my_printf("aaaa %s hhhhh", h2->name);
my_printf("%s", s2->name);

// should do nothing
my_printf("%s");
my_printf("%s", city);

// don't match.
my_printf("a %s %d", h2->name, id);
my_printf("ddddd %s %s %s", h2->name, city, h2->name);
my_printf("%d it would work but dunno mydata=%m\n", id, h2);
my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name, h2->name, s2);
}

*#### Result*
HANDLING: /Volumes/Users/test/Coccinella/sample.c
diff =
--- /Volumes/Users/test/Coccinella/sample.c
+++ /tmp/cocci-output-99329-3a9829-sample.c
@@ -5,13 +5,13 @@ int foo() {
  char *city;

  // works fine
- my_printf("%s", s2->name);
+ my_printf("%m", s2);

  // works without any criterious about the data type of %fmt
- my_printf("sss %s gggg", h1.name);
+ my_printf("sss %m gggg", &h1);
  my_printf("33131231313 %d %s %d %s hhhhh", id, s1.name, (*h2)->name,
h2->name);
- my_printf("aaaa %s hhhhh", h2->name);
- my_printf("%s", s2->name);
+ my_printf("aaaa %m hhhhh", h2);
+ my_printf("%m", s2);

  // should do nothing
  my_printf("%s");


Basically, I intend to replace alls "%s" called with "mydata->name" by "%m"
with "mydata" or "&mydata"





On Fri, Nov 29, 2019 at 6:55 PM Julia Lawall <julia.lawall@inria.fr> wrote:

> Maybe this will help you:
>
> @r@
> format list d;
> @@
>
> "%@d@"
>
> @script:ocaml s@
> d << r.d;
> res;
> @@
> res := make_expr ("\""^(String.concat "%s" (Str.split_delim
> (Str.regexp_string "%d") d))^"\"")
>
>
> @@
> format list r.d;
> expression s.res;
> @@
>
> -"%@d@"
> +res
>
> ---------------
>
> Example:
>
> int main() {
>   printf("some %d more\n", 12);
> }
>
> int main() {
>   printf("%d more\n", 12);
> }
>
> int main() {
>   printf("more %d\n", 12);
> }
>
> int main() {
>   printf("%d more %d\n", 12);
> }
>
> julia
>

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

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  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
  2 siblings, 0 replies; 31+ messages in thread
From: Julia Lawall @ 2019-11-30  6:35 UTC (permalink / raw)
  To: Strace Labs; +Cc: cocci

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



--- Please note the new email address ---


On Sat, 30 Nov 2019, Strace Labs wrote:

> Hi Julia,
>
> Thanks for the suggestion. But, It is working partially... I am not sure if
> Coccinelle is able to filter the %fmt e.g: %s only called with a parameter
> of specific data-type. In my case, {struct mydata }.name and { struct mydata
> *}->name.
>
> #####  Cocci
> @r1@
> format list d;
> identifier fn;
> @@
>
> fn("%@d@", ...)

There is no need to put ... here if you want to specify something else.

julia

> @script:ocaml s1@
> d << r1.d;
> res;
> @@
> res := make_expr ("\""^(String.concat "%m"
> (Str.split_delim(Str.regexp_string "%s") d))^"\"")
>
> @main depends on s1 && r1@
> format list r1.d;
> expression s1.res;
> identifier r1.fn;
> struct mydata SMD;
> struct mydata* SMDP;
> @@
>
>  fn(
> -"%@d@"
> +res
> ,
> (
> + &
>   SMD
> - .name
> |
>   SMDP
> - ->name
> )
>  );
>  
> #####  .c Code sample
> int foo() {
> int id;
> struct mydata h1, *h2, s1, *s2;
> char *city;
>
> // works fine
> my_printf("%s", s2->name);
>
> // works without any criterions about the data type of %fmt
> my_printf("sss %s gggg", h1.name);
> my_printf("33131231313 %d %s %d %s hhhhh", id, s1.name, (*h2)->name,
> h2->name);
> my_printf("aaaa %s hhhhh", h2->name);
> my_printf("%s", s2->name);
>
> // should do nothing
> my_printf("%s");
> my_printf("%s", city);
>
> // don't match.
> my_printf("a %s %d", h2->name, id);
> my_printf("ddddd %s %s %s", h2->name, city, h2->name);
> my_printf("%d it would work but dunno mydata=%m\n", id, h2);
> my_printf("%d here also, tt=%s | %s and %m\n", id, h2->name, h2->name, s2);
> }
>
> #### Result
> HANDLING: /Volumes/Users/test/Coccinella/sample.c
> diff =
> --- /Volumes/Users/test/Coccinella/sample.c
> +++ /tmp/cocci-output-99329-3a9829-sample.c
> @@ -5,13 +5,13 @@ int foo() {
>   char *city;
>
>   // works fine
> - my_printf("%s", s2->name);
> + my_printf("%m", s2);
>
>   // works without any criterious about the data type of %fmt
> - my_printf("sss %s gggg", h1.name);
> + my_printf("sss %m gggg", &h1);
>   my_printf("33131231313 %d %s %d %s hhhhh", id, s1.name, (*h2)->name,
> h2->name);
> - my_printf("aaaa %s hhhhh", h2->name);
> - my_printf("%s", s2->name);
> + my_printf("aaaa %m hhhhh", h2);
> + my_printf("%m", s2);
>
>   // should do nothing
>   my_printf("%s");
>
>
> Basically, I intend to replace alls "%s" called with "mydata->name" by "%m"
> with "mydata" or "&mydata"
>
>
>
>
>
> On Fri, Nov 29, 2019 at 6:55 PM Julia Lawall <julia.lawall@inria.fr> wrote:
>       Maybe this will help you:
>
>       @r@
>       format list d;
>       @@
>
>       "%@d@"
>
>       @script:ocaml s@
>       d << r.d;
>       res;
>       @@
>       res := make_expr ("\""^(String.concat "%s" (Str.split_delim
>       (Str.regexp_string "%d") d))^"\"")
>
>
>       @@
>       format list r.d;
>       expression s.res;
>       @@
>
>       -"%@d@"
>       +res
>
>       ---------------
>
>       Example:
>
>       int main() {
>         printf("some %d more\n", 12);
>       }
>
>       int main() {
>         printf("%d more\n", 12);
>       }
>
>       int main() {
>         printf("more %d\n", 12);
>       }
>
>       int main() {
>         printf("%d more %d\n", 12);
>       }
>
>       julia
>
>
>

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

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  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
  2 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-11-30  8:46 UTC (permalink / raw)
  To: stracelabs, Julia Lawall; +Cc: cocci

> I am not sure if Coccinelle is able to filter the %fmt e.g: %s only called with
> a parameter of specific data-type.

I would expect general support for such a task by the semantic patch language.


> Basically, I intend to replace alls "%s" called with "mydata->name" by "%m" with "mydata" or "&mydata"

I find that this is a succinct description for your source code transformation goal.


The usage of the other SmPL code seems to indicate that your understanding
grew for the application of previously mentioned syntax elements in significant ways.
We will probably be more curious then how the data processing for SmPL ellipses
(triple dots) within format strings can become better together with a different
selection of metavariables for possible SmPL disjunctions.

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

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

* Re: [Cocci] Replacing printf() parameters according to used data types
  2019-11-29 20:55             ` Julia Lawall
  2019-11-30  2:25               ` Strace Labs
@ 2019-11-30 15:11               ` Markus Elfring
  1 sibling, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-11-30 15:11 UTC (permalink / raw)
  To: Julia Lawall, stracelabs; +Cc: cocci

> Maybe this will help you:
>
> @r@
> format list d;
> @@
>
> "%@d@"
>
> @script:ocaml s@
> d << r.d;
> res;
> @@
> res := make_expr ("\""^(String.concat "%s" (Str.split_delim
> (Str.regexp_string "%d") d))^"\"")

Such a replacement approach might look promising.
But I got the impression that another aspect can be more important
for the safe data processing of format strings.
The passed function parameters should fit to the specified
data conversions in the string.

Can the Coccinelle software help any more to group or mark
update candidates from the expression list in appropriate ways?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  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                 ` Markus Elfring
  2019-12-03  3:30                   ` Strace Labs
  2 siblings, 1 reply; 31+ messages in thread
From: Markus Elfring @ 2019-12-01  8:00 UTC (permalink / raw)
  To: stracelabs, Julia Lawall; +Cc: cocci

> 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?

@find@
expression action;
expression list context, inputs;
format list fl;
@@
 action(context, "%@fl@", inputs)


Which algorithm will become sufficient for your data processing needs
around the usage of functions with variadic arguments because of format strings?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-01  8:00                 ` [Cocci] Changing format string usage with SmPL? Markus Elfring
@ 2019-12-03  3:30                   ` Strace Labs
  2019-12-03  5:18                     ` Julia Lawall
  2019-12-03 10:01                     ` Markus Elfring
  0 siblings, 2 replies; 31+ messages in thread
From: Strace Labs @ 2019-12-03  3:30 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci


[-- 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 --]

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

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-03  3:30                   ` Strace Labs
@ 2019-12-03  5:18                     ` Julia Lawall
  2019-12-03 13:28                       ` Markus Elfring
                                         ` (2 more replies)
  2019-12-03 10:01                     ` Markus Elfring
  1 sibling, 3 replies; 31+ messages in thread
From: Julia Lawall @ 2019-12-03  5:18 UTC (permalink / raw)
  To: Strace Labs; +Cc: Markus Elfring, cocci


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

> De: "Strace Labs" <stracelabs@gmail.com>
> À: "Markus Elfring" <Markus.Elfring@web.de>
> Cc: "Julia Lawall" <julia.lawall@inria.fr>, cocci@systeme.lip6.fr
> Envoyé: Mardi 3 Décembre 2019 11:30:14
> Objet: Re: [Cocci] Changing format string usage with SmPL?

> On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring < [ mailto:Markus.Elfring@web.de |
> 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", [ http://h1.name/ | h1.name ] );
> my_printf("1234 %d %s @ %d %s | %s -> city=%s", id, [ http://s1.name/ | 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, [ http://s1.name/ | 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.

OK, if you may have more than one argument to your print, then you can find the offset using an expression list metavariable: 

@r@ 
expression list[n] between; 
@@ 

print(s,between,h2->name,...) 

Then you can use r.n in your python rule to figure out where is the %s to change. Unfortunately, this will not work well if there are multiple name references in the argument list. Because you will be trying to change the format string in multiple ways, eg once where between has length 2 and once where between has length 4. Substantial hacks would be required to deal with this. 

It would be nice if you could do 

@r@ 
expression list[bn] between; 
expression list[an] after; 
position p; 
@@ 
print@p(s,between,name,after) 

@@ 
format list[r.bn] f1; 
format list[r.an] f2; 
position r.p; 
@@ 
print@p( 
- "%@f1@%s%@f2@" 
+ "%@f1@%m%@f2@" 
, l) 

I don't know if that would work, though. 

julia 

>> Regards,
>> Markus

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

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

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-03  3:30                   ` Strace Labs
  2019-12-03  5:18                     ` Julia Lawall
@ 2019-12-03 10:01                     ` Markus Elfring
  1 sibling, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-03 10:01 UTC (permalink / raw)
  To: stracelabs, Julia Lawall; +Cc: cocci

> > 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.

I suggest to take another look at affected software aspects.


> because we are talking about X and you're asking for Y.

I presented another approach to tackle your use case.


> the point is because I am studying about the Coccinelle

This is nice.


> 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"

It can be achieved for such format string parameters.
But I hope that the software development attention will grow
for the handling of multiple data conversions for several arguments.


> But, I've read again the other samples and the documentation.
> therefore, I didn't figure out how it should be.

Would you like to help to improve this area also for your needs?


> 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.

Both programming languages can perform string replacements as usual.


> But, I can't just replace all "%s" by "%m".

Will you become aware of more temporary software limitations
because mentioned implementation details can refer also to work in progress?


> As I said, it should be only if the "%s" was declared to use "mydata->name".

Such a requirement seems to be clear.


> so, I still fighting yet.

Can it be that your design imaginations are too limited
for the discussed use case so far?

How do you think about to develop a few corresponding SmPL script variants
which can handle more concrete function calls besides searching for a solution
according to the desired general source code transformation?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  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
  2 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-03 13:28 UTC (permalink / raw)
  To: Julia Lawall, stracelabs; +Cc: cocci

> OK, if you may have more than one argument to your print,
> then you can find the offset using an expression list metavariable:
>
> @r@
> expression list[n] between;
> @@
>
> print(s,between,h2->name,...)
>
> Then you can use r.n in your python rule to figure out where is the %s to change.

This data processing approach sounds promising.


> Unfortunately, this will not work well if there are multiple name references in the argument list.

I hope that the Coccinelle software can help more with the analysis
for format strings.


> Because you will be trying to change the format string in multiple ways,
> eg once where between has length 2 and once where between has length 4.

This can probably happen.


> Substantial hacks would be required to deal with this.

How can corresponding collateral evolution be better supported?


> It would be nice if you could do
>
> @r@
> expression list[bn] between;
> expression list[an] after;
> position p;
> @@
> print@p(s,between,name,after)
>
> @@
> format list[r.bn] f1;
> format list[r.an] f2;
> position r.p;
> @@
> print@p(
> -    "%@f1@%s%@f2@"
> +   "%@f1@%m%@f2@"
> , l)
>
> I don't know if that would work, though.

I find this information interesting.
How will the clarification be continued for affected open issues?

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

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

* Re: [Cocci] Generation of expression lists by SmPL script rules?
  2019-12-03  5:18                     ` Julia Lawall
  2019-12-03 13:28                       ` Markus Elfring
@ 2019-12-03 15:43                       ` Markus Elfring
  2019-12-03 17:28                       ` [Cocci] Changing format string usage with SmPL? Strace Labs
  2 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-03 15:43 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

> OK, if you may have more than one argument to your print,
> then you can find the offset using an expression list metavariable:

How challenging would it be to add support for the construction
of such expression lists by programming interfaces (besides “make_expr”)
of Coccinelle's software library?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  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                       ` Strace Labs
  2019-12-04  0:21                         ` Strace Labs
                                           ` (2 more replies)
  2 siblings, 3 replies; 31+ messages in thread
From: Strace Labs @ 2019-12-03 17:28 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci


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

Unfortunately, it doesn't work. But, I am working on some solutions using
Python.

therefore, once we have something like:

...
@r1@
format list fl;
identifier fn;
expression list e;
position p;
@@

fn("%@fl@", e@p)
....

Then, I could handle the *format list* using *make_expr()* as well. But, Is
it possible to rename/handle the *expression list?*


On Tue, Dec 3, 2019 at 3:18 AM Julia Lawall <julia.lawall@inria.fr> wrote:

> ------------------------------
>
> *De: *"Strace Labs" <stracelabs@gmail.com>
> *À: *"Markus Elfring" <Markus.Elfring@web.de>
> *Cc: *"Julia Lawall" <julia.lawall@inria.fr>, cocci@systeme.lip6.fr
> *Envoyé: *Mardi 3 Décembre 2019 11:30:14
> *Objet: *Re: [Cocci] Changing format string usage with SmPL?
>
> 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.
>
> OK, if you may have more than one argument to your print, then you can
> find the offset using an expression list metavariable:
>
> @r@
> expression list[n] between;
> @@
>
> print(s,between,h2->name,...)
>
> Then you can use r.n in your python rule to figure out where is the %s to
> change.  Unfortunately, this will not work well if there are multiple name
> references in the argument list.  Because you will be trying to change the
> format string in multiple ways, eg once where between has length 2 and once
> where between has length 4.  Substantial hacks would be required to deal
> with this.
>
> It would be nice if you could do
>
> @r@
> expression list[bn] between;
> expression list[an] after;
> position p;
> @@
> print@p(s,between,name,after)
>
> @@
> format list[r.bn] f1;
> format list[r.an] f2;
> position r.p;
> @@
> print@p(
> -    "%@f1@%s%@f2@"
> +   "%@f1@%m%@f2@"
> , l)
>
> I don't know if that would work, though.
>
> julia
>
> Regards,
>> Markus
>>
>
>

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

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

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  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:20                         ` Markus Elfring
  2 siblings, 2 replies; 31+ messages in thread
From: Strace Labs @ 2019-12-04  0:21 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci


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

After some research, I could create a Python function called
fmt_replace_by_pos() to replace the %fmt by the Indice position.

*1. Input test*

int foo() {
   int id;
   struct mydata h1, *h2, s1, *s2;
   char *city = "Hello";
   my_printf("test: char*=%s mydata=%s int=%d mydata*=%s (*mydata)=%s",
city, h1.name, id, s2->name, (*h2)->name);
}

*2. My *.cocci* (~> https://pastebin.com/a6Tfav4x )

@initialize:python@
@@
import re

def fmt_parser(_st):
# a bunch of (non-% or %%), and then (% followed by non-%).
REG = re.compile('([^%]|%%)*(%[^%])')
retval = {}
pos = 0  # where to start searching for next time
i = 0
while True:
match = REG.match(_st, pos)
if match is None:
return retval
fmt = match.group(2)
pos = match.end()
idx = pos - len(fmt)
retval[i] = { 'idx': idx, 'fmt': fmt }
i += 1

def fmt_replace_by_pos(_str, _idx, _fmt):
try:
fmts  = fmt_parser(_str)
new   = _str

if _idx == -1:
_idx = [item for item in range(0, len(fmts))]

for _i in _idx:
f     = fmts[_i]
idx   = f['idx']
fmt   = f['fmt']
fmt_l = len(fmt)
new   = new[:idx] + _fmt + new[idx + fmt_l:]

return ''.join(new)
except Exception as e:
print("** ERROR: Something wrong in fmt_replace_by_pos():\n
{}\n".format(str(e)))

@r1@
format list fl;
identifier fn;
expression list e;
position p;
@@

fn("%@fl@", e@p)

@script:python s1@
fl << r1.fl;
fn << r1.fn;
e << r1.e;
p << r1.p;
new_fmt;
to_e;
@@
// Update the %fmt by the position (Position currently hardcode)
new_fmt = fmt_replace_by_pos(coccinelle.fl, { 1, 3, 4 }, "%m")
coccinelle.new_fmt = cocci.make_expr("\"{}\"".format(new_fmt))

@main depends on s1 && r1@
format list r1.fl;
expression s1.new_fmt;
identifier r1.fn;
expression list r1.e;
expression list s1.to_e;
position r1.p;
//struct mydata SMD;
//struct mydata* SMDP;
@@

 fn(
-"%@fl@"
+new_fmt
,
e@p
 );

*3. Execution*

# spatch --sp-file fix-format.cocci sample.c
init_defs_builtins:
/usr/local/Cellar/coccinelle/1.0.9/bin/../lib/coccinelle/standard.h
warning: main: inherited metavariable to_e not used in the -, +, or context
code
HANDLING: sample.c
diff =
--- sample.c
+++ /tmp/cocci-output-17883-e8cce6-sample.c
@@ -4,7 +4,8 @@ int foo() {
  struct mydata h1, *h2, s1, *s2;
  char *city = "Hello";

- my_printf("test: char*=%s mydata=%s int=%d mydata*=%s (*mydata)=%s",
city, h1.name, id, s2->name, (*h2)->name);
+ my_printf("test: char*=%s mydata=*%m* int=%d mydata*=*%m* (*mydata)=*%m*",
+  city, h1.name, id, s2->name, (*h2)->name);
 }

#

Therefore, I could find the %fmt and replace by whatever I want based on
the *expression-list. *currently struggled on that.







On Tue, Dec 3, 2019 at 3:28 PM Strace Labs <stracelabs@gmail.com> wrote:

> Unfortunately, it doesn't work. But, I am working on some solutions using
> Python.
>
> therefore, once we have something like:
>
> ...
> @r1@
> format list fl;
> identifier fn;
> expression list e;
> position p;
> @@
>
> fn("%@fl@", e@p)
> ....
>
> Then, I could handle the *format list* using *make_expr()* as well. But,
> Is it possible to rename/handle the *expression list?*
>
>
> On Tue, Dec 3, 2019 at 3:18 AM Julia Lawall <julia.lawall@inria.fr> wrote:
>
>> ------------------------------
>>
>> *De: *"Strace Labs" <stracelabs@gmail.com>
>> *À: *"Markus Elfring" <Markus.Elfring@web.de>
>> *Cc: *"Julia Lawall" <julia.lawall@inria.fr>, cocci@systeme.lip6.fr
>> *Envoyé: *Mardi 3 Décembre 2019 11:30:14
>> *Objet: *Re: [Cocci] Changing format string usage with SmPL?
>>
>> 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.
>>
>> OK, if you may have more than one argument to your print, then you can
>> find the offset using an expression list metavariable:
>>
>> @r@
>> expression list[n] between;
>> @@
>>
>> print(s,between,h2->name,...)
>>
>> Then you can use r.n in your python rule to figure out where is the %s to
>> change.  Unfortunately, this will not work well if there are multiple name
>> references in the argument list.  Because you will be trying to change the
>> format string in multiple ways, eg once where between has length 2 and once
>> where between has length 4.  Substantial hacks would be required to deal
>> with this.
>>
>> It would be nice if you could do
>>
>> @r@
>> expression list[bn] between;
>> expression list[an] after;
>> position p;
>> @@
>> print@p(s,between,name,after)
>>
>> @@
>> format list[r.bn] f1;
>> format list[r.an] f2;
>> position r.p;
>> @@
>> print@p(
>> -    "%@f1@%s%@f2@"
>> +   "%@f1@%m%@f2@"
>> , l)
>>
>> I don't know if that would work, though.
>>
>> julia
>>
>> Regards,
>>> Markus
>>>
>>
>>

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

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

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-03 17:28                       ` [Cocci] Changing format string usage with SmPL? Strace Labs
  2019-12-04  0:21                         ` Strace Labs
@ 2019-12-04  6:47                         ` Julia Lawall
  2019-12-06 19:44                           ` Markus Elfring
  2019-12-06 19:20                         ` Markus Elfring
  2 siblings, 1 reply; 31+ messages in thread
From: Julia Lawall @ 2019-12-04  6:47 UTC (permalink / raw)
  To: Strace Labs; +Cc: cocci


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

> De: "Strace Labs" <stracelabs@gmail.com>
> À: "Julia Lawall" <julia.lawall@inria.fr>
> Cc: "cocci" <cocci@systeme.lip6.fr>
> Envoyé: Mercredi 4 Décembre 2019 01:28:22
> Objet: Re: [Cocci] Changing format string usage with SmPL?

> Unfortunately, it doesn't work. But, I am working on some solutions using
> Python.

> therefore, once we have something like:

> ...
> @r1@
> format list fl;
> identifier fn;
> expression list e;
> position p;
> @@

> fn("%@fl@", e@p)
> ....

> Then, I could handle the format list using make_expr() as well. But, Is it
> possible to rename/handle the expression list?

Could you fix up the expression list first? Then you can write a rule like 

char[] s; 

fn(s, ..., 
- oldcode 
+ newcode 
,...) 

julia 

> On Tue, Dec 3, 2019 at 3:18 AM Julia Lawall < [ mailto:julia.lawall@inria.fr |
> julia.lawall@inria.fr ] > wrote:

>>> De: "Strace Labs" < [ mailto:stracelabs@gmail.com | stracelabs@gmail.com ] >
>>> À: "Markus Elfring" < [ mailto:Markus.Elfring@web.de | Markus.Elfring@web.de ] >
>>> Cc: "Julia Lawall" < [ mailto:julia.lawall@inria.fr | julia.lawall@inria.fr ] >,
>>> [ mailto:cocci@systeme.lip6.fr | cocci@systeme.lip6.fr ]
>>> Envoyé: Mardi 3 Décembre 2019 11:30:14
>>> Objet: Re: [Cocci] Changing format string usage with SmPL?

>>> On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring < [ mailto:Markus.Elfring@web.de |
>>> 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", [ http://h1.name/ | h1.name ] );
>>> my_printf("1234 %d %s @ %d %s | %s -> city=%s", id, [ http://s1.name/ | 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, [ http://s1.name/ | 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.

>> OK, if you may have more than one argument to your print, then you can find the
>> offset using an expression list metavariable:

>> @r@
>> expression list[n] between;
>> @@

>> print(s,between,h2->name,...)

>> Then you can use r.n in your python rule to figure out where is the %s to
>> change. Unfortunately, this will not work well if there are multiple name
>> references in the argument list. Because you will be trying to change the
>> format string in multiple ways, eg once where between has length 2 and once
>> where between has length 4. Substantial hacks would be required to deal with
>> this.

>> It would be nice if you could do

>> @r@
>> expression list[bn] between;
>> expression list[an] after;
>> position p;
>> @@
>> print@p(s,between,name,after)

>> @@
>> format list[ [ http://r.bn/ | r.bn ] ] f1;
>> format list[ [ http://r.an/ | r.an ] ] f2;
>> position r.p;
>> @@
>> print@p(
>> - "%@f1@%s%@f2@"
>> + "%@f1@%m%@f2@"
>> , l)

>> I don't know if that would work, though.

>> julia

>>>> Regards,
>>>> Markus

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

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

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-03 17:28                       ` [Cocci] Changing format string usage with SmPL? Strace Labs
  2019-12-04  0:21                         ` Strace Labs
  2019-12-04  6:47                         ` Julia Lawall
@ 2019-12-06 19:20                         ` Markus Elfring
  2 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-06 19:20 UTC (permalink / raw)
  To: stracelabs; +Cc: cocci

> Unfortunately, it doesn't work.

A bit more information would be nice for the explanation of the failure reason.

I assume that you are still looking for better support of format strings
with several conversion parameters.


> But, I am working on some solutions using Python.

I am curious how corresponding approaches will evolve further.


> But, Is it possible to rename/handle the *expression list?*

Renaming can not be performed for the list. Data processing can become more
interesting for the managed elements, can't it?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-04  0:21                         ` Strace Labs
@ 2019-12-06 19:36                           ` Markus Elfring
  2019-12-07  7:49                           ` Markus Elfring
  1 sibling, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-06 19:36 UTC (permalink / raw)
  To: stracelabs; +Cc: cocci

> Therefore, I could find the %fmt and replace by whatever I want based on
> the *expression-list. *currently struggled on that.

Are you also looking for direct support of such expression lists by
Coccinelle's programming interface (see also “man coccilib”)?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-04  6:47                         ` Julia Lawall
@ 2019-12-06 19:44                           ` Markus Elfring
  0 siblings, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-06 19:44 UTC (permalink / raw)
  To: Julia Lawall, stracelabs; +Cc: cocci

> Could you fix up the expression list first? Then you can write a rule like
>
> char[] s;
>
> fn(s, ...,
> - oldcode
> + newcode
> ,...)

Can it be that such a transformation approach will only work if the number
of passed function parameters will be fixed?

How should the data processing work with variable arguments?

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

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

* Re: [Cocci] Changing format string usage with SmPL?
  2019-12-04  0:21                         ` Strace Labs
  2019-12-06 19:36                           ` Markus Elfring
@ 2019-12-07  7:49                           ` Markus Elfring
  1 sibling, 0 replies; 31+ messages in thread
From: Markus Elfring @ 2019-12-07  7:49 UTC (permalink / raw)
  To: stracelabs; +Cc: cocci

> After some research, I could create a Python function called
> fmt_replace_by_pos() to replace the %fmt by the Indice position.

I imagine that this development direction can become more interesting.

Now I would like to point a few implementation details out
which can be improved in the shown SmPL script.


> REG = re.compile('([^%]|%%)*(%[^%])')

* I suggest to move the compilation for such a regular expression
  into the initialisation rule.

* I find the need for the alternation unclear.

* The data processing approach can become nicer if Coccinelle's programming interface
  would support also format lists directly.


> retval[i] = { 'idx': idx, 'fmt': fmt }

I wonder about the need for a separate Python dictionary here.


> print("** ERROR: Something wrong in fmt_replace_by_pos():\n
> {}\n".format(str(e)))

Would you like to use the output channel “standard error” instead?


> @main depends on s1 && r1@

The explicit dependency specification can probably be omitted.

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

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

end of thread, other threads:[~2019-12-07  7:49 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).