{"thread":{"id":"47738","subject":"[PATCH] cocci: simplify check for trivial format strings","startedAt":"2018-02-01T18:56:48Z","lastAt":"2018-02-02T18:50:04Z","messageCount":3,"participants":["René Scharfe","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"338035","messageId":"376eb2e8-0a95-233b-743b-cdc1caa49015@web.de","threadId":"47738","inReplyTo":null,"subject":"[PATCH] cocci: simplify check for trivial format strings","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-02-01T18:56:34Z","receivedAt":"2018-02-01T18:56:48Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"353d84c537 (coccicheck: make transformation for strbuf_addf(sb, \"...\")\nmore precise) added a check to avoid transforming calls with format\nstrings which contain percent signs, as that would change the result.\nIt uses embedded Python code for that.  Simplify this rule by using the\nregular expression matching operator instead.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\nInspired by the Coccinelle package in Debian experimental, which lost\nsupport for Python for some reason.  Tested only with that version\n(1.0.6.deb-3) and Debian testing's 1.0.4.deb-3+b3.\n\n contrib/coccinelle/strbuf.cocci | 17 +----------------\n 1 file changed, 1 insertion(+), 16 deletions(-)\n\ndiff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci\nindex 6fe8727421..e34eada1ad 100644\n--- a/contrib/coccinelle/strbuf.cocci\n+++ b/contrib/coccinelle/strbuf.cocci\n@@ -1,21 +1,6 @@\n @ strbuf_addf_with_format_only @\n expression E;\n-constant fmt;\n-@@\n-  strbuf_addf(E,\n-(\n-  fmt\n-|\n-  _(fmt)\n-)\n-  );\n-\n-@ script:python @\n-fmt << strbuf_addf_with_format_only.fmt;\n-@@\n-cocci.include_match(\"%\" not in fmt)\n-\n-@ extends strbuf_addf_with_format_only @\n+constant fmt !~ \"%\";\n @@\n - strbuf_addf\n + strbuf_addstr\n-- \n2.16.1\n"},{"id":"338095","messageId":"CAM0VKjnoux1CBq-HvzRW14hXZyviG_z_Rv-qv7d0kakh18zXcw@mail.gmail.com","threadId":"47738","inReplyTo":"376eb2e8-0a95-233b-743b-cdc1caa49015@web.de","subject":"Re: [PATCH] cocci: simplify check for trivial format strings","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-02-02T14:34:35Z","receivedAt":"2018-02-02T14:34:44Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Feb 1, 2018 at 7:56 PM, René Scharfe <l.s.r@web.de> wrote:\n> 353d84c537 (coccicheck: make transformation for strbuf_addf(sb, \"...\")\n> more precise) added a check to avoid transforming calls with format\n> strings which contain percent signs, as that would change the result.\n> It uses embedded Python code for that.  Simplify this rule by using the\n> regular expression matching operator instead.\n>\n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n> Inspired by the Coccinelle package in Debian experimental, which lost\n> support for Python for some reason.  Tested only with that version\n> (1.0.6.deb-3) and Debian testing's 1.0.4.deb-3+b3.\n\nFWIW, it appears to be working fine with Coccinelle version\n1.0.0~rc19.deb-3 running on Travis CI.\nApplied it on top of 'rs/strbuf-cocci-workaround' currently at cd9a4b6d9\n(cocci: use format keyword instead of a literal string, 2018-01-19)\nalong with an other patch to show the resulting suggestions in\n'.../*.cocci.patch' files, and the results look fine:\n\n  https://travis-ci.org/szeder/git/jobs/336573242#L1466\n\nand are the same as without this patch:\n\n  https://travis-ci.org/szeder/git/jobs/336257153#L1466\n\n\n>\n>  contrib/coccinelle/strbuf.cocci | 17 +----------------\n>  1 file changed, 1 insertion(+), 16 deletions(-)\n>\n> diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci\n> index 6fe8727421..e34eada1ad 100644\n> --- a/contrib/coccinelle/strbuf.cocci\n> +++ b/contrib/coccinelle/strbuf.cocci\n> @@ -1,21 +1,6 @@\n>  @ strbuf_addf_with_format_only @\n>  expression E;\n> -constant fmt;\n> -@@\n> -  strbuf_addf(E,\n> -(\n> -  fmt\n> -|\n> -  _(fmt)\n> -)\n> -  );\n> -\n> -@ script:python @\n> -fmt << strbuf_addf_with_format_only.fmt;\n> -@@\n> -cocci.include_match(\"%\" not in fmt)\n> -\n> -@ extends strbuf_addf_with_format_only @\n> +constant fmt !~ \"%\";\n>  @@\n>  - strbuf_addf\n>  + strbuf_addstr\n> --\n> 2.16.1\n"},{"id":"338108","messageId":"0df36d0a-6066-05c4-d471-f25a76ce301c@web.de","threadId":"47738","inReplyTo":"CAM0VKjnoux1CBq-HvzRW14hXZyviG_z_Rv-qv7d0kakh18zXcw@mail.gmail.com","subject":"Re: [PATCH] cocci: simplify check for trivial format strings","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-02-02T18:49:51Z","receivedAt":"2018-02-02T18:50:04Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 02.02.2018 um 15:34 schrieb SZEDER Gábor:\n> On Thu, Feb 1, 2018 at 7:56 PM, René Scharfe <l.s.r@web.de> wrote:\n>> 353d84c537 (coccicheck: make transformation for strbuf_addf(sb, \"...\")\n>> more precise) added a check to avoid transforming calls with format\n>> strings which contain percent signs, as that would change the result.\n>> It uses embedded Python code for that.  Simplify this rule by using the\n>> regular expression matching operator instead.\n>>\n>> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n>> ---\n>> Inspired by the Coccinelle package in Debian experimental, which lost\n>> support for Python for some reason.  Tested only with that version\n>> (1.0.6.deb-3) and Debian testing's 1.0.4.deb-3+b3.\n> \n> FWIW, it appears to be working fine with Coccinelle version\n> 1.0.0~rc19.deb-3 running on Travis CI.\n> Applied it on top of 'rs/strbuf-cocci-workaround' currently at cd9a4b6d9\n> (cocci: use format keyword instead of a literal string, 2018-01-19)\n> along with an other patch to show the resulting suggestions in\n> '.../*.cocci.patch' files, and the results look fine:\n> \n>    https://travis-ci.org/szeder/git/jobs/336573242#L1466\n> \n> and are the same as without this patch:\n> \n>    https://travis-ci.org/szeder/git/jobs/336257153#L1466\n\nIt's good to hear that it doesn't error out, but there is no code in\nmaster that would trigger a good or bad transformation.  It should\npropose a patch for calls like this:\n\n\tstrbuf_addf(sb, \"just a string, better use strbuf_addstr\");\n\n... but leave those examples here alone:\n\n\tstrbuf_addf(sb, \"200%% more percent signs\");\n\tstrbuf_addf(sb, \"error: %m\");\n\nRené\n"}]}