Skip to content

Commit db89b5a

Browse files
committed
internal/lsp: handle nil pointer in fixInitStmt
I'm going to make a follow-up CL to create a source.Offset function that will always check inRange, and we should use that everywhere instead of token.Offset, which is pretty prone to panicking. Fixes golang/go#48763 Change-Id: Ia81309400d15a28c133f4b3d41c6239231c2532d Reviewed-on: https://go-review.googlesource.com/c/tools/+/353889 Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent ccaa907 commit db89b5a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/lsp/cache/parse.go

+4
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ func fixInitStmt(bad *ast.BadExpr, parent ast.Node, tok *token.File, src []byte)
995995
}
996996

997997
// Try to extract a statement from the BadExpr.
998+
// Make sure that the positions are in range first.
999+
if !source.InRange(tok, bad.Pos()) || !source.InRange(tok, bad.End()-1) {
1000+
return
1001+
}
9981002
stmtBytes := src[tok.Offset(bad.Pos()) : tok.Offset(bad.End()-1)+1]
9991003
stmt, err := parseStmt(bad.Pos(), stmtBytes)
10001004
if err != nil {

0 commit comments

Comments
 (0)