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

[PATCH 1/2] coccinelle: add rules to use strbuf_add() for adding buffers to strbufs

From
René Scharfe <l.s.r@web.de>
Date
Oct 1, 2017, 14:49 UTC
Message-ID
<85605bc6-2e91-7132-ce63-f6e08a08a768@web.de>

strbuf_addf() can be used with "%.*s" to add a buffer of a specific size to a strbuf, but the resulting code is longer, may require casting the length to int and is less efficient than simply calling strbuf_add(). Add Coccinelle rules for transforming calls of the former type to the latter.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 contrib/coccinelle/strbuf.cocci | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index 1d580e49b0..700a5f9c13 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -44,3 +44,15 @@ expression E1, E2;
 @@
 - strbuf_addstr(E1, real_path(E2));
 + strbuf_add_real_path(E1, E2);
+
+@@
+expression sb, buf, len;
+@@
+- strbuf_addf(sb, "%.*s", len, buf)
++ strbuf_add(sb, buf, len)
+
+@@
+expression sb, buf, len;
+@@
+- strbuf_addf(sb, "%.*s", (int)(len), buf)
++ strbuf_add(sb, buf, len)
-- 
2.14.2
Next: René Scharfe
Message 1 of 3 in “coccinelle: add rules to use strbuf_add() for adding buffers to strbufs”
  1. 1/2 coccinelle: add rules to use strbuf_add() for adding buffers to strbufsRené Scharfe, Oct 1, 2017
  2. 2/2 commit: use strbuf_add() to add a buffer to a strbufRené Scharfe, Oct 1, 2017
  3. Jeff KingOct 2, 2017

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.