mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
setLen doesn't crash on nil strings/seqs anymore
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user