Skip to content

Commit 22184af

Browse files
dschogitster
authored andcommitted
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: 28c23cd (strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other, 2019-01-25) Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Teng Long <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e815171 commit 22184af

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

contrib/coccinelle/strbuf.cocci

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ constant fmt !~ "%";
1515
@@
1616
expression E;
1717
struct strbuf SB;
18-
format F =~ "s";
18+
format F =~ "^s$";
1919
@@
2020
- strbuf_addf(E, "%@F@", SB.buf);
2121
+ strbuf_addbuf(E, &SB);
2222

2323
@@
2424
expression E;
2525
struct strbuf *SBP;
26-
format F =~ "s";
26+
format F =~ "^s$";
2727
@@
2828
- strbuf_addf(E, "%@F@", SBP->buf);
2929
+ strbuf_addbuf(E, SBP);
@@ -44,7 +44,7 @@ struct strbuf *SBP;
4444

4545
@@
4646
expression E1, E2;
47-
format F =~ "s";
47+
format F =~ "^s$";
4848
@@
4949
- strbuf_addf(E1, "%@F@", E2);
5050
+ strbuf_addstr(E1, E2);

0 commit comments

Comments
 (0)