Merge pull request #770 from peco/fix-filtered-buffer-bounds

add negative index check to FilteredBuffer.LineAt
This commit is contained in:
lestrrat 2026-02-20 22:52:56 +09:00 committed by GitHub
commit 4e58dad08a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,7 +94,7 @@ func (flb *FilteredBuffer) MaxColumn() int {
// in this filtered buffer may actually correspond to a totally // in this filtered buffer may actually correspond to a totally
// different line number in the source buffer. // different line number in the source buffer.
func (flb FilteredBuffer) LineAt(i int) (line.Line, error) { func (flb FilteredBuffer) LineAt(i int) (line.Line, error) {
if i >= len(flb.selection) { if i < 0 || i >= len(flb.selection) {
return nil, fmt.Errorf("specified index %d is out of range", len(flb.selection)) return nil, fmt.Errorf("specified index %d is out of range", len(flb.selection))
} }
return flb.src.LineAt(flb.selection[i]) return flb.src.LineAt(flb.selection[i])