internal/lsp: add an additional check to ToUTF16Column
This change will at least stop the panic from occurring. Updates golang/go#31341 Change-Id: I6b06941cfb6c020d2b37813573cb0dc068d54e65 Reviewed-on: https://go-review.googlesource.com/c/tools/+/172667 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
4796d4bd3d
commit
f939817187
|
@ -35,9 +35,14 @@ func ToUTF16Column(p Point, content []byte) (int, error) {
|
|||
if lineOffset < 0 || offset > len(content) {
|
||||
return -1, fmt.Errorf("ToUTF16Column: offsets %v-%v outside file contents (%v)", lineOffset, offset, len(content))
|
||||
}
|
||||
// use the offset to pick out the line start
|
||||
// Use the offset to pick out the line start.
|
||||
// This cannot panic: offset > len(content) and lineOffset < offset.
|
||||
start := content[lineOffset:]
|
||||
// now truncate down to the supplied column
|
||||
|
||||
// Now, truncate down to the supplied column.
|
||||
if col >= len(start) {
|
||||
return -1, fmt.Errorf("ToUTF16Column: line (%v) is shorter than column (%v)", len(start), col)
|
||||
}
|
||||
start = start[:col]
|
||||
// and count the number of utf16 characters
|
||||
// in theory we could do this by hand more efficiently...
|
||||
|
|
Loading…
Reference in New Issue