{"thread":{"id":"47643","subject":"[PATCH] cocci: use format keyword instead of a literal string","startedAt":"2018-01-19T17:06:14Z","lastAt":"2018-01-19T17:06:14Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"336896","messageId":"1955155b-3853-300a-869f-5d59356c1a94@web.de","threadId":"47643","inReplyTo":null,"subject":"[PATCH] cocci: use format keyword instead of a literal string","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-01-19T17:05:59Z","receivedAt":"2018-01-19T17:06:14Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"There's a rule in strbuf.cocci for converting trivial uses of\nstrbuf_addf() to strbuf_addstr() in order to simplify the code and\nimprove performance a bit.  Coccinelle 1.0.0~rc19.deb-3 on Travis CI\nlets the \"%s\" in that rule match format strings like \"%d\" as well for\nsome reason, though, leading to invalid proposed patches.\n\nUse the \"format\" keyword to let Coccinelle parse the format string and\nmatch the conversion specifier with a trivial regular expression\ninstead.  This works fine with both Coccinelle 1.0.0~rc19.deb-3 and\n1.0.4.deb-3+b3 (the current version on Debian testing).\n\nReported-by: SZEDER Gábor <szeder.dev@gmail.com>\nTested-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n contrib/coccinelle/strbuf.cocci | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci\nindex 1d580e49b0..6fe8727421 100644\n--- a/contrib/coccinelle/strbuf.cocci\n+++ b/contrib/coccinelle/strbuf.cocci\n@@ -29,8 +29,9 @@ cocci.include_match(\"%\" not in fmt)\n \n @@\n expression E1, E2;\n+format F =~ \"s\";\n @@\n-- strbuf_addf(E1, \"%s\", E2);\n+- strbuf_addf(E1, \"%@F@\", E2);\n + strbuf_addstr(E1, E2);\n \n @@\n-- \n2.16.0\n"}]}