]> Repositorios git - scryer-prolog.git/commitdiff
add bounds checks for stackless iterator (#2110)
authorMark <[email protected]>
Sat, 14 Oct 2023 18:05:57 +0000 (12:05 -0600)
committerMark <[email protected]>
Sat, 14 Oct 2023 18:11:22 +0000 (12:11 -0600)
src/machine/gc.rs

index 8bb38e178e42987f191377cd55ab995e2142f0e6..5b1ccca3ee2f4d41584480b3dacb1ff1ccf91347 100644 (file)
@@ -280,9 +280,11 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
                             return Some(cell);
                         }
 
-                        if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() {
-                            let tag = HeapCellValueTag::AttrVar;
-                            return Some(HeapCellValue::build_with(tag, next));
+                        if self.next < self.heap.len() as u64 {
+                            if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() {
+                                let tag = HeapCellValueTag::AttrVar;
+                                return Some(HeapCellValue::build_with(tag, next));
+                            }
                         }
                     }
                     HeapCellValueTag::Var => {
@@ -297,9 +299,11 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
                             return Some(cell);
                         }
 
-                        if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() {
-                            let tag = HeapCellValueTag::Var;
-                            return Some(HeapCellValue::build_with(tag, next));
+                        if self.next < self.heap.len() as u64 {
+                            if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() {
+                                let tag = HeapCellValueTag::Var;
+                                return Some(HeapCellValue::build_with(tag, next));
+                            }
                         }
                     }
                     HeapCellValueTag::Str => {