Skip to content

Commit

Permalink
cocci: allow padding with strbuf_addf()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho authored and gitster committed Mar 23, 2022
1 parent e815171 commit 22184af
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contrib/coccinelle/strbuf.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ constant fmt !~ "%";
@@
expression E;
struct strbuf SB;
format F =~ "s";
format F =~ "^s$";
@@
- strbuf_addf(E, "%@F@", SB.buf);
+ strbuf_addbuf(E, &SB);

@@
expression E;
struct strbuf *SBP;
format F =~ "s";
format F =~ "^s$";
@@
- strbuf_addf(E, "%@F@", SBP->buf);
+ strbuf_addbuf(E, SBP);
Expand All @@ -44,7 +44,7 @@ struct strbuf *SBP;

@@
expression E1, E2;
format F =~ "s";
format F =~ "^s$";
@@
- strbuf_addf(E1, "%@F@", E2);
+ strbuf_addstr(E1, E2);
Expand Down

0 comments on commit 22184af

Please sign in to comment.