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:
parent
3d692d08f7
commit
06cd15663d
25 changed files with 50 additions and 50 deletions
|
|
@ -229,7 +229,7 @@ when defineSsl:
|
|||
let len = bioCtrlPending(socket.bioOut)
|
||||
if len > 0:
|
||||
var data = newString(len)
|
||||
let read = bioRead(socket.bioOut, addr data[0], len)
|
||||
let read = bioRead(socket.bioOut, cast[cstring](addr data[0]), len)
|
||||
assert read != 0
|
||||
if read < 0:
|
||||
raiseSSLError()
|
||||
|
|
@ -247,7 +247,7 @@ when defineSsl:
|
|||
var data = await recv(socket.fd.AsyncFD, BufferSize, flags)
|
||||
let length = len(data)
|
||||
if length > 0:
|
||||
let ret = bioWrite(socket.bioIn, addr data[0], length.cint)
|
||||
let ret = bioWrite(socket.bioIn, cast[cstring](addr data[0]), length.cint)
|
||||
if ret < 0:
|
||||
raiseSSLError()
|
||||
elif length == 0:
|
||||
|
|
@ -459,7 +459,7 @@ proc send*(socket: AsyncSocket, data: string,
|
|||
when defineSsl:
|
||||
var copy = data
|
||||
sslLoop(socket, flags,
|
||||
sslWrite(socket.sslHandle, addr copy[0], copy.len.cint))
|
||||
sslWrite(socket.sslHandle, cast[cstring](addr copy[0]), copy.len.cint))
|
||||
await sendPendingSslData(socket, flags)
|
||||
else:
|
||||
await send(socket.fd.AsyncFD, data, flags)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -2435,11 +2435,11 @@ func formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
|||
frmtstr[3] = '*'
|
||||
frmtstr[4] = floatFormatToChar[format]
|
||||
frmtstr[5] = '\0'
|
||||
L = c_sprintf(addr buf, addr frmtstr, precision, f)
|
||||
L = c_sprintf(cast[cstring](addr buf), cast[cstring](addr frmtstr), precision, f)
|
||||
else:
|
||||
frmtstr[1] = floatFormatToChar[format]
|
||||
frmtstr[2] = '\0'
|
||||
L = c_sprintf(addr buf, addr frmtstr, f)
|
||||
L = c_sprintf(cast[cstring](addr buf), cast[cstring](addr frmtstr), f)
|
||||
result = newString(L)
|
||||
for i in 0 ..< L:
|
||||
# Depending on the locale either dot or comma is produced,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue