]> Repositorios git - scryer-prolog.git/commitdiff
add bounds check for attributed variables slice
authorMark Thom <[email protected]>
Sun, 21 Nov 2021 18:30:15 +0000 (11:30 -0700)
committerMark Thom <[email protected]>
Fri, 7 Jan 2022 04:44:41 +0000 (21:44 -0700)
src/machine/attributed_variables.rs

index 48c5ec8be93852b58f9a244e3ec85dc5fef40733..30ec9a8c9bbca922101b7e84562e02331cf1b695 100644 (file)
@@ -82,19 +82,23 @@ impl MachineState {
     }
 
     pub(super) fn gather_attr_vars_created_since(&mut self, b: usize) -> IntoIter<HeapCellValue> {
-        let mut attr_vars: Vec<_> = self.attr_var_init.attr_var_queue[b..]
-            .iter()
-            .filter_map(|h| {
-                read_heap_cell!(self.store(self.deref(heap_loc_as_cell!(*h))), //Addr::HeapCell(*h))) {
-                                (HeapCellValueTag::AttrVar, h) => {
-                                    Some(attr_var_as_cell!(h))
-                                }
-                                _ => {
-                                    None
-                                }
-                )
-            })
-            .collect();
+        let mut attr_vars: Vec<_> = if b >= self.attr_var_init.attr_var_queue.len() {
+            vec![]
+        } else {
+            self.attr_var_init.attr_var_queue[b..]
+                .iter()
+                .filter_map(|h| {
+                    read_heap_cell!(self.store(self.deref(heap_loc_as_cell!(*h))),
+                        (HeapCellValueTag::AttrVar, h) => {
+                            Some(attr_var_as_cell!(h))
+                        }
+                        _ => {
+                            None
+                        }
+                    )
+                })
+                .collect()
+        };
 
         attr_vars.sort_unstable_by(|a1, a2| {
             compare_term_test!(self, *a1, *a2).unwrap_or(Ordering::Less)