Skip to content

Commit acb0d76

Browse files
authored
ReHighlightStates: sanity-check startline value (zyedidia#3237)
Check if startline value is valid before passing it to input.State(), to prevent a theoretically possible race when the number of lines changes in the meantime, causing an out of bounds access. Actually this race cannot happen: ReHighlightStates() is only called from the main goroutine, and the line array is modified, again, only by the main goroutine. So for now this change is rather cosmetic: it is just to make the highligher API implementation self-sufficiently safe without assumptions about which goroutines are using which API functions and how.
1 parent d1d38d1 commit acb0d76

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/highlight/highlighter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
363363
h.lastRegion = nil
364364
if startline > 0 {
365365
input.Lock()
366-
h.lastRegion = input.State(startline - 1)
366+
if startline-1 < input.LinesNum() {
367+
h.lastRegion = input.State(startline - 1)
368+
}
367369
input.Unlock()
368370
}
369371
for i := startline; ; i++ {

0 commit comments

Comments
 (0)