Skip to content

Commit eaf43a1

Browse files
authored
fixes remaining ptr2cstring warnings on version-1-6 (#20861)
1 parent dd80e96 commit eaf43a1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/pure/os.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ when defined(windows) and not weirdTarget:
11461146
template findNextFile(a, b: untyped): untyped = findNextFileA(a, b)
11471147
template getCommandLine(): untyped = getCommandLineA()
11481148

1149-
template getFilename(f: untyped): untyped = $cstring(addr f.cFileName)
1149+
template getFilename(f: untyped): untyped = $cast[cstring](addr f.cFileName)
11501150

11511151
proc skipFindData(f: WIN32_FIND_DATA): bool {.inline.} =
11521152
# Note - takes advantage of null delimiter in the cstring
@@ -2337,7 +2337,7 @@ iterator walkDir*(dir: string; relative = false, checkDir = false):
23372337
while true:
23382338
var x = readdir(d)
23392339
if x == nil: break
2340-
var y = $cstring(addr x.d_name)
2340+
var y = $cast[cstring](addr x.d_name)
23412341
if y != "." and y != "..":
23422342
var s: Stat
23432343
let path = dir / y

lib/system/formatfloat.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ proc writeFloatToBufferSprintf*(buf: var array[65, char]; value: BiggestFloat):
4444
##
4545
## returns the amount of bytes written to `buf` not counting the
4646
## terminating '\0' character.
47-
var n: int = c_sprintf(addr buf, "%.16g", value)
47+
var n: int = c_sprintf(cast[cstring](addr buf), "%.16g", value)
4848
var hasDot = false
4949
for i in 0..n-1:
5050
if buf[i] == ',':
@@ -85,15 +85,15 @@ proc addFloatRoundtrip*(result: var string; x: float | float32) =
8585
else:
8686
var buffer {.noinit.}: array[65, char]
8787
let n = writeFloatToBufferRoundtrip(buffer, x)
88-
result.addCstringN(cstring(buffer[0].addr), n)
88+
result.addCstringN(cast[cstring](buffer[0].addr), n)
8989

9090
proc addFloatSprintf*(result: var string; x: float) =
9191
when nimvm:
9292
doAssert false
9393
else:
9494
var buffer {.noinit.}: array[65, char]
9595
let n = writeFloatToBufferSprintf(buffer, x)
96-
result.addCstringN(cstring(buffer[0].addr), n)
96+
result.addCstringN(cast[cstring](buffer[0].addr), n)
9797

9898
proc nimFloatToString(a: float): cstring =
9999
## ensures the result doesn't print like an integer, i.e. return 2.0, not 2

tests/system/tostring.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import strutils
4747

4848
let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
4949
doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\\x00']"
50-
doAssert $cast[cstring](addr arr) == "Hello World!"
50+
doAssert $cast[cstring](unsafeAddr arr) == "Hello World!"
5151

5252
proc takes(c: cstring) =
5353
doAssert c == cstring""

0 commit comments

Comments
 (0)