diff --git a/compiler/int128.nim b/compiler/int128.nim index 74e581cd51..cc253fb682 100644 --- a/compiler/int128.nim +++ b/compiler/int128.nim @@ -460,7 +460,9 @@ proc addInt128*(result: var string; value: Int128) = var i = initialSize var j = high(result) while i < j: - swap(result[i], result[j]) + let tmp = result[i] + result[i] = result[j] + result[j] = tmp i += 1 j -= 1 diff --git a/lib/system/strs_v3.nim b/lib/system/strs_v3.nim index ff22e24ecc..81c52d3134 100644 --- a/lib/system/strs_v3.nim +++ b/lib/system/strs_v3.nim @@ -574,6 +574,7 @@ proc setLengthStrV2(s: var SmallString; newLen: int) {.compilerRtl.} = proc nimAsgnStrV2(a: var SmallString; b: SmallString) {.compilerRtl, inline.} = if ssLen(b) <= PayloadSize: + nimDestroyStrV1(a) # free any existing heap block before overwriting copyMem(addr a, unsafeAddr b, sizeof(SmallString)) else: if addr(a) == unsafeAddr(b): return