mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-29 18:53:58 +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>
This commit is contained in:
@@ -49,7 +49,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] == ',':
|
||||
@@ -90,7 +90,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:
|
||||
@@ -98,7 +98,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
|
||||
|
||||
Reference in New Issue
Block a user