diff options
author | Arne Döring <arne.doering@gmx.net> | 2017-07-24 23:55:30 +0200 |
---|---|---|
committer | Arne Döring <arne.doering@gmx.net> | 2017-07-24 23:55:30 +0200 |
commit | 11914a23bebe4499f4161edb9a421e37a3182abe (patch) | |
tree | 5ac50b9942c277361726c36708fdbf8df1934adc /lib | |
parent | a6e6b05565ad717c77d6d66b3c6fd865ad0f615d (diff) | |
download | Nim-11914a23bebe4499f4161edb9a421e37a3182abe.tar.gz |
prevent null characters in $ on collections of char
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system.nim | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/system.nim b/lib/system.nim index 014538098..0bc0a0dbf 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2425,6 +2425,14 @@ proc collectionToString[T](x: T, prefix, separator, suffix: string): string = result.add "nil" else: result.add($value) + # prevent temporary string allocation + elif compiles(result.add(value)): + # don't insert '\0' characters into the result string + when value is char: + if value != '\0': + result.add(value) + else: + result.add(value) else: result.add($value) @@ -3307,7 +3315,6 @@ proc `$`*[T, IDX](x: array[IDX, T]): string = ## generic ``$`` operator for arrays that is lifted from the components collectionToString(x, "[", ", ", "]") - proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} = ## a shorthand for ``echo(errormsg); quit(errorcode)``. echo(errormsg) |