git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cocci: simplify check for trivial format strings
@ 2018-02-01 18:56 René Scharfe
  2018-02-02 14:34 ` SZEDER Gábor
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2018-02-01 18:56 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, SZEDER Gábor, Lars Schneider

353d84c537 (coccicheck: make transformation for strbuf_addf(sb, "...")
more precise) added a check to avoid transforming calls with format
strings which contain percent signs, as that would change the result.
It uses embedded Python code for that.  Simplify this rule by using the
regular expression matching operator instead.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
Inspired by the Coccinelle package in Debian experimental, which lost
support for Python for some reason.  Tested only with that version
(1.0.6.deb-3) and Debian testing's 1.0.4.deb-3+b3.

 contrib/coccinelle/strbuf.cocci | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index 6fe8727421..e34eada1ad 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -1,21 +1,6 @@
 @ strbuf_addf_with_format_only @
 expression E;
-constant fmt;
-@@
-  strbuf_addf(E,
-(
-  fmt
-|
-  _(fmt)
-)
-  );
-
-@ script:python @
-fmt << strbuf_addf_with_format_only.fmt;
-@@
-cocci.include_match("%" not in fmt)
-
-@ extends strbuf_addf_with_format_only @
+constant fmt !~ "%";
 @@
 - strbuf_addf
 + strbuf_addstr
-- 
2.16.1

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

* Re: [PATCH] cocci: simplify check for trivial format strings
  2018-02-01 18:56 [PATCH] cocci: simplify check for trivial format strings René Scharfe
@ 2018-02-02 14:34 ` SZEDER Gábor
  2018-02-02 18:49   ` René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: SZEDER Gábor @ 2018-02-02 14:34 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano, Lars Schneider

On Thu, Feb 1, 2018 at 7:56 PM, René Scharfe <l.s.r@web.de> wrote:
> 353d84c537 (coccicheck: make transformation for strbuf_addf(sb, "...")
> more precise) added a check to avoid transforming calls with format
> strings which contain percent signs, as that would change the result.
> It uses embedded Python code for that.  Simplify this rule by using the
> regular expression matching operator instead.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> Inspired by the Coccinelle package in Debian experimental, which lost
> support for Python for some reason.  Tested only with that version
> (1.0.6.deb-3) and Debian testing's 1.0.4.deb-3+b3.

FWIW, it appears to be working fine with Coccinelle version
1.0.0~rc19.deb-3 running on Travis CI.
Applied it on top of 'rs/strbuf-cocci-workaround' currently at cd9a4b6d9
(cocci: use format keyword instead of a literal string, 2018-01-19)
along with an other patch to show the resulting suggestions in
'.../*.cocci.patch' files, and the results look fine:

  https://travis-ci.org/szeder/git/jobs/336573242#L1466

and are the same as without this patch:

  https://travis-ci.org/szeder/git/jobs/336257153#L1466


>
>  contrib/coccinelle/strbuf.cocci | 17 +----------------
>  1 file changed, 1 insertion(+), 16 deletions(-)
>
> diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
> index 6fe8727421..e34eada1ad 100644
> --- a/contrib/coccinelle/strbuf.cocci
> +++ b/contrib/coccinelle/strbuf.cocci
> @@ -1,21 +1,6 @@
>  @ strbuf_addf_with_format_only @
>  expression E;
> -constant fmt;
> -@@
> -  strbuf_addf(E,
> -(
> -  fmt
> -|
> -  _(fmt)
> -)
> -  );
> -
> -@ script:python @
> -fmt << strbuf_addf_with_format_only.fmt;
> -@@
> -cocci.include_match("%" not in fmt)
> -
> -@ extends strbuf_addf_with_format_only @
> +constant fmt !~ "%";
>  @@
>  - strbuf_addf
>  + strbuf_addstr
> --
> 2.16.1

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

* Re: [PATCH] cocci: simplify check for trivial format strings
  2018-02-02 14:34 ` SZEDER Gábor
@ 2018-02-02 18:49   ` René Scharfe
  0 siblings, 0 replies; 3+ messages in thread
From: René Scharfe @ 2018-02-02 18:49 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Git List, Junio C Hamano, Lars Schneider

Am 02.02.2018 um 15:34 schrieb SZEDER Gábor:
> On Thu, Feb 1, 2018 at 7:56 PM, René Scharfe <l.s.r@web.de> wrote:
>> 353d84c537 (coccicheck: make transformation for strbuf_addf(sb, "...")
>> more precise) added a check to avoid transforming calls with format
>> strings which contain percent signs, as that would change the result.
>> It uses embedded Python code for that.  Simplify this rule by using the
>> regular expression matching operator instead.
>>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>> ---
>> Inspired by the Coccinelle package in Debian experimental, which lost
>> support for Python for some reason.  Tested only with that version
>> (1.0.6.deb-3) and Debian testing's 1.0.4.deb-3+b3.
> 
> FWIW, it appears to be working fine with Coccinelle version
> 1.0.0~rc19.deb-3 running on Travis CI.
> Applied it on top of 'rs/strbuf-cocci-workaround' currently at cd9a4b6d9
> (cocci: use format keyword instead of a literal string, 2018-01-19)
> along with an other patch to show the resulting suggestions in
> '.../*.cocci.patch' files, and the results look fine:
> 
>    https://travis-ci.org/szeder/git/jobs/336573242#L1466
> 
> and are the same as without this patch:
> 
>    https://travis-ci.org/szeder/git/jobs/336257153#L1466

It's good to hear that it doesn't error out, but there is no code in
master that would trigger a good or bad transformation.  It should
propose a patch for calls like this:

	strbuf_addf(sb, "just a string, better use strbuf_addstr");

... but leave those examples here alone:

	strbuf_addf(sb, "200%% more percent signs");
	strbuf_addf(sb, "error: %m");

René

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

end of thread, other threads:[~2018-02-02 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01 18:56 [PATCH] cocci: simplify check for trivial format strings René Scharfe
2018-02-02 14:34 ` SZEDER Gábor
2018-02-02 18:49   ` René Scharfe

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