fixes remaining ptr2cstring warnings on version-1-6 (#20861)

This commit is contained in:
ringabout
2022-11-17 04:19:32 +08:00
committed by GitHub
parent dd80e968e8
commit eaf43a1bd9
3 changed files with 6 additions and 6 deletions

View File

@@ -1146,7 +1146,7 @@ when defined(windows) and not weirdTarget:
template findNextFile(a, b: untyped): untyped = findNextFileA(a, b)
template getCommandLine(): untyped = getCommandLineA()
template getFilename(f: untyped): untyped = $cstring(addr f.cFileName)
template getFilename(f: untyped): untyped = $cast[cstring](addr f.cFileName)
proc skipFindData(f: WIN32_FIND_DATA): bool {.inline.} =
# Note - takes advantage of null delimiter in the cstring
@@ -2337,7 +2337,7 @@ iterator walkDir*(dir: string; relative = false, checkDir = false):
while true:
var x = readdir(d)
if x == nil: break
var y = $cstring(addr x.d_name)
var y = $cast[cstring](addr x.d_name)
if y != "." and y != "..":
var s: Stat
let path = dir / y

View File

@@ -44,7 +44,7 @@ proc writeFloatToBufferSprintf*(buf: var array[65, char]; value: BiggestFloat):
##
## returns the amount of bytes written to `buf` not counting the
## terminating '\0' character.
var n: int = c_sprintf(addr buf, "%.16g", value)
var n: int = c_sprintf(cast[cstring](addr buf), "%.16g", value)
var hasDot = false
for i in 0..n-1:
if buf[i] == ',':
@@ -85,7 +85,7 @@ proc addFloatRoundtrip*(result: var string; x: float | float32) =
else:
var buffer {.noinit.}: array[65, char]
let n = writeFloatToBufferRoundtrip(buffer, x)
result.addCstringN(cstring(buffer[0].addr), n)
result.addCstringN(cast[cstring](buffer[0].addr), n)
proc addFloatSprintf*(result: var string; x: float) =
when nimvm:
@@ -93,7 +93,7 @@ proc addFloatSprintf*(result: var string; x: float) =
else:
var buffer {.noinit.}: array[65, char]
let n = writeFloatToBufferSprintf(buffer, x)
result.addCstringN(cstring(buffer[0].addr), n)
result.addCstringN(cast[cstring](buffer[0].addr), n)
proc nimFloatToString(a: float): cstring =
## ensures the result doesn't print like an integer, i.e. return 2.0, not 2

View File

@@ -47,7 +47,7 @@ import strutils
let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\\x00']"
doAssert $cast[cstring](addr arr) == "Hello World!"
doAssert $cast[cstring](unsafeAddr arr) == "Hello World!"
proc takes(c: cstring) =
doAssert c == cstring""