gvalue: Add explicit casts in numeric transform functions

Compiling with `-Wfloat-conversion` warns about a few implicit
conversions from `double`/`float` to other numeric types in the `GValue`
transform functions.

These warnings are correct: value transformations can result in loss of
precision. That loss of precision is understood and expected, so add
some explicit casts to squash the warnings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
This commit is contained in:
Philip Withnall 2024-06-28 14:35:57 +01:00
parent cdbfef3842
commit 665292006e
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73
2 changed files with 3 additions and 2 deletions

View File

@ -51,7 +51,7 @@ static void \
value_transform_##func_name (const GValue *src_value, \
GValue *dest_value) \
{ \
ctype c_value = src_value->data[0].from_member; \
ctype c_value = (ctype) src_value->data[0].from_member; \
dest_value->data[0].to_member = c_value; \
} extern void glib_dummy_decl (void)
DEFINE_CAST (int_s8, v_int, gint8, v_int);

View File

@ -190,7 +190,8 @@ value_collect_float (GValue *value,
GTypeCValue *collect_values,
guint collect_flags)
{
value->data[0].v_float = collect_values[0].v_double;
/* This necessarily loses precision */
value->data[0].v_float = (gfloat) collect_values[0].v_double;
return NULL;
}