fix off-by-1 bug in ''/4 (#2037)
This commit is contained in:
@@ -180,12 +180,6 @@ impl BrentAlgState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_result(mut self, heap: &[HeapCellValue]) -> CycleSearchResult {
|
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 {
|
loop {
|
||||||
read_heap_cell!(heap[self.hare],
|
read_heap_cell!(heap[self.hare],
|
||||||
(HeapCellValueTag::PStrOffset) => {
|
(HeapCellValueTag::PStrOffset) => {
|
||||||
@@ -248,7 +242,7 @@ impl BrentAlgState {
|
|||||||
let cstr = PartialString::from(cstr_atom);
|
let cstr = PartialString::from(cstr_atom);
|
||||||
let num_chars = cstr.as_str_from(offset).chars().count();
|
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;
|
self.pstr_chars += num_chars;
|
||||||
Some(CycleSearchResult::ProperList(self.num_steps()))
|
Some(CycleSearchResult::ProperList(self.num_steps()))
|
||||||
} else {
|
} else {
|
||||||
@@ -261,7 +255,7 @@ impl BrentAlgState {
|
|||||||
let pstr = PartialString::from(pstr_atom);
|
let pstr = PartialString::from(pstr_atom);
|
||||||
let num_chars = pstr.as_str_from(offset).chars().count();
|
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.pstr_chars += num_chars - 1;
|
||||||
self.step(h+1)
|
self.step(h+1)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user