From 0544efcbb4070ababfeb3a2864ce5c5d4f4c19c0 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 13:10:53 +0100 Subject: 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 e4302fd74..a5ba2ea95 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); } } -- cgit v1.2.1