Re: [PATCH v9 9/9] cocci: allow padding with `strbuf_addf()`
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 7, 2022, 13:03 UTC
- Message-ID
- <nycvar.QRO.7.76.6.2201071401240.339@tvgsbejvaqbjf.bet>
- In-Reply-To
- <8dafb2b3779715aa277eb825a94af87b72f3e093.1641440700.git.dyroneteng@gmail.com>
Hi Teng,
On Thu, 6 Jan 2022, Teng Long wrote:
Show 10 quoted lines
> 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/28c23cd4c3902449aff72cb9a4a703220be0d6ac
Doing 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
Show 24 quoted lines
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > Signed-off-by: Teng Long <dyroneteng@gmail.com> > --- > 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 > >