Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2019-01-25 15:25:17 +0300
committerJunio C Hamano <gitster@pobox.com>2019-01-28 03:21:09 +0300
commit28c23cd4c3902449aff72cb9a4a703220be0d6ac (patch)
tree5adc4148e4869d55f3e886f6778493facd325921 /contrib
parent0d0ac3826a3bbb9247e39e12623bbcfdd722f24c (diff)
strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other
The best way to add one strbuf to an other is via: strbuf_addbuf(&sb, &sb2); This is a bit more idiomatic and efficient than: strbuf_addstr(&sb, sb2.buf); because the size of the second strbuf is known and thus it can spare a strlen() call, and much more so than: strbuf_addf(&sb, "%s", sb2.buf); because it can spare the whole vsnprintf() formatting magic. Add new semantic patches to 'contrib/coccinelle/strbuf.cocci' to catch these undesired patterns and to suggest strbuf_addbuf() instead. Luckily, our codebase is already clean from any such undesired patterns (but one of the in-flight topics just tried to sneak in such a strbuf_addf() call). Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/coccinelle/strbuf.cocci30
1 files changed, 30 insertions, 0 deletions
diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index e34eada1ad..d9ada69b43 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -13,6 +13,36 @@ constant fmt !~ "%";
);
@@
+expression E;
+struct strbuf SB;
+format F =~ "s";
+@@
+- strbuf_addf(E, "%@F@", SB.buf);
++ strbuf_addbuf(E, &SB);
+
+@@
+expression E;
+struct strbuf *SBP;
+format F =~ "s";
+@@
+- strbuf_addf(E, "%@F@", SBP->buf);
++ strbuf_addbuf(E, SBP);
+
+@@
+expression E;
+struct strbuf SB;
+@@
+- strbuf_addstr(E, SB.buf);
++ strbuf_addbuf(E, &SB);
+
+@@
+expression E;
+struct strbuf *SBP;
+@@
+- strbuf_addstr(E, SBP->buf);
++ strbuf_addbuf(E, SBP);
+
+@@
expression E1, E2;
format F =~ "s";
@@