From d63b0a192c25f9dd33902b8577fc813fea77efec Mon Sep 17 00:00:00 2001 From: Skgland Date: Sun, 7 Dec 2025 21:31:24 +0100 Subject: [PATCH] use checked multiplication in heap_index! macro --- src/macros.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 2eda4980..4ac590eb 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -471,11 +471,16 @@ macro_rules! resource_error_call_result { } macro_rules! heap_index { - ($idx:expr) => { + ($idx:expr) => {{ + let idx = $idx; std::mem::size_of::() - .checked_mul($idx) - .unwrap() - }; + .checked_mul(idx) + .expect(&format!( + "overflow while calculating heap index {idx} * {} > {}", + std::mem::size_of::(), + usize::MAX, + )) + }}; } macro_rules! cell_index { -- 2.54.0