From: Jérémie Astor Date: Thu, 18 Nov 2021 16:55:50 +0000 (+0100) Subject: :art: Improve string slices X-Git-Tag: nightly~403 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=08e972d0799af17da43db2fb56bbfabdaac11400;p=gwion.git :art: Improve string slices --- 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); }