~ chicken-core (master) 1eeaa7c203e8867e9859d8431c776d42de4f1602


commit 1eeaa7c203e8867e9859d8431c776d42de4f1602
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Fri Oct 16 22:54:53 2026 +0200
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Fri Oct 16 22:54:53 2026 +0200

    scratch-alloc may move objects, so recompute references

diff --git a/utf.c b/utf.c
index 8ff36e69..a899c8b6 100644
--- a/utf.c
+++ b/utf.c
@@ -267,8 +267,9 @@ C_regparm C_word C_utf_setsubchar(C_word s, C_word i, C_word c)
 
     if(nl > ol) {
         int tl = bvlen + nl - ol;
-        if(C_in_scratchspacep(bv)) C_mutate_scratch_slot(NULL, bv);
         C_word bvn = C_scratch_alloc(C_SIZEOF_BYTEVECTOR(tl + 1));
+        bv = C_block_item(s, 0);    // scratch_alloc may move object
+        if(C_in_scratchspacep(bv)) C_mutate_scratch_slot(NULL, bv);
         C_block_header_init(bvn, C_make_header(C_BYTEVECTOR_TYPE, tl + 1));
         if(prefix) C_memcpy(C_c_string(bvn), C_c_string(bv), prefix);
         C_memcpy((C_char *)C_data_pointer(bvn) + prefix, buf, nl);
@@ -300,7 +301,10 @@ C_regparm C_word C_utf_overwrite(C_word s, C_word i, C_word len, C_word bv,
 
     if(count > d) {
         int tl = bvlen + count - d;
+        // C_scratch_alloc() may move bvs
         C_word bvn = C_scratch_alloc(C_SIZEOF_BYTEVECTOR(tl + 1));
+        bvs = C_block_item(s, 0);
+        p2 = (C_char *)C_data_pointer(bvs) + prefix + d;
         if(C_in_scratchspacep(bvs)) C_mutate_scratch_slot(NULL, bvs);
         C_block_header_init(bvn, C_make_header(C_BYTEVECTOR_TYPE, tl + 1));
         if(prefix) C_memcpy(C_c_string(bvn), C_data_pointer(bvs), prefix);
Trap