From 616f071cd93b2e6061878a7a581787a861cb2429 Mon Sep 17 00:00:00 2001 From: Skgland Date: Mon, 8 Dec 2025 19:59:43 +0100 Subject: [PATCH] fix another integer overflow --- src/machine/heap.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/machine/heap.rs b/src/machine/heap.rs index c93d005b..d8c52ac8 100644 --- a/src/machine/heap.rs +++ b/src/machine/heap.rs @@ -1148,7 +1148,9 @@ pub fn sized_iter_to_heap_list>( ) -> Result { if size > 0 { let h = heap.cell_len(); - let mut writer = heap.reserve(1 + 2 * size)?; + // not using checked_add for 1 + as the result of multiplying by 2 will be even and the largest representable usize is odd, + // so the addition cannot overflow + let mut writer = heap.reserve(1 + size.checked_mul(2).ok_or(AllocError)?)?; writer.write_with(|section| { for (idx, value) in values.enumerate() { -- 2.54.0