From 39ea2d5899fdbcbe87be2f7f7c254530c3900402 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 21 Apr 2025 20:25:50 -0700 Subject: [PATCH] make self.s_offset use bytes in case of HeapPtr::PStr in UnifyVoid (#2897) --- src/machine/dispatch.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 254f9adc..94b26ad3 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -3072,9 +3072,19 @@ impl Machine { } &Instruction::UnifyVoid(n) => { match self.machine_st.mode { - MachineMode::Read => { - self.machine_st.s_offset += n; - } + MachineMode::Read => match &self.machine_st.s { + HeapPtr::HeapCell(_) => self.machine_st.s_offset += n, + &HeapPtr::PStr(pstr_loc) => { + debug_assert!(n <= 2); + let mut char_iter = self.machine_st.heap.char_iter(pstr_loc); + + // this only matters in the case that n == 1, but the case + // analysis isn't worth doing since the effect is benign if n == + // 2 + self.machine_st.s_offset += + char_iter.next().unwrap().len_utf8(); + } + }, MachineMode::Write => { let h = self.machine_st.heap.cell_len(); -- 2.54.0