From ed69bc89234d4da124b1fb6cf99d6dae2b033a0b Mon Sep 17 00:00:00 2001 From: Tenari Date: Fri, 2 Oct 2026 07:19:29 -0500 Subject: [PATCH] fix stringDeleteCodepointAtByte() logic --- string.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/string.c b/string.c index a07b275..e9e68a1 100644 --- a/string.c +++ b/string.c @@ -262,14 +262,10 @@ fn u8 stringDeleteCodepointAtByte(String* s, u32 byte_offset) { if (s->length == 0) return 0; Codepoint cp = codepointFromBytes(s->bytes, byte_offset); - // shift all the bytes from the back towards the byte_offset - for (u32 i = 0; i < cp.size; i++) { - for (u32 ii = byte_offset+i; ii < s->length; ii++) { - s->bytes[ii] = s->bytes[ii+1]; - } - s->length -= 1; - } - s->bytes[byte_offset] = '\0'; + assert(cp.size + byte_offset <= s->length); + MemoryCopy(s->bytes + byte_offset, s->bytes + byte_offset + cp.size, s->length - byte_offset - cp.size); + s->length -= cp.size; + s->bytes[s->length] = '\0'; return cp.size; }