diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim index 6972983fb45c3..a66f29e7190f2 100644 --- a/lib/system/dollars.nim +++ b/lib/system/dollars.nim @@ -25,7 +25,7 @@ proc `$`*(x: char): string {.magic: "CharToStr", noSideEffect.} const cLikeTarget = defined(c) or defined(cpp) when cLikeTarget: - proc c_strnlen(s: cstring, maxlen: csize_t): csize_t {.importc: "strnlen".} + proc c_strnlen(s: cstring, maxlen: csize_t): csize_t {.importc: "strnlen", header: "".} # see also: `strnlen_s` that also checks for nil, but may incur overhead proc strAppend*(result: var string, a: ptr char, n: int) {.inline.} = @@ -50,7 +50,7 @@ proc strAppend*[R](result: var string, a: array[R, char], stopAt0: bool) {.inlin ## If `stopAt0` is true we stop right before the first `\0`, if no `\0`, ## we append all elements. ## Compared to `$toCstring(addr(a))`, this prevents buffer overflow bugs at no - ## cost thanks to `len(a)` being known at compile time. + ## cost since `len(a)` is known. const N = len(a) static: doAssert N > 0 var n {.noinit.}: int @@ -60,9 +60,9 @@ proc strAppend*[R](result: var string, a: array[R, char], stopAt0: bool) {.inlin else: n = N strAppend(result, cast[ptr char](a.unsafeAddr), n) else: + const first = low(a) if stopAt0: n = 0 - const first = low(a) while n < N: if a[first+n] == '\0': break diff --git a/tests/stdlib/tmisc_imports.nim b/tests/stdlib/tmisc_imports.nim index 17ecd4730d78e..0c4a65e3ea60f 100644 --- a/tests/stdlib/tmisc_imports.nim +++ b/tests/stdlib/tmisc_imports.nim @@ -1,6 +1,13 @@ #[ catch regressions on modules for which we don't have tests yet; at least should catch some compilation errors. + +Note: `koch docs` is also catching some regressions but compared to it, this +invokes a single compilation step (will fail fast if any error), +and can be used locally to test different platforms via: +`--compileOnly --os:windows` (say, from osx). + +Note: we could use a glob as in `kochdocs`. ]# {.push warning[UnusedImport]: off.}