From 271db1f409fa8452281a309b39242e0db35c4885 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 12:58:25 +0100 Subject: [PATCH 1/5] ghash: Move initialisation to declaration This introduces no functional changes, but should squash a warning from `scan-build`: ``` ../../../glib/ghash.c:575:3: warning: Value stored to 'small' is never read small = FALSE; ``` Signed-off-by: Philip Withnall --- glib/ghash.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/glib/ghash.c b/glib/ghash.c index 40a0fb2ca8..f3ed0f3b91 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -565,13 +565,12 @@ g_hash_table_remove_node (GHashTable *hash_table, static void g_hash_table_setup_storage (GHashTable *hash_table) { - gboolean small; + gboolean small = FALSE; /* We want to use small arrays only if: * - we are running on a system where that makes sense (64 bit); and * - we are not running under valgrind. */ - small = FALSE; #ifdef USE_SMALL_ARRAYS small = TRUE; -- GitLab From 2e7d3dcf7082e7f09b84b62cc68bd6b38bde39f9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 13:04:44 +0100 Subject: [PATCH 2/5] tests: Add some additional assertions to avoid scan-build warnings This should avoid warnings like: ``` ../../../glib/tests/regex.c:715:7: warning: Array access (from variable 'matches') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, matches[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ../../../glib/tests/regex.c:803:7: warning: Array access (from variable 'tokens') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, tokens[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ../../../glib/tests/regex.c:886:7: warning: Array access (from variable 'tokens') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, tokens[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ../../../glib/tests/regex.c:918:7: warning: Array access (from variable 'tokens') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, tokens[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ``` Signed-off-by: Philip Withnall --- glib/tests/regex.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glib/tests/regex.c b/glib/tests/regex.c index ee9cd21cac..1ea6f9288a 100644 --- a/glib/tests/regex.c +++ b/glib/tests/regex.c @@ -712,6 +712,7 @@ test_fetch_all (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (matches); g_assert_cmpstr (l_exp->data, ==, matches[i]); } @@ -800,6 +801,7 @@ test_split_simple (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (tokens); g_assert_cmpstr (l_exp->data, ==, tokens[i]); } @@ -883,6 +885,7 @@ test_split_full (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (tokens); g_assert_cmpstr (l_exp->data, ==, tokens[i]); } @@ -915,6 +918,7 @@ test_split (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (tokens); g_assert_cmpstr (l_exp->data, ==, tokens[i]); } -- GitLab From 12f87089284d92c6dc08393fd51219a9f7fff532 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 13:06:34 +0100 Subject: [PATCH 3/5] tests: Add an assertion to avoid a scan-build warning This should avoid the warning: ``` ../../../glib/tests/mainloop.c:119:3: warning: Value stored to 'id' is never read id = g_source_attach (source, ctx); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Signed-off-by: Philip Withnall --- glib/tests/mainloop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c index 1368e9bc05..ec96bfa8ad 100644 --- a/glib/tests/mainloop.c +++ b/glib/tests/mainloop.c @@ -121,6 +121,7 @@ test_maincontext_basic (void) g_source_set_funcs (source, &funcs); g_source_set_callback (source, cb, data, NULL); id = g_source_attach (source, ctx); + g_assert_cmpint (id, >, 0); g_source_unref (source); g_assert_true (g_source_remove_by_user_data (data)); g_assert_false (g_source_remove_by_user_data ((gpointer)0x1234)); -- GitLab From 0544efcbb4070ababfeb3a2864ce5c5d4f4c19c0 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 13:10:53 +0100 Subject: [PATCH 4/5] tests: Improve signed int handling to silence scan-build warnings This should silence the following warning: ``` ../../../glib/tests/mutex.c:206:5: warning: 1st function call argument is an uninitialized value g_thread_join (threads[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Signed-off-by: Philip Withnall --- glib/tests/mutex.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/glib/tests/mutex.c b/glib/tests/mutex.c index e4302fd74a..a5ba2ea95c 100644 --- a/glib/tests/mutex.c +++ b/glib/tests/mutex.c @@ -186,14 +186,16 @@ addition_thread (gpointer value) static void test_mutex_perf (gconstpointer data) { - gint n_threads = GPOINTER_TO_INT (data); + guint n_threads = GPOINTER_TO_UINT (data); GThread *threads[THREADS]; gint64 start_time; gdouble rate; gint x = -1; - gint i; + guint i; + + g_assert (n_threads <= G_N_ELEMENTS (threads)); - for (i = 0; i < n_threads - 1; i++) + for (i = 0; n_threads > 0 && i < n_threads - 1; i++) threads[i] = g_thread_create (addition_thread, &x, TRUE, NULL); /* avoid measuring thread setup/teardown time */ @@ -204,7 +206,7 @@ test_mutex_perf (gconstpointer data) rate = g_get_monotonic_time () - start_time; rate = x / rate; - for (i = 0; i < n_threads - 1; i++) + for (i = 0; n_threads > 0 && i < n_threads - 1; i++) g_thread_join (threads[i]); g_test_maximized_result (rate, "%f mips", rate); @@ -223,15 +225,15 @@ main (int argc, char *argv[]) if (g_test_perf ()) { - gint i; + guint i; - g_test_add_data_func ("/thread/mutex/perf/uncontended", NULL, test_mutex_perf); + g_test_add_data_func ("/thread/mutex/perf/uncontended", GUINT_TO_POINTER (0), test_mutex_perf); for (i = 1; i <= 10; i++) { gchar name[80]; - sprintf (name, "/thread/mutex/perf/contended/%d", i); - g_test_add_data_func (name, GINT_TO_POINTER (i), test_mutex_perf); + sprintf (name, "/thread/mutex/perf/contended/%u", i); + g_test_add_data_func (name, GUINT_TO_POINTER (i), test_mutex_perf); } } -- GitLab From e9c4e199500f73348c027f98cd83200eeb9eb00f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 13:13:07 +0100 Subject: [PATCH 5/5] tests: Add additional keyfile assertions These slightly improve the tests but, more importantly, squash a scan-build warning about assigning to a variable which is never subsequently used: ``` ../../../glib/tests/keyfile.c:1150:3: warning: Value stored to 'value' is never read value = g_key_file_get_string (keyfile, "a", "key=", &error); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/tests/keyfile.c:1159:3: warning: Value stored to 'value' is never read value = g_key_file_get_string (keyfile, "a", "key[", &error); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/tests/keyfile.c:1176:3: warning: Value stored to 'value' is never read value = g_key_file_get_string (keyfile, "a", " key", &error); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 warnings generated. ``` Signed-off-by: Philip Withnall --- glib/tests/keyfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/glib/tests/keyfile.c b/glib/tests/keyfile.c index ccbdadd567..7530bc8c32 100644 --- a/glib/tests/keyfile.c +++ b/glib/tests/keyfile.c @@ -1151,6 +1151,7 @@ test_key_names (void) check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND); + g_assert_null (value); g_key_file_free (keyfile); keyfile = g_key_file_new (); @@ -1160,6 +1161,7 @@ test_key_names (void) check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND); + g_assert_null (value); g_key_file_free (keyfile); keyfile = g_key_file_new (); @@ -1177,6 +1179,7 @@ test_key_names (void) check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND); + g_assert_null (value); g_key_file_free (keyfile); keyfile = g_key_file_new (); -- GitLab