summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-04-27 11:07:40 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-04-27 11:07:40 +0200
commitce36b8efd6795500694e954979e1ccb97058583d (patch)
treecfe0d16d2e4d65ffd9ad3025d7e1c28a67dc03ce /lib
parentef1b547f358ce610e8f728a05169a2ee434b8f87 (diff)
downloadNim-ce36b8efd6795500694e954979e1ccb97058583d.tar.gz
setLen doesn't crash on nil strings/seqs anymore
Diffstat (limited to 'lib')
-rw-r--r--lib/system/sysstr.nim11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim
index 7640b888b..42aae6654 100644
--- a/lib/system/sysstr.nim
+++ b/lib/system/sysstr.nim
@@ -226,8 +226,8 @@ proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} =
 
 proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} =
   var n = max(newLen, 0)
-  if wasMoved(s):
-    result = newOwnedString(s, n)
+  if s == nil:
+    result = mnewString(newLen)
   elif n <= s.space:
     result = s
   else:
@@ -313,6 +313,13 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
            (newLen*%elemSize)), (result.len-%newLen) *% elemSize)
   result.len = newLen
 
+proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {.
+    compilerRtl.} =
+  if s == nil:
+    result = cast[PGenericSeq](newSeq(typ, newLen))
+  else:
+    result = setLengthSeq(s, typ.base.size, newLen)
+
 # --------------- other string routines ----------------------------------
 proc add*(result: var string; x: int64) =
   let base = result.len