matrix_sdk_base: Member power level math from Int -> i64

master
Devin Ragotzy 2020-08-22 07:52:12 -04:00
parent 176181bdcf
commit 8a71cec81a
1 changed files with 8 additions and 1 deletions

View File

@ -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