From 412aed7c70d0fc45fa313b254cd53a1070a318de Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 28 Jun 2024 14:31:18 +0100 Subject: [PATCH] gtestutils: Add some explicit double casts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids some false positive warnings from `-Wfloat-conversion`. The code in `gtestutils.c` is a bit odd: it uses an array of `long double` elements, with specific indices of that array storing specific meaningful numbers, each of which has a type which is representable as a `long double`, but which actually isn’t. This is a prime candidate for refactoring to not use such a type-unsafe API where everything is marshalled through `long double`. Unfortunately, the array is declared in `GTestLogMsg`, which is defined in the public `gtestutils.h` header, so we can’t change it. Boo. Signed-off-by: Philip Withnall Helps: #3405 --- glib/gtestutils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index ab7f1e1bc..8c1ef8893 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -747,9 +747,9 @@ static GPrintFunc g_default_print_func = NULL; enum { - G_TEST_CASE_LARGS_RESULT = 0, - G_TEST_CASE_LARGS_RUN_FORKS = 1, - G_TEST_CASE_LARGS_EXECUTION_TIME = 2, + G_TEST_CASE_LARGS_RESULT = 0, /* a GTestResult */ + G_TEST_CASE_LARGS_RUN_FORKS = 1, /* a gint */ + G_TEST_CASE_LARGS_EXECUTION_TIME = 2, /* a gdouble */ G_TEST_CASE_LARGS_MAX }; @@ -974,7 +974,7 @@ g_test_log (GTestLogType lbit, break; case G_TEST_LOG_STOP_CASE: result = largs[G_TEST_CASE_LARGS_RESULT]; - timing = largs[G_TEST_CASE_LARGS_EXECUTION_TIME]; + timing = (gdouble) largs[G_TEST_CASE_LARGS_EXECUTION_TIME]; fail = result == G_TEST_RUN_FAILURE; if (test_tap_log) { @@ -4373,7 +4373,7 @@ g_test_log_dump (GTestLogMsg *msg, g_string_append_len (gstring, msg->strings[ui], l); } for (ui = 0; ui < msg->n_nums; ui++) - gstring_append_double (gstring, msg->nums[ui]); + gstring_append_double (gstring, (gdouble) msg->nums[ui]); *len = gstring->len; gstring_overwrite_int (gstring, 0, *len); /* message length */ return (guint8*) g_string_free (gstring, FALSE);