summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-04-27 09:57:14 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-04-27 09:57:20 +0200
commitef1b547f358ce610e8f728a05169a2ee434b8f87 (patch)
tree1e34d9b7b959c3467e504f2848d0946af5f4c675 /lib/system
parentc71c951a64c8c0adc6f6ae9992bc8bfeb003a31f (diff)
downloadNim-ef1b547f358ce610e8f728a05169a2ee434b8f87.tar.gz
'add' on a nil sequence doesn't produce a crash anymore
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/sysstr.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim
index ea0273340..7640b888b 100644
--- a/lib/system/sysstr.nim
+++ b/lib/system/sysstr.nim
@@ -261,6 +261,18 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
                                GenericSeqSize))
     result.reserved = r
 
+proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} =
+  if s == nil:
+    result = cast[PGenericSeq](newSeq(typ, 1))
+    result.len = 0
+  else:
+    result = s
+    if result.len >= result.space:
+      let r = resize(result.space)
+      result = cast[PGenericSeq](growObj(result, typ.base.size * r +
+                                GenericSeqSize))
+      result.reserved = r
+
 proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
     compilerRtl, inl.} =
   result = seq