Do not read past end of input. Ensure NUL termination.

This commit is contained in:
Charles Blake
2015-07-26 09:02:43 -04:00
parent ae303cc1c3
commit 18df5dad11

View File

@@ -82,7 +82,8 @@ proc copyStr(s: NimString, start: int): NimString {.compilerProc.} =
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
result = rawNewStringNoInit(len)
result.len = len
c_memcpy(result.data, str, len + 1)
c_memcpy(result.data, str, len)
result[result.len] = '\0'
proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} =
result = toNimStr(str, c_strlen(str))