From: Ian Lance Taylor Date: Fri, 21 Jan 2011 21:57:52 +0000 (-0800) Subject: net: Fix race condition in test. X-Git-Tag: weekly.2011-02-01~106 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9e441e52156d3b5c795083544745c53124c6df4e;p=gostls13.git net: Fix race condition in test. The test code used to do this: for _, tc := range tests { ch <- &tc } Note that &tc is always the same value here. As the value is received from the channel, the sender can loop around and change the contents of tc. This means that the receiver's value is unstable and can change while it is in use. R=adg, r2, rsc CC=chris, golang-dev https://golang.org/cl/3978043 --- diff --git a/src/pkg/net/dnsname_test.go b/src/pkg/net/dnsname_test.go index f4089c5db8..0c1a625189 100644 --- a/src/pkg/net/dnsname_test.go +++ b/src/pkg/net/dnsname_test.go @@ -27,7 +27,7 @@ var tests = []testCase{ {"a.b..com", false}, } -func getTestCases(ch chan<- *testCase) { +func getTestCases(ch chan<- testCase) { defer close(ch) var char59 = "" var char63 = "" @@ -39,17 +39,17 @@ func getTestCases(ch chan<- *testCase) { char64 = char63 + "a" for _, tc := range tests { - ch <- &tc + ch <- tc } - ch <- &testCase{char63 + ".com", true} - ch <- &testCase{char64 + ".com", false} + ch <- testCase{char63 + ".com", true} + ch <- testCase{char64 + ".com", false} // 255 char name is fine: - ch <- &testCase{char59 + "." + char63 + "." + char63 + "." + + ch <- testCase{char59 + "." + char63 + "." + char63 + "." + char63 + ".com", true} // 256 char name is bad: - ch <- &testCase{char59 + "a." + char63 + "." + char63 + "." + + ch <- testCase{char59 + "a." + char63 + "." + char63 + "." + char63 + ".com", false} } @@ -58,7 +58,7 @@ func TestDNSNames(t *testing.T) { if runtime.GOOS == "windows" { return } - ch := make(chan *testCase) + ch := make(chan testCase) go getTestCases(ch) for tc := range ch { if isDomainName(tc.name) != tc.result {