mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
Fix newStringUninit not setting the '\0' terminator [backport] (#22746)
Causes problems when working with `cstring`s.
This commit is contained in:
committed by
GitHub
parent
eadd0d72cf
commit
a6c281bd1d
@@ -1639,10 +1639,14 @@ when not defined(js):
|
||||
## the same effect can be achieved with the `&` operator or with `add`.
|
||||
result = newStringOfCap(len)
|
||||
when defined(nimSeqsV2):
|
||||
cast[ptr int](addr result)[] = len
|
||||
let s = cast[ptr NimStringV2](addr result)
|
||||
if len > 0:
|
||||
s.len = len
|
||||
s.p.data[len] = '\0'
|
||||
else:
|
||||
var s = cast[PGenericSeq](result)
|
||||
let s = cast[NimString](result)
|
||||
s.len = len
|
||||
s.data[len] = '\0'
|
||||
else:
|
||||
proc newStringUninit*(len: Natural): string {.
|
||||
magic: "NewString", importc: "mnewString", noSideEffect.}
|
||||
|
||||
Reference in New Issue
Block a user