From 08e972d0799af17da43db2fb56bbfabdaac11400 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 18 Nov 2021 17:55:50 +0100 Subject: [PATCH] :art: Improve string slices --- src/lib/string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/string.c b/src/lib/string.c index e5a5287b..60559940 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -87,13 +87,13 @@ static INSTR(StringSlice) { return; } const m_int op = start < end ? 1 : -1; - const m_uint sz = op > 0 ? end - start : start - end; + const m_uint sz = (op > 0 ? end - start : start - end) + 1; if(sz >= SIZE_MAX/SZ_INT) { handle(shred, "SliceTooBig"); return; } char c[sz + 1]; - for (m_int i = start, j = 0; i != end; i += op, ++j) c[j] = str[i]; + for (m_int i = start, j = 0; j < (m_int)sz; i += op, ++j) c[j] = str[i]; c[sz] = '\0'; *(M_Object *)REG(-SZ_INT) = new_string(shred->info->vm->gwion, c); } -- 2.43.0