summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-01-19 09:26:11 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-01-19 09:26:11 +0100
commit0b52466bb83a747ee7c3325f20b741ad243c0c6a (patch)
treefef083925c303b58144d5b4bcd51db5e3e8f9768
parentfea66497b4f36ed73cfaa5eaa962cfd30307930a (diff)
downloadNim-0b52466bb83a747ee7c3325f20b741ad243c0c6a.tar.gz
bugfix: do not call memcmp for nil strings
-rw-r--r--lib/system/sysstr.nim9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim
index 514223af2..31a59c0c0 100644
--- a/lib/system/sysstr.nim
+++ b/lib/system/sysstr.nim
@@ -25,9 +25,12 @@ proc cmpStrings(a, b: NimString): int {.inline, compilerProc.} =
   if a == nil: return -1
   if b == nil: return 1
   let minlen = min(a.len, b.len)
-  result = c_memcmp(addr a.data, addr b.data, minlen.csize)
-  if result == 0:
-    result = a.len - b.len
+  if minlen > 0:
+    result = c_memcmp(addr a.data, addr b.data, minlen.csize)
+    if result == 0:
+      result = a.len - b.len
+  else:
+    result = 0
 
 proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} =
   if a == b: return true