From c04f1dea481617c059d8012923bb4f7b83b2924f Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 23 Sep 2023 18:32:32 -0600 Subject: [PATCH] fix off-by-1 bug in '$skip_max_list'/4 (#2037) --- src/machine/system_calls.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 9e2d9760..4a54ad91 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -180,12 +180,6 @@ impl BrentAlgState { } pub fn to_result(mut self, heap: &[HeapCellValue]) -> CycleSearchResult { - /* - if let Some(var) = heap[self.hare].as_var() { - return CycleSearchResult::PartialList(self.num_steps(), var); - } - */ - loop { read_heap_cell!(heap[self.hare], (HeapCellValueTag::PStrOffset) => { @@ -248,7 +242,7 @@ impl BrentAlgState { let cstr = PartialString::from(cstr_atom); let num_chars = cstr.as_str_from(offset).chars().count(); - if self.max_steps == -1 || self.num_steps() + num_chars < self.max_steps as usize { + if self.max_steps == -1 || self.num_steps() + num_chars <= self.max_steps as usize { self.pstr_chars += num_chars; Some(CycleSearchResult::ProperList(self.num_steps())) } else { @@ -261,7 +255,7 @@ impl BrentAlgState { let pstr = PartialString::from(pstr_atom); let num_chars = pstr.as_str_from(offset).chars().count(); - if self.max_steps == -1 || self.num_steps() + num_chars < self.max_steps as usize { + if self.max_steps == -1 || self.num_steps() + num_chars <= self.max_steps as usize { self.pstr_chars += num_chars - 1; self.step(h+1) } else { -- 2.54.0