From d37dac8f39d6ea932a63cebbac84d89c5e5f6ce8 Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Tue, 4 Apr 2023 02:46:09 +0800 Subject: [PATCH] Fix potential panic (#2755) * Fix potential panic * Update CHANGELOG.md * Use checked_div --------- Co-authored-by: Xiaopeng Li --- CHANGELOG.md | 2 ++ src/platform_impl/macos/monitor.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcff48c7a5..e9e6bb3067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On macOS, fixed potential panic when getting refresh rate. + # 0.28.3 - Fix macOS memory leaks. diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index 21250241fd..54a99040ad 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -230,7 +230,9 @@ impl MonitorHandle { return None; } - Some((time.time_scale as i64 / time.time_value * 1000) as u32) + (time.time_scale as i64) + .checked_div(time.time_value) + .map(|v| (v * 1000) as u32) } }