mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-27 19:06:31 +00:00
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>
(cherry picked from commit 06cd15663d)
This commit is contained in:
@@ -29,7 +29,7 @@ suite "inet_ntop tests":
|
||||
check: ip4.s_addr == 0x10111213'u32
|
||||
|
||||
var buff: array[0..255, char]
|
||||
let r = inet_ntop(AF_INET, cast[pointer](ip4.s_addr.addr), buff[0].addr, buff.len.int32)
|
||||
let r = inet_ntop(AF_INET, cast[pointer](ip4.s_addr.addr), cast[cstring](buff[0].addr), buff.len.int32)
|
||||
let res = if r == nil: "" else: $r
|
||||
check: res == "19.18.17.16"
|
||||
|
||||
@@ -42,9 +42,9 @@ suite "inet_ntop tests":
|
||||
var ip6 = [0x1000'u16, 0x1001, 0x2000, 0x2001, 0x3000, 0x3001, 0x4000, 0x4001]
|
||||
var buff: array[0..255, char]
|
||||
when defined(zephyr):
|
||||
let r = inet_ntop(AF_INET6, cast[pointer](ip6[0].addr), buff[0].addr, buff.len.int32)
|
||||
let r = inet_ntop(AF_INET6, cast[pointer](ip6[0].addr), cast[cstring](buff[0].addr), buff.len.int32)
|
||||
else:
|
||||
let r = inet_ntop(AF_INET6, ip6[0].addr, buff[0].addr, buff.sizeof.int32)
|
||||
let r = inet_ntop(AF_INET6, ip6[0].addr, cast[cstring](buff[0].addr), buff.sizeof.int32)
|
||||
let res = if r == nil: "" else: $r
|
||||
check: not ipv6Support or res == "10:110:20:120:30:130:40:140"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user