Re: [PATCH v9 9/9] cocci: allow padding with `strbuf_addf()`
From: Johannes Schindelin <hidden>
Date: 2022-01-07 13:04:03
Hi Teng, On Thu, 6 Jan 2022, Teng Long wrote:
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:
https://github.com/git/git/commit/28c23cd4c3902449aff72cb9a4a703220be0d6acDoing this in 9/9 is too late, by this time you already introduced the code site that requires this workaround. At the same time, I wonder why you want to defend spinning up the full-blown `printf()` machinery just to pad text that you can easily pad yourself. It sounds like a lot of trouble to me to introduce this patch and then use an uncommon method to pad a fixed string at runtime. Too much trouble for my liking. Ciao, Dscho
quoted hunk ↗ jump to hunk
Signed-off-by: Johannes Schindelin <redacted> Signed-off-by: Teng Long <redacted> --- contrib/coccinelle/strbuf.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci index d9ada69b43..2d6e0f58fc 100644 --- a/contrib/coccinelle/strbuf.cocci +++ b/contrib/coccinelle/strbuf.cocci@@ -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); --2.33.0.rc1.1794.g2ae0a9cb82