mirror of
https://github.com/golang/go
synced 2024-11-19 13:14:42 -07:00
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
This commit is contained in:
parent
8ed9fc600c
commit
f9f21aa1fb
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user