fixes #235
This commit is contained in:
parent
7e31134ff6
commit
86ed918157
3 changed files with 19 additions and 1 deletions
|
|
@ -684,6 +684,10 @@ proc genArrayElem(p: BProc, e: PNode, d: var TLoc) =
|
||||||
else:
|
else:
|
||||||
lineCg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseIndexError();$n",
|
lineCg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseIndexError();$n",
|
||||||
[rdCharLoc(b), first, intLiteral(lastOrd(ty))])
|
[rdCharLoc(b), first, intLiteral(lastOrd(ty))])
|
||||||
|
else:
|
||||||
|
let idx = getOrdValue(e.sons[1])
|
||||||
|
if idx < firstOrd(ty) or idx > lastOrd(ty):
|
||||||
|
localError(e.info, errIndexOutOfBounds)
|
||||||
if d.k == locNone: d.s = a.s
|
if d.k == locNone: d.s = a.s
|
||||||
putIntoDest(p, d, elemType(skipTypes(ty, abstractVar)),
|
putIntoDest(p, d, elemType(skipTypes(ty, abstractVar)),
|
||||||
ropef("$1[($2)- $3]", [rdLoc(a), rdCharLoc(b), first]))
|
ropef("$1[($2)- $3]", [rdLoc(a), rdCharLoc(b), first]))
|
||||||
|
|
|
||||||
14
tests/reject/tinvalidarrayaccess.nim
Normal file
14
tests/reject/tinvalidarrayaccess.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "index out of bounds"
|
||||||
|
line: 11
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
type TTestArr = array[0..1, int16]
|
||||||
|
var f: TTestArr
|
||||||
|
f[0] = 30
|
||||||
|
f[1] = 40
|
||||||
|
f[2] = 50
|
||||||
|
f[3] = 60
|
||||||
|
|
||||||
|
echo(repr(f))
|
||||||
|
|
@ -81,7 +81,7 @@ case $uos in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $ucpu in
|
case $ucpu in
|
||||||
*i386* | *i486* | *i586* | *i686* | *bepc* )
|
*i386* | *i486* | *i586* | *i686* | *bepc* | *i86pc* )
|
||||||
mycpu="i386" ;;
|
mycpu="i386" ;;
|
||||||
*amd*64* | *x86-64* | *x86_64* )
|
*amd*64* | *x86-64* | *x86_64* )
|
||||||
mycpu="amd64" ;;
|
mycpu="amd64" ;;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue