diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-11-16 17:22:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 10:22:51 +0100 |
commit | 06cd15663d6aed6cbf03a265f546043c47f250d4 (patch) | |
tree | 644bcc378c2a044655df58a91058b7c73e478d06 /lib/std | |
parent | 3d692d08f74e41588fa157b006e882f142bd77d4 (diff) | |
download | Nim-06cd15663d6aed6cbf03a265f546043c47f250d4.tar.gz |
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>
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/formatfloat.nim | 6 | ||||
-rw-r--r-- | lib/std/private/oscommon.nim | 2 | ||||
-rw-r--r-- | lib/std/private/osdirs.nim | 2 | ||||
-rw-r--r-- | lib/std/private/strimpl.nim | 2 | ||||
-rw-r--r-- | lib/std/private/win_setenv.nim | 4 | ||||
-rw-r--r-- | lib/std/syncio.nim | 2 |
6 files changed, 9 insertions, 9 deletions
diff --git a/lib/std/formatfloat.nim b/lib/std/formatfloat.nim index 6f2383760..2850f7021 100644 --- a/lib/std/formatfloat.nim +++ b/lib/std/formatfloat.nim @@ -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 diff --git a/lib/std/private/oscommon.nim b/lib/std/private/oscommon.nim index 66725395f..bab4856ca 100644 --- a/lib/std/private/oscommon.nim +++ b/lib/std/private/oscommon.nim @@ -63,7 +63,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 diff --git a/lib/std/private/osdirs.nim b/lib/std/private/osdirs.nim index 4b349817c..add9ed424 100644 --- a/lib/std/private/osdirs.nim +++ b/lib/std/private/osdirs.nim @@ -231,7 +231,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 diff --git a/lib/std/private/strimpl.nim b/lib/std/private/strimpl.nim index 7d19825f4..6a38cbfd2 100644 --- a/lib/std/private/strimpl.nim +++ b/lib/std/private/strimpl.nim @@ -106,7 +106,7 @@ func find*(s, sub: cstring, start: Natural = 0, last = 0): int = if sub.len > s.len - start: return -1 if sub.len == 1: return find(s, sub[0], start, last) if last == 0 and s.len > start: - let found = c_strstr(s[start].unsafeAddr, sub) + let found = c_strstr(cast[cstring](s[start].unsafeAddr), sub) if not found.isNil: result = cast[ByteAddress](found) -% cast[ByteAddress](s) else: diff --git a/lib/std/private/win_setenv.nim b/lib/std/private/win_setenv.nim index 9315f3e7e..303889a40 100644 --- a/lib/std/private/win_setenv.nim +++ b/lib/std/private/win_setenv.nim @@ -94,9 +94,9 @@ else: var buf = newSeq[char](requiredSize + 1) let buf2 = buf[0].addr if wcstombs(buf2, wideName, csize_t(requiredSize + 1)) != high(csize_t): - var ptrToEnv = c_getenv(buf2) + var ptrToEnv = c_getenv(cast[cstring](buf2)) ptrToEnv[0] = '\0' - ptrToEnv = c_getenv(buf2) + ptrToEnv = c_getenv(cast[cstring](buf2)) ptrToEnv[1] = '=' # And now, we have to update the outer environment to have a proper empty value. diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index d406c254f..16abc5afe 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -467,7 +467,7 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect], while true: # fixes #9634; this pattern may need to be abstracted as a template if reused; # likely other io procs need this for correctness. - fgetsSuccess = c_fgets(addr line[pos], sp.cint, f) != nil + fgetsSuccess = c_fgets(cast[cstring](addr line[pos]), sp.cint, f) != nil if fgetsSuccess: break when not defined(nimscript): if errno == EINTR: |