summaryrefslogtreecommitdiff
path: root/pango/pango-markup.c
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-07-13 21:08:31 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2021-07-21 19:20:03 +0200
commitd439eea5909b13a138930a668b3114a1dc4904b4 (patch)
tree5a2e4a6281889d2c4a23d26d6040bfbe0bb9cb02 /pango/pango-markup.c
parent5e20f517a297344c1424f78d9a6784a02b2f82da (diff)
downloadpango-d439eea5909b13a138930a668b3114a1dc4904b4.tar.gz
font-desc: Use local volatile double values to store sizes
Under i386 multiplying double and integer values and cast it to integer may end up to compute the wrong value when only 387 FPU is used, because the temporary value will be stored in a register whose precision isn't good enough. And so, some multiplications which are expected to produce an integer, will actually return a truncated value, that will be eventually floored. An example is 1.2 * 12800 that is clearly 15360.0, but will produce 15359 when casted to int in the said i386 environment. So use a temporary double variable to ensure that we do this computation in the double scope, before casting to int. And this will avoid using the said register, even when using more aggressive optimizations (as per marking the local variable volatile). Fixes: https://gitlab.gnome.org/GNOME/pango/-/issues/580
Diffstat (limited to 'pango/pango-markup.c')
-rw-r--r--pango/pango-markup.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 38e908c5..2828eab3 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -294,12 +294,16 @@ markup_data_close_tag (MarkupData *md)
if (ot->has_base_font_size)
{
- /* Create a font using the absolute point size
- * as the base size to be scaled from
- */
- a = pango_attr_size_new (scale_factor (ot->scale_level,
- 1.0) *
- ot->base_font_size);
+ /* Create a font using the absolute point size as the base size
+ * to be scaled from.
+ * We need to use a local variable to ensure that the compiler won't
+ * implicitly cast it to integer while the result is kept in registers,
+ * leading to a wrong approximation in i386 (with 387 FPU)
+ */
+ volatile double size;
+
+ size = scale_factor (ot->scale_level, 1.0) * ot->base_font_size;
+ a = pango_attr_size_new (size);
}
else
{