public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cocci: strbuf.buf is never NULL
@ 2026-03-19 22:39 Junio C Hamano
  2026-03-20 16:31 ` Derrick Stolee
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2026-03-19 22:39 UTC (permalink / raw)
  To: git

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>
---
 * Comes directly on top of my recent rerere.c clean-up patch.

 contrib/coccinelle/strbuf.cocci | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index 5f06105df6..13f0ad2679 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -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
-- 
2.53.0-816-g44373249a2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-20 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19 22:39 [PATCH] cocci: strbuf.buf is never NULL Junio C Hamano
2026-03-20 16:31 ` Derrick Stolee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox