]> Repositorios git - scryer-prolog.git/commitdiff
fix another integer overflow
authorSkgland <[email protected]>
Mon, 8 Dec 2025 18:59:43 +0000 (19:59 +0100)
committerBennet Bleßmann <[email protected]>
Mon, 8 Dec 2025 18:59:43 +0000 (19:59 +0100)
src/machine/heap.rs

index c93d005b4675fc21d27bf0a4b68cd525767a970f..d8c52ac8fb0ab8d977f6e3308557d3afd547f8ad 100644 (file)
@@ -1148,7 +1148,9 @@ pub fn sized_iter_to_heap_list<SrcT: Into<HeapCellValue>>(
 ) -> Result<HeapCellValue, AllocError> {
     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() {