]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cocci: strbuf.buf is never NULL
authorJunio C Hamano <gitster@pobox.com>
Thu, 19 Mar 2026 22:39:02 +0000 (15:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Mar 2026 01:33:33 +0000 (18:33 -0700)
We recently noticed one old code from 19 years ago protecting
against an ancient strbuf convention that the .buf member can be
NULL for an empty strbuf.  As that is no longer the case in the
modern codebase, let's catch such a construct.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/coccinelle/strbuf.cocci

index 5f06105df6db7b790a89d3af8633c511d68bc85b..13f0ad267902f5ba46aefabe50f455cee6289c25 100644 (file)
@@ -60,3 +60,10 @@ expression E1, E2;
 @@
 - strbuf_addstr(E1, real_path(E2));
 + strbuf_add_real_path(E1, E2);
+
+// In modern codebase, .buf member of an empty strbuf is not NULL.
+@@
+struct strbuf SB;
+@@
+- SB.buf ? SB.buf : ""
++ SB.buf