From: Skgland Date: Sun, 7 Dec 2025 20:31:24 +0000 (+0100) Subject: use checked multiplication in heap_index! macro X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=d63b0a192c25f9dd33902b8577fc813fea77efec;p=scryer-prolog.git use checked multiplication in heap_index! macro --- 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 {