From 3355b4972493ddce70019717534f20c10dc9ef11 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sun, 21 Nov 2021 11:30:15 -0700 Subject: [PATCH] add bounds check for attributed variables slice --- src/machine/attributed_variables.rs | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/machine/attributed_variables.rs b/src/machine/attributed_variables.rs index 48c5ec8b..30ec9a8c 100644 --- a/src/machine/attributed_variables.rs +++ b/src/machine/attributed_variables.rs @@ -82,19 +82,23 @@ impl MachineState { } pub(super) fn gather_attr_vars_created_since(&mut self, b: usize) -> IntoIter { - 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) -- 2.54.0