From 1ab1cd6ba414afb9536dfd8273bf9ba273a5eb4a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 12:45:42 +0000 Subject: [PATCH] gfileutils: Add an assertion to help static analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This assertion basically mirrors the existing `buffer_size >= 2` assertion (one implies the other), but scan-build doesn’t seem to be able to work that out — so give it some help. Fixes: ``` ../../../glib/gfileutils.c: In function ‘g_get_current_dir’: ../../../glib/gfileutils.c:2995:17: warning: potential null pointer dereference [-Wnull-dereference] 2995 | buffer[1] = 0; | ~~~~~~~~~~^~~ ../../../glib/gfileutils.c:2994:17: warning: potential null pointer dereference [-Wnull-dereference] 2994 | buffer[0] = G_DIR_SEPARATOR; ``` Signed-off-by: Philip Withnall --- glib/gfileutils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/glib/gfileutils.c b/glib/gfileutils.c index f40400ca5..25500cbf5 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -2991,6 +2991,7 @@ g_get_current_dir (void) { /* Fallback return value */ g_assert (buffer_size >= 2); + g_assert (buffer != NULL); buffer[0] = G_DIR_SEPARATOR; buffer[1] = 0; }