fixes nim-lang/nimsuggest#76 (#10093)
* nimsuggest: prevent out-of-bound access * fixes nim-lang/nimsuggest#76 * undo tester changes
This commit is contained in:
parent
5f2b66751a
commit
58d293d6a9
3 changed files with 41 additions and 3 deletions
|
|
@ -315,7 +315,17 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
|
||||||
result = semIdentWithPragma(c, kind, n, {})
|
result = semIdentWithPragma(c, kind, n, {})
|
||||||
if result.owner.kind == skModule:
|
if result.owner.kind == skModule:
|
||||||
incl(result.flags, sfGlobal)
|
incl(result.flags, sfGlobal)
|
||||||
suggestSym(c.config, n.info, result, c.graph.usageSym)
|
let info = case n.kind
|
||||||
|
of nkPostfix:
|
||||||
|
n.sons[1].info
|
||||||
|
of nkPragmaExpr:
|
||||||
|
if n.sons[0].kind == nkPostfix:
|
||||||
|
n.sons[0].sons[1].info
|
||||||
|
else:
|
||||||
|
n.sons[0].info
|
||||||
|
else:
|
||||||
|
n.info
|
||||||
|
suggestSym(c.config, info, result, c.graph.usageSym)
|
||||||
|
|
||||||
proc checkNilable(c: PContext; v: PSym) =
|
proc checkNilable(c: PContext; v: PSym) =
|
||||||
if {sfGlobal, sfImportC} * v.flags == {sfGlobal} and
|
if {sfGlobal, sfImportC} * v.flags == {sfGlobal} and
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ type
|
||||||
proc parseQuoted(cmd: string; outp: var string; start: int): int =
|
proc parseQuoted(cmd: string; outp: var string; start: int): int =
|
||||||
var i = start
|
var i = start
|
||||||
i += skipWhitespace(cmd, i)
|
i += skipWhitespace(cmd, i)
|
||||||
if cmd[i] == '"':
|
if i < cmd.len and cmd[i] == '"':
|
||||||
i += parseUntil(cmd, outp, '"', i+1)+2
|
i += parseUntil(cmd, outp, '"', i+1)+2
|
||||||
else:
|
else:
|
||||||
i += parseUntil(cmd, outp, seps, i)
|
i += parseUntil(cmd, outp, seps, i)
|
||||||
|
|
@ -428,7 +428,7 @@ proc execCmd(cmd: string; graph: ModuleGraph; cachedMsgs: CachedMsgs) =
|
||||||
var dirtyfile = ""
|
var dirtyfile = ""
|
||||||
var orig = ""
|
var orig = ""
|
||||||
i = parseQuoted(cmd, orig, i)
|
i = parseQuoted(cmd, orig, i)
|
||||||
if cmd[i] == ';':
|
if i < cmd.len and cmd[i] == ';':
|
||||||
i = parseQuoted(cmd, dirtyfile, i+1)
|
i = parseQuoted(cmd, dirtyfile, i+1)
|
||||||
i += skipWhile(cmd, seps, i)
|
i += skipWhile(cmd, seps, i)
|
||||||
var line = -1
|
var line = -1
|
||||||
|
|
|
||||||
28
nimsuggest/tests/ttype_highlight.nim
Normal file
28
nimsuggest/tests/ttype_highlight.nim
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
type
|
||||||
|
TypeA = int
|
||||||
|
TypeB* = int
|
||||||
|
TypeC {.unchecked.} = array[1, int]
|
||||||
|
TypeD[T] = T
|
||||||
|
TypeE* {.unchecked.} = array[0, int]#[!]#
|
||||||
|
|
||||||
|
discard """
|
||||||
|
disabled:true
|
||||||
|
$nimsuggest --tester $file
|
||||||
|
>highlight $1
|
||||||
|
highlight;;skType;;2;;2;;5
|
||||||
|
highlight;;skType;;3;;2;;5
|
||||||
|
highlight;;skType;;4;;2;;5
|
||||||
|
highlight;;skType;;5;;2;;5
|
||||||
|
highlight;;skType;;6;;2;;5
|
||||||
|
highlight;;skType;;2;;10;;3
|
||||||
|
highlight;;skType;;3;;11;;3
|
||||||
|
highlight;;skType;;4;;24;;5
|
||||||
|
highlight;;skType;;4;;33;;3
|
||||||
|
highlight;;skType;;5;;13;;1
|
||||||
|
highlight;;skType;;6;;25;;5
|
||||||
|
highlight;;skType;;6;;34;;3
|
||||||
|
highlight;;skType;;2;;10;;3
|
||||||
|
highlight;;skType;;3;;11;;3
|
||||||
|
highlight;;skType;;4;;33;;3
|
||||||
|
highlight;;skType;;6;;34;;3
|
||||||
|
"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue