summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-01-26 23:50:19 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-01-26 23:50:19 +0100
commit8d3d9ce5cc8a7e82482c25c7acc7737410d76f3b (patch)
treedd64473dd53b4f9f92632020fc98eeff7c51e292
parent0b93db5a7cf85ae9b736538de7c2c880203a34a9 (diff)
downloadNim-8d3d9ce5cc8a7e82482c25c7acc7737410d76f3b.tar.gz
repr.nim: minor improvement when outputting addresses of cstrings
-rw-r--r--lib/system/repr.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/system/repr.nim b/lib/system/repr.nim
index db7fdcbca..04dbe1142 100644
--- a/lib/system/repr.nim
+++ b/lib/system/repr.nim
@@ -38,12 +38,12 @@ proc `$`(x: uint64): string =
     for t in 0 .. < half: swap(buf[t], buf[i-t-1])
     result = $buf
 
-proc reprStrAux(result: var string, s: string) =
+proc reprStrAux(result: var string, s: cstring; len: int) =
   if cast[pointer](s) == nil:
     add result, "nil"
     return
   add result, reprPointer(cast[pointer](s)) & "\""
-  for i in 0.. <s.len:
+  for i in 0.. <len:
     let c = s[i]
     case c
     of '"': add result, "\\\""
@@ -57,7 +57,7 @@ proc reprStrAux(result: var string, s: string) =
 
 proc reprStr(s: string): string {.compilerRtl.} =
   result = ""
-  reprStrAux(result, s)
+  reprStrAux(result, s, s.len)
 
 proc reprBool(x: bool): string {.compilerRtl.} =
   if x: result = "true"
@@ -277,11 +277,11 @@ when not defined(useNimRtl):
     of tyEnum: add result, reprEnum(getInt(p, typ.size), typ)
     of tyBool: add result, reprBool(cast[ptr bool](p)[])
     of tyChar: add result, reprChar(cast[ptr char](p)[])
-    of tyString: reprStrAux(result, cast[ptr string](p)[])
+    of tyString: reprStrAux(result, cast[ptr string](p)[], cast[ptr string](p)[].len)
     of tyCString:
       let cs = cast[ptr cstring](p)[]
       if cs.isNil: add result, "nil"
-      else: reprStrAux(result, $cs)
+      else: reprStrAux(result, cs, cs.len)
     of tyRange: reprAux(result, p, typ.base, cl)
     of tyProc, tyPointer:
       if cast[PPointer](p)[] == nil: add result, "nil"