fixes ptr to cstring warnings[backport] (#20848)

* fix =#13790 ptr char (+friends) should not implicitly convert to cstring

* Apply suggestions from code review

* first round; compiles on windows

* nimPreviewSlimSystem

* conversion is unsafe, cast needed

* fixes more tests

* fixes asyncnet

* another try another error

* last one

* true

* one more

* why bugs didn't show at once

* add `nimPreviewCstringConversion` switch

* typo

* fixes ptr to cstring warnings[backport]

* add fixes

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
This commit is contained in:
ringabout 2022-11-16 17:22:51 +08:00 • committed by GitHub
commit 06cd15663d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 50 additions and 50 deletions

View file

@ -481,13 +481,13 @@ when not useNimNetLite:
result = newString(addrLen)
let addr6 = addr cast[ptr Sockaddr_in6](sockAddr).sin6_addr
when not useWinVersion:
if posix.inet_ntop(posix.AF_INET6, addr6, addr result[0],
if posix.inet_ntop(posix.AF_INET6, addr6, cast[cstring](addr result[0]),
result.len.int32) == nil:
raiseOSError(osLastError())
if posix.IN6_IS_ADDR_V4MAPPED(addr6) != 0:
result.setSlice("::ffff:".len..<addrLen)
else:
if winlean.inet_ntop(winlean.AF_INET6, addr6, addr result[0],
if winlean.inet_ntop(winlean.AF_INET6, addr6, cast[cstring](addr result[0]),
result.len.int32) == nil:
raiseOSError(osLastError())
setLen(result, len(cstring(result)))
@ -509,23 +509,23 @@ when not useNimNetLite:
if sockAddr.sa_family.cint == nativeAfInet:
let addr4 = addr cast[ptr Sockaddr_in](sockAddr).sin_addr
when not useWinVersion:
if posix.inet_ntop(posix.AF_INET, addr4, addr strAddress[0],
if posix.inet_ntop(posix.AF_INET, addr4, cast[cstring](addr strAddress[0]),
strAddress.len.int32) == nil:
raiseOSError(osLastError())
else:
if winlean.inet_ntop(winlean.AF_INET, addr4, addr strAddress[0],
if winlean.inet_ntop(winlean.AF_INET, addr4, cast[cstring](addr strAddress[0]),
strAddress.len.int32) == nil:
raiseOSError(osLastError())
elif sockAddr.sa_family.cint == nativeAfInet6:
let addr6 = addr cast[ptr Sockaddr_in6](sockAddr).sin6_addr
when not useWinVersion:
if posix.inet_ntop(posix.AF_INET6, addr6, addr strAddress[0],
if posix.inet_ntop(posix.AF_INET6, addr6, cast[cstring](addr strAddress[0]),
strAddress.len.int32) == nil:
raiseOSError(osLastError())
if posix.IN6_IS_ADDR_V4MAPPED(addr6) != 0:
strAddress.setSlice("::ffff:".len..<length)
else:
if winlean.inet_ntop(winlean.AF_INET6, addr6, addr strAddress[0],
if winlean.inet_ntop(winlean.AF_INET6, addr6, cast[cstring](addr strAddress[0]),
strAddress.len.int32) == nil:
raiseOSError(osLastError())
else:
@ -584,7 +584,7 @@ when not useNimNetLite:
# Cannot use INET6_ADDRSTRLEN here, because it's a C define.
result[0] = newString(64)
if inet_ntop(name.sin6_family.cint,
addr name.sin6_addr, addr result[0][0], (result[0].len+1).int32).isNil:
addr name.sin6_addr, cast[cstring](addr result[0][0]), (result[0].len+1).int32).isNil:
raiseOSError(osLastError())
setLen(result[0], result[0].cstring.len)
result[1] = Port(nativesockets.ntohs(name.sin6_port))
@ -621,7 +621,7 @@ when not useNimNetLite:
# Cannot use INET6_ADDRSTRLEN here, because it's a C define.
result[0] = newString(64)
if inet_ntop(name.sin6_family.cint,
addr name.sin6_addr, addr result[0][0], (result[0].len+1).int32).isNil:
addr name.sin6_addr, cast[cstring](addr result[0][0]), (result[0].len+1).int32).isNil:
raiseOSError(osLastError())
setLen(result[0], result[0].cstring.len)
result[1] = Port(nativesockets.ntohs(name.sin6_port))