git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] cocci: simplify check for trivial format strings

From
René Scharfe <l.s.r@web.de>
Date
Feb 1, 2018, 18:56 UTC
Message-ID
<376eb2e8-0a95-233b-743b-cdc1caa49015@web.de>

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
Next: SZEDER Gábor
Message 1 of 3 in “cocci: simplify check for trivial format strings”
  1. cocci: simplify check for trivial format stringsRené Scharfe, Feb 1, 2018
  2. SZEDER GáborFeb 2, 2018
  3. René ScharfeFeb 2, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.