Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 29, 2020
1 parent 587deb5 commit 488e35c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/system/dollars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<string.h>".}
# see also: `strnlen_s` that also checks for nil, but may incur overhead

proc strAppend*(result: var string, a: ptr char, n: int) {.inline.} =
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/stdlib/tmisc_imports.nim
Original file line number Diff line number Diff line change
@@ -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.}
Expand Down

0 comments on commit 488e35c

Please sign in to comment.