diff options
author | Philip Withnall <pwithnall@endlessos.org> | 2020-10-14 13:10:53 +0100 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2020-10-14 13:15:09 +0100 |
commit | 0544efcbb4070ababfeb3a2864ce5c5d4f4c19c0 (patch) | |
tree | a4539bf80aa9c9ebcc6ff11ed1c93bc6b2b574c1 | |
parent | 12f87089284d92c6dc08393fd51219a9f7fff532 (diff) | |
download | glib-0544efcbb4070ababfeb3a2864ce5c5d4f4c19c0.tar.gz |
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 <pwithnall@endlessos.org>
-rw-r--r-- | glib/tests/mutex.c | 18 |
1 files 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); } } |