mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 07:26:15 +01:00
girnode: Explicitly lose precision on parsed float values
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 <pwithnall@gnome.org> Helps: #3405
This commit is contained in:
parent
ebe609eeef
commit
d0cba9e6ec
@ -2371,7 +2371,7 @@ gi_ir_node_build_typelib (GIIrNode *node,
|
|||||||
break;
|
break;
|
||||||
case GI_TYPE_TAG_FLOAT:
|
case GI_TYPE_TAG_FLOAT:
|
||||||
blob->size = sizeof (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;
|
break;
|
||||||
case GI_TYPE_TAG_DOUBLE:
|
case GI_TYPE_TAG_DOUBLE:
|
||||||
blob->size = sizeof (double);
|
blob->size = sizeof (double);
|
||||||
|
Loading…
Reference in New Issue
Block a user