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:
ringabout
2022-11-16 17:22:51 +08:00
committed by GitHub
parent 3d692d08f7
commit 06cd15663d
25 changed files with 50 additions and 50 deletions

View File

@@ -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