]> git.ipfire.org Git - thirdparty/git.git/commit
strbuf.cocci: suggest strbuf_addbuf() to add one strbuf to an other
authorSZEDER Gábor <szeder.dev@gmail.com>
Fri, 25 Jan 2019 12:25:17 +0000 (13:25 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Jan 2019 00:21:09 +0000 (16:21 -0800)
commit28c23cd4c3902449aff72cb9a4a703220be0d6ac
tree5adc4148e4869d55f3e886f6778493facd325921
parent0d0ac3826a3bbb9247e39e12623bbcfdd722f24c
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>
contrib/coccinelle/strbuf.cocci