From d0cba9e6ece022c8d03877c40a7eb8c42b84a981 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 28 Jun 2024 14:27:23 +0100 Subject: [PATCH] girnode: Explicitly lose precision on parsed float values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building a typelib, the values of constants need to be converted from a string format (from the GIR) to a binary format. This is currently done, for all numeric types, using `g_ascii_strto*()` functions, but with minimal validation. String values which are not representable as binary numbers are either silently truncated or clamped. `-Wfloat-conversion` has flagged that this happens for floats – a double-precision return from `g_ascii_strtod()` is implicitly cast down to a float. While we should ideally have some better error handling so that conversion to a typelib fails if a constant is not representable in the typelib, this is a problem for *all* numeric types and not just `float`, so add an explicit cast to ignore the error for now. In practice there probably isn’t a problem for any numeric types here, as there should be validation of the string value when the GIR is generated anyway. Signed-off-by: Philip Withnall Helps: #3405 --- girepository/girnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/girnode.c b/girepository/girnode.c index aacc2a0d3..b619b4174 100644 --- a/girepository/girnode.c +++ b/girepository/girnode.c @@ -2371,7 +2371,7 @@ gi_ir_node_build_typelib (GIIrNode *node, break; case GI_TYPE_TAG_FLOAT: blob->size = sizeof (float); - DO_ALIGNED_COPY (&data[blob->offset], parse_float_value (constant->value), float); + DO_ALIGNED_COPY (&data[blob->offset], (float) parse_float_value (constant->value), float); break; case GI_TYPE_TAG_DOUBLE: blob->size = sizeof (double);