cocci: allow padding with `strbuf_addf()`

A convenient way to pad strings is to use something like `strbuf_addf(&buf, "%20s", "Hello, world!")`. However, the Coccinelle rule that forbids a format `"%s"` with a constant string argument cast too wide a net, and also forbade such padding. The original rule was introduced by commit: 28c23cd4c39 (strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other, 2019-01-25) Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 23, 2022 at 17:13 UTC 22184af2cb89f74b7245c77f1c3c10dae6098bcf
1 file changed +3 -3
contrib/coccinelle/strbuf.cocci
+3 -3
@@ -15,7 +15,7 @@ constant fmt !~ "%";
15 @@
16 expression E;
17 struct strbuf SB;
18 -format F =~ "s";
18 +format F =~ "^s$";
19 @@
20 - strbuf_addf(E, "%@F@", SB.buf);
21 + strbuf_addbuf(E, &SB);
@@ -23,7 +23,7 @@ format F =~ "s";
23 @@
24 expression E;
25 struct strbuf *SBP;
26 -format F =~ "s";
26 +format F =~ "^s$";
27 @@
28 - strbuf_addf(E, "%@F@", SBP->buf);
29 + strbuf_addbuf(E, SBP);
@@ -44,7 +44,7 @@ struct strbuf *SBP;
44
45 @@
46 expression E1, E2;
47 -format F =~ "s";
47 +format F =~ "^s$";
48 @@
49 - strbuf_addf(E1, "%@F@", E2);
50 + strbuf_addstr(E1, E2);