Skip to content

Commit

Permalink
fix off-by-1 bug in ''/4 (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Sep 24, 2023
1 parent 142e0c2 commit a5db117
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit a5db117

Please sign in to comment.