about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-20 11:54:26 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-20 11:56:26 +0200
commit9276603b49f3be41226fea47bb63f9d2f6baad8b (patch)
tree89557b2d4033d3e470d81ae7f6566ac3758b09df
parent3194b602d8b2f53d2db3a594300e104bcac67c10 (diff)
downloadchawan-9276603b49f3be41226fea47bb63f9d2f6baad8b.tar.gz
px: convert to float first for percentage values
px now converts to float64 before converting back to a layout unit
when calculating percentage values.
This should reduce overflow crashes somewhat.

(The real solution would be to not crash on overflow, but that's a
little more difficult problem to solve.)
-rw-r--r--src/css/values.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index cd27ce98..aa9feba0 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -408,7 +408,7 @@ func px*(l: CSSLength, window: WindowAttributes, p: LayoutUnit): LayoutUnit {.in
   of UNIT_CH: ch_to_px(l.num, window)
   of UNIT_IC: ic_to_px(l.num, window)
   of UNIT_EX: ex_to_px(l.num, window)
-  of UNIT_PERC: p * l.num / 100
+  of UNIT_PERC: toLayoutUnit(toFloat64(p) * l.num / 100)
   of UNIT_PX: toLayoutUnit(l.num)
   of UNIT_CM: toLayoutUnit(l.num * 37.8)
   of UNIT_MM: toLayoutUnit(l.num * 3.78)