aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2011-07-12 01:21:06 -0400
committerRuss Cox <rsc@golang.org>2011-07-12 01:21:06 -0400
commitf9f21aa1fb45aaa4eece55f192783bfa46df4909 (patch)
treed9733196177d563754392a1cf4a62e4ea4167585 /src/pkg/runtime
parent8ed9fc600c7dc6a9286a6f04bdb41694d53bac3c (diff)
downloadgo-f9f21aa1fb45aaa4eece55f192783bfa46df4909.tar.xz
runtime: fix data race on runtime·maxstring
The data race can lead to erroneous output of "[invalid string]" instead of a string. R=golang-dev CC=golang-dev https://golang.org/cl/4678049
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/print.c2
-rw-r--r--src/pkg/runtime/string.goc10
2 files changed, 8 insertions, 4 deletions
diff --git a/src/pkg/runtime/print.c b/src/pkg/runtime/print.c
index b8069aa393..3ce7794957 100644
--- a/src/pkg/runtime/print.c
+++ b/src/pkg/runtime/print.c
@@ -320,7 +320,7 @@ runtime·printpointer(void *p)
void
runtime·printstring(String v)
{
- extern int32 runtime·maxstring;
+ extern uint32 runtime·maxstring;
if(v.len > runtime·maxstring) {
runtime·write(2, "[invalid string]", 16);
diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc
index b72aa937c3..15b3459ada 100644
--- a/src/pkg/runtime/string.goc
+++ b/src/pkg/runtime/string.goc
@@ -32,19 +32,23 @@ runtime·findnullw(uint16 *s)
return l;
}
-int32 runtime·maxstring = 256;
+uint32 runtime·maxstring = 256;
String
runtime·gostringsize(int32 l)
{
String s;
+ uint32 ms;
if(l == 0)
return runtime·emptystring;
s.str = runtime·mal(l+1); // leave room for NUL for C runtime (e.g., callers of getenv)
s.len = l;
- if(l > runtime·maxstring)
- runtime·maxstring = l;
+ for(;;) {
+ ms = runtime·maxstring;
+ if((uint32)l <= ms || runtime·cas(&runtime·maxstring, ms, (uint32)l))
+ break;
+ }
return s;
}