From 995a39419acea117a30791c7db6e321804250f9f Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sat, 19 Apr 2025 23:51:26 -0700 Subject: [PATCH] fix read_s logic around HeapPtr::PStrLoc (#2894) --- src/machine/machine_state_impl.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index 45c689a5..0358cfd4 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -345,8 +345,8 @@ impl MachineState { pub(crate) fn read_s(&mut self) -> HeapCellValue { match self.s { HeapPtr::HeapCell(h) => self.deref(self.heap[h + self.s_offset]), - HeapPtr::PStr(h) => { - let mut char_iter = self.heap.char_iter(h); + HeapPtr::PStr(byte_index) => { + let mut char_iter = self.heap.char_iter(byte_index); if self.s_offset == 0 { // read the car of the list @@ -354,10 +354,9 @@ impl MachineState { char_as_cell!(c) } else { // read the (self.s_offset)^{th} cdr of the list - let byte_offset: usize = - char_iter.take(self.s_offset).map(|c| c.len_utf8()).sum(); - let new_h = h + byte_offset; - + // self.s_offset is the number of bytes offset into the PStr + // in this context, *not* the number of heap cells. + let new_h = byte_index + self.s_offset; self.s_offset = 0; if self.heap.char_iter(new_h).next().is_some() { -- 2.54.0