]> Cypherpunks repositories - gostls13.git/commit
go/token: Fix race in FileSet.PositionFor.
authorJan Mercl <0xjnml@gmail.com>
Tue, 2 Aug 2016 11:00:46 +0000 (13:00 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 16 Aug 2016 01:45:25 +0000 (01:45 +0000)
commit52fcff3ec147ea8ae48c023f3d5000a8bf42fe8c
tree4d881d57dcbca3efe33ea7e2e7029347bea9a662
parent14e446d909784fba7b349b76ec0a234c2a86a491
go/token: Fix race in FileSet.PositionFor.

Methods of FileSet are documented to be safe for concurrent use by
multiple goroutines, so FileSet is protected by a mutex and all its
methods use it to prevent concurrent mutations. All methods of File that
mutate the respective FileSet, including AddLine, do also lock its
mutex, but that does not help when PositionFor is invoked concurrently
and reads without synchronization what AddLine mutates.

The change adds acquiring a RLock around the racy call of File.position
and the respective test.

Fixes #16548

Change-Id: Iecaaa02630b2532cb29ab555376633ee862315dd
Reviewed-on: https://go-review.googlesource.com/25345
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/go/token/position.go
src/go/token/position_test.go