From f64c50e76827f39c843102bc603817648a38a48c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 19 Mar 2026 15:39:02 -0700 Subject: [PATCH] cocci: strbuf.buf is never NULL 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 --- 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.52.0