From 8a71cec81a5041254e99fc46264340b193d3392d Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Sat, 22 Aug 2020 07:52:12 -0400 Subject: [PATCH] matrix_sdk_base: Member power level math from Int -> i64 --- matrix_sdk_base/src/models/room.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matrix_sdk_base/src/models/room.rs b/matrix_sdk_base/src/models/room.rs index 4aa509f6..08d7c309 100644 --- a/matrix_sdk_base/src/models/room.rs +++ b/matrix_sdk_base/src/models/room.rs @@ -1047,7 +1047,14 @@ impl Room { } if max_power > int!(0) { - member.power_level_norm = Some((member.power_level.unwrap() * int!(100)) / max_power); + // `js_int::Int` can overflowed when math is done in `js_int::Int`s + // use i64 to avoid this + let normalized = { + let pl: i64 = member.power_level.unwrap_or_default().into(); + let max: i64 = max_power.into(); + Int::new((pl * 100_i64) / max) + }; + member.power_level_norm = normalized; } changed