VM: accessing the string terminator is not allowed anymore; cleanup tests/system/tostring.nim

This commit is contained in:
Andreas Rumpf 2018-07-17 18:22:20 +02:00
commit 2e3f477957
2 changed files with 13 additions and 8 deletions

View file

@ -533,8 +533,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let s = regs[rb].node.strVal let s = regs[rb].node.strVal
if s.isNil: if s.isNil:
stackTrace(c, tos, pc, errNilAccess) stackTrace(c, tos, pc, errNilAccess)
elif idx <=% s.len: elif idx <% s.len:
regs[ra].intVal = s[idx].ord regs[ra].intVal = s[idx].ord
elif idx == s.len and optLaxStrings in c.config.options:
regs[ra].intVal = 0
else: else:
stackTrace(c, tos, pc, errIndexOutOfBounds) stackTrace(c, tos, pc, errIndexOutOfBounds)
of opcWrArr: of opcWrArr:

View file

@ -1,12 +1,12 @@
discard """ discard """
output:"" output: ""
""" """
doAssert "@[23, 45]" == $(@[23, 45]) doAssert "@[23, 45]" == $(@[23, 45])
doAssert "[32, 45]" == $([32, 45]) doAssert "[32, 45]" == $([32, 45])
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"]) doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"]) doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2)) doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2))
# bug #2395 # bug #2395
let alphaSet: set[char] = {'a'..'c'} let alphaSet: set[char] = {'a'..'c'}
@ -69,13 +69,13 @@ var yy: string
doAssert xx == @[] doAssert xx == @[]
doAssert yy == "" doAssert yy == ""
proc bar(arg: cstring): void = proc bar(arg: cstring) =
doAssert arg[0] == '\0' doAssert arg[0] == '\0'
proc baz(arg: openarray[char]): void = proc baz(arg: openarray[char]) =
doAssert arg.len == 0 doAssert arg.len == 0
proc stringCompare(): void = proc stringCompare() =
var a,b,c,d,e,f,g: string var a,b,c,d,e,f,g: string
a.add 'a' a.add 'a'
doAssert a == "a" doAssert a == "a"
@ -102,9 +102,12 @@ proc stringCompare(): void =
doAssert "" != "\0\0\0\0\0\0\0\0\0\0" doAssert "" != "\0\0\0\0\0\0\0\0\0\0"
var nilstring: string var nilstring: string
bar(nilstring) #bar(nilstring)
baz(nilstring) baz(nilstring)
stringCompare() stringCompare()
var nilstring: string
bar(nilstring)
static: static:
stringCompare() stringCompare()