Skip to content

Commit

Permalink
updateDiffSync(): fix potential race
Browse files Browse the repository at this point in the history
updateDiffSync() may called asynchronously, so it should lock the
line array when calling Bytes(), to prevent race if the line array is
being modified by the main goroutine in the meantime.
  • Loading branch information
dmaluka committed May 12, 2024
1 parent bca35a5 commit f65afa9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,12 @@ func (b *Buffer) updateDiffSync() {
}

differ := dmp.New()
baseRunes, bufferRunes, _ := differ.DiffLinesToRunes(string(b.diffBase), string(b.Bytes()))

b.Lock()
bytes := b.Bytes()
b.Unlock()

baseRunes, bufferRunes, _ := differ.DiffLinesToRunes(string(b.diffBase), string(bytes))
diffs := differ.DiffMainRunes(baseRunes, bufferRunes, false)
lineN := 0

Expand Down

0 comments on commit f65afa9

Please sign in to comment.