From 1ab1cd6ba414afb9536dfd8273bf9ba273a5eb4a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 12:45:42 +0000 Subject: [PATCH 1/6] 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; } From 472aef8278e5453528ff8db0668412dcc42ef6f0 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 12:52:40 +0000 Subject: [PATCH 2/6] tests: Add various non-null checks to extended error domain tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This silences various ‘potential null pointer dereference’ warnings from scan-build. Signed-off-by: Philip Withnall --- glib/tests/error.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/glib/tests/error.c b/glib/tests/error.c index 8dd40aa56..cdd6b1e3c 100644 --- a/glib/tests/error.c +++ b/glib/tests/error.c @@ -258,6 +258,8 @@ typedef struct static void test_error_private_init (TestErrorPrivate *priv) { + g_assert_nonnull (priv); + priv->foo = 13; /* If that triggers, it's test bug. */ @@ -272,15 +274,20 @@ static void test_error_private_copy (const TestErrorPrivate *src_priv, TestErrorPrivate *dest_priv) { + g_assert_nonnull (src_priv); + g_assert_nonnull (dest_priv); + dest_priv->foo = src_priv->foo; dest_priv->check = src_priv->check; + g_assert_nonnull (dest_priv->check); dest_priv->check->copy_called++; } static void test_error_private_clear (TestErrorPrivate *priv) { + g_assert_nonnull (priv->check); priv->check->free_called++; } @@ -291,6 +298,7 @@ fill_test_error (GError *error, TestErrorCheck *check) { TestErrorPrivate *test_error = test_error_get_private (error); + g_assert_nonnull (test_error); test_error->check = check; return test_error; @@ -326,6 +334,7 @@ test_extended (void) g_assert_cmpstr (error->message, ==, copy_error->message); copy_test_priv = test_error_get_private (copy_error); + g_assert_nonnull (copy_test_priv); g_assert_cmpint (test_priv->foo, ==, copy_test_priv->foo); g_error_free (error); From 61ce6d55117d3c446777c882dd6c6a59788d553b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 12:53:12 +0000 Subject: [PATCH 3/6] =?UTF-8?q?tests:=20Initialise=20an=20array=E2=80=99s?= =?UTF-8?q?=20elements=20to=20NULL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not strictly necessary, but helps scan-build understand that the `g_thread_join()` calls are not going to use uninitialised `GThread` pointers. It can’t reason that the number of loop iterations on the `g_thread_create()` and `g_thread_join()` loops are identical. Fixes: ``` ../../../glib/tests/mutex.c:271:5: warning: 1st function call argument is an uninitialized value [core.CallAndMessage] 271 | g_thread_join (threads[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Signed-off-by: Philip Withnall --- glib/tests/mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/tests/mutex.c b/glib/tests/mutex.c index bd484c59e..5a089a099 100644 --- a/glib/tests/mutex.c +++ b/glib/tests/mutex.c @@ -246,7 +246,7 @@ static void test_mutex_perf (gconstpointer data) { const guint n_threads = GPOINTER_TO_UINT (data); - GThread *threads[THREADS]; + GThread *threads[THREADS] = { NULL, }; gint64 start_time; gdouble rate; gint x = -1; From 6f6743de61fb20ad7519e71884f4b7d3d5f1ac11 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 13:05:02 +0000 Subject: [PATCH 4/6] gfilteroutputstream: Fix duplicated property name in doc comment Looks like a copy/paste error from the doc comment immediately below. Signed-off-by: Philip Withnall --- gio/gfilteroutputstream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gfilteroutputstream.c b/gio/gfilteroutputstream.c index cb1602ef3..4fc82d45c 100644 --- a/gio/gfilteroutputstream.c +++ b/gio/gfilteroutputstream.c @@ -89,7 +89,7 @@ g_filter_output_stream_class_init (GFilterOutputStreamClass *klass) ostream_class->close_fn = g_filter_output_stream_close; /** - * GFilterOutputStream:close-base-stream: + * GFilterOutputStream:base-stream: * * The underlying base stream on which the I/O ops will be done. */ From 5147d503b4a4dc73750d3a85adb344d98e4c12d3 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 13:05:38 +0000 Subject: [PATCH 5/6] goption: Fix typo in GIR annotation Signed-off-by: Philip Withnall --- glib/goption.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/goption.c b/glib/goption.c index 8ac283ce4..170b88dd2 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -2559,7 +2559,7 @@ g_option_context_get_description (GOptionContext *context) /** * g_option_context_parse_strv: * @context: a #GOptionContext - * @arguments: (inout) (array null-terminated=1) (optional): a pointer + * @arguments: (inout) (array zero-terminated=1) (optional): a pointer * to the command line arguments (which must be in UTF-8 on Windows). * Starting with GLib 2.62, @arguments can be %NULL, which matches * g_option_context_parse(). From e70144bf5b35c610f470cc864feb6f2946321764 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 31 Dec 2024 13:06:13 +0000 Subject: [PATCH 6/6] gtestutils: Add missing colon in GIR annotation Signed-off-by: Philip Withnall --- glib/gtestutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 9e9ee1e82..47bb9c66a 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -611,7 +611,7 @@ /** * g_assert_no_error: - * @err: (nullable) a `GError` + * @err: (nullable): a `GError` * * Debugging macro to check that a [struct@GLib.Error] is not set. *