mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
Fix issue #4001: invalid pragma {. hint[]: off .}
The bug was in processNote, module pragmas. The code assumed that
a nkBracketExpr AST node always had two children (without testing
this), and tried to access elements with index 0 and 1 in the sons
array of the nkBracketExpr node.
The code that triggered the bug was just {. hint[]: off .}
by itself in a module; in this case the nkBracketExpr has only
one children in the sons array, so the code in processNote caused
an out-of-bounds array access.
This commit also adds a test to guarantee that this pragma is
rejected, as is.
This commit is contained in:
@@ -277,6 +277,7 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) =
|
||||
proc processNote(c: PContext, n: PNode) =
|
||||
if (n.kind == nkExprColonExpr) and (sonsLen(n) == 2) and
|
||||
(n.sons[0].kind == nkBracketExpr) and
|
||||
(n.sons[0].sons.len == 2) and
|
||||
(n.sons[0].sons[1].kind == nkIdent) and
|
||||
(n.sons[0].sons[0].kind == nkIdent):
|
||||
#and (n.sons[1].kind == nkIdent):
|
||||
|
||||
6
tests/pragmas/thintoff.nim
Normal file
6
tests/pragmas/thintoff.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
# issue #4001
|
||||
discard """
|
||||
errormsg: "invalid pragma: hint[]: off"
|
||||
"""
|
||||
|
||||
{. hint[]: off .}
|
||||
Reference in New Issue
Block a user