diff --git a/lib/system/strs_v2.nim b/lib/system/strs_v2.nim index c77ed6ad1e..95e76b1f8f 100644 --- a/lib/system/strs_v2.nim +++ b/lib/system/strs_v2.nim @@ -112,9 +112,10 @@ proc nimToCStringConv(s: NimStringV2): cstring {.compilerproc, nonReloadable, in proc appendString(dest: var NimStringV2; src: NimStringV2) {.compilerproc, inline.} = if src.len > 0: - # also copy the \0 terminator: - copyMem(unsafeAddr dest.p.data[dest.len], unsafeAddr src.p.data[0], src.len+1) + # don't copy the \0 terminator: + copyMem(unsafeAddr dest.p.data[dest.len], unsafeAddr src.p.data[0], src.len) inc dest.len, src.len + dest.p.data[dest.len] = '\0' proc appendChar(dest: var NimStringV2; c: char) {.compilerproc, inline.} = dest.p.data[dest.len] = c diff --git a/tests/system/t24664.nim b/tests/system/t24664.nim new file mode 100644 index 0000000000..b38e0b4dfc --- /dev/null +++ b/tests/system/t24664.nim @@ -0,0 +1,14 @@ +discard """ + output: ''' +TestString123TestString123 +TestString123TestString123 +''' +""" + +proc foostring() = # bug #24664 + for i in 0..1: + var s = "TestString123" + s.add s + echo s + +foostring() \ No newline at end of file