]> Repositorios git - scryer-prolog.git/commitdiff
use checked multiplication in heap_index! macro
authorSkgland <[email protected]>
Sun, 7 Dec 2025 20:31:24 +0000 (21:31 +0100)
committerBennet Bleßmann <[email protected]>
Sun, 7 Dec 2025 20:31:24 +0000 (21:31 +0100)
src/macros.rs

index 2eda4980312b65f25fd872a4bff38da5f6935c15..4ac590ebe1bbd718e7074905277c30fc47d509e1 100644 (file)
@@ -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::<HeapCellValue>()
-            .checked_mul($idx)
-            .unwrap()
-    };
+            .checked_mul(idx)
+            .expect(&format!(
+                "overflow while calculating heap index {idx} * {} > {}",
+                std::mem::size_of::<HeapCellValue>(),
+                usize::MAX,
+            ))
+    }};
 }
 
 macro_rules! cell_index {