From: Mark Date: Sun, 24 Sep 2023 00:32:32 +0000 (-0600) Subject: fix off-by-1 bug in '$skip_max_list'/4 (#2037) X-Git-Tag: remove~87 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=c04f1dea481617c059d8012923bb4f7b83b2924f;p=scryer-prolog.git fix off-by-1 bug in '$skip_max_list'/4 (#2037) --- 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 {