internal/lsp/source: fix nil pointer in extract function
Ran into this while debugging another issue.
Change-Id: I154493418c7676a24457a4e11431ad4f0311c07a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/246757
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Baum <joshbaum@google.com>
diff --git a/internal/lsp/source/extract.go b/internal/lsp/source/extract.go
index 4725572..6cac9a3 100644
--- a/internal/lsp/source/extract.go
+++ b/internal/lsp/source/extract.go
@@ -477,8 +477,8 @@
rng.Start = tok.Pos(offset)
offset = tok.Offset(rng.End)
- for offset-1 >= 0 {
- if !unicode.IsSpace(rune(content[offset-1])) {
+ for o := offset - 1; 0 <= o && o < len(content); {
+ if !unicode.IsSpace(rune(content[o])) {
break
}
// Move backwards one byte to find a non-whitespace character.