mirror of
https://github.com/golang/go
synced 2024-11-23 06:20:07 -07:00
runtime: fix GOTRACEBACK on Plan 9
Getenv() should not call malloc when called from gotraceback(). Instead, we return a static buffer in this case, with enough room to hold the longest value. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/85680043
This commit is contained in:
parent
b69238bfbe
commit
a07f6adda8
@ -12,6 +12,7 @@ runtime·getenv(int8 *s)
|
||||
intgo len;
|
||||
byte file[128];
|
||||
byte *p;
|
||||
static byte b[128];
|
||||
|
||||
len = runtime·findnull((byte*)s);
|
||||
if(len > sizeof file-6)
|
||||
@ -25,6 +26,13 @@ runtime·getenv(int8 *s)
|
||||
if(fd < 0)
|
||||
return nil;
|
||||
n = runtime·seek(fd, 0, 2);
|
||||
if(runtime·strcmp((byte*)s, (byte*)"GOTRACEBACK") == 0){
|
||||
// should not call malloc
|
||||
if(n >= sizeof b)
|
||||
return nil;
|
||||
runtime·memclr(b, sizeof b);
|
||||
p = b;
|
||||
}else
|
||||
p = runtime·malloc(n+1);
|
||||
r = runtime·pread(fd, p, n, 0);
|
||||
runtime·close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user