mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 20:17:42 +00:00
Check for nil in cstringArrayToSeq (#23747)
This fixes crashes in some specific network configurations (as `cstringArrayToSeq` is used extensively in `nativesockets`). --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
@@ -2102,12 +2102,14 @@ when not defined(js):
|
||||
proc cstringArrayToSeq*(a: cstringArray, len: Natural): seq[string] =
|
||||
## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
|
||||
## of length `len`.
|
||||
if a == nil: return @[]
|
||||
newSeq(result, len)
|
||||
for i in 0..len-1: result[i] = $a[i]
|
||||
|
||||
proc cstringArrayToSeq*(a: cstringArray): seq[string] =
|
||||
## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
|
||||
## terminated by `nil`.
|
||||
if a == nil: return @[]
|
||||
var L = 0
|
||||
while a[L] != nil: inc(L)
|
||||
result = cstringArrayToSeq(a, L)
|
||||
|
||||
Reference in New Issue
Block a user