cocci: add and apply a rule to find "unused" strbufs
commit4f40f6cb7365889b262aa93871964f70c91a9ebc
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 5 Jul 2022 13:46:59 +0000 (5 15:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2022 19:24:43 +0000 (6 12:24 -0700)
tree08640c84f6f2f5a86bbe0decd609cb140531d305
parent7a9a10b10e2f14ffb7c17e59f147186f85a2a94e
cocci: add and apply a rule to find "unused" strbufs

Add a coccinelle rule to remove "struct strbuf" initialization
followed by calling "strbuf_release()" function, without any uses of
the strbuf in the same function.

See the tests in contrib/coccinelle/tests/unused.{c,res} for what it's
intended to find and replace.

The inclusion of "contrib/scalar/scalar.c" is because "spatch" was
manually run on it (we don't usually run spatch on contrib).

Per the "buggy code" comment we also match a strbuf_init() before the
xmalloc(), but we're not seeking to be so strict as to make checks
that the compiler will catch for us redundant. Saying we'll match
either "init" or "xmalloc" lines makes the rule simpler.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
builtin/merge.c
contrib/coccinelle/tests/unused.c [new file with mode: 0644]
contrib/coccinelle/tests/unused.res [new file with mode: 0644]
contrib/coccinelle/unused.cocci [new file with mode: 0644]
contrib/scalar/scalar.c
diff.c