[PATCH v9 9/9] cocci: allow padding with `strbuf_addf()`
- From
Teng Long <dyroneteng@gmail.com>
- Date
- Jan 6, 2022, 04:31 UTC
- Message-ID
- <8dafb2b3779715aa277eb825a94af87b72f3e093.1641440700.git.dyroneteng@gmail.com>
- In-Reply-To
- <cover.1641440700.git.dyroneteng@gmail.com>
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
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