Commit 9d06cfc8 authored by David du Colombier's avatar David du Colombier

runtime: handle non-nil-terminated environment strings on Plan 9

Russ Cox pointed out that environment strings are not
required to be nil-terminated on Plan 9.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/159130044
parent 1946afb6
...@@ -30,7 +30,7 @@ func gogetenv(key string) string { ...@@ -30,7 +30,7 @@ func gogetenv(key string) string {
if fd < 0 { if fd < 0 {
return "" return ""
} }
n := seek(fd, 0, 2) - 1 n := seek(fd, 0, 2)
if n <= 0 { if n <= 0 {
close(fd) close(fd)
return "" return ""
...@@ -44,6 +44,10 @@ func gogetenv(key string) string { ...@@ -44,6 +44,10 @@ func gogetenv(key string) string {
return "" return ""
} }
if p[r-1] == 0 {
r--
}
var s string var s string
sp := (*_string)(unsafe.Pointer(&s)) sp := (*_string)(unsafe.Pointer(&s))
sp.str = &p[0] sp.str = &p[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment