From 122a22e0e9eba7fe712030d429fc4bcf6f447f5e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 11 Nov 2022 12:42:51 -0800 Subject: [PATCH] internal/syscall/unix: use runtime.gostring for Gostring Under the race detector, checkptr flags uses of unsafe.Slice that result in slices that straddle multiple Go allocations. Avoid that scenario by calling existing runtime code. This fixes a failure on the darwin-.*-race builders introduced in CL 446178. Change-Id: I6e0fdb37e3c3f38d97939a8799bb4d10f519c5b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/449936 Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- src/internal/syscall/unix/net_darwin.go | 14 ++++---------- src/runtime/string.go | 7 +++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/internal/syscall/unix/net_darwin.go b/src/internal/syscall/unix/net_darwin.go index 9840359693..b9da4f1dc7 100644 --- a/src/internal/syscall/unix/net_darwin.go +++ b/src/internal/syscall/unix/net_darwin.go @@ -95,17 +95,11 @@ func GaiStrerror(ecode int) string { return GoString((*byte)(unsafe.Pointer(r1))) } +// Implemented in the runtime package. +func gostring(*byte) string + func GoString(p *byte) string { - if p == nil { - return "" - } - x := unsafe.Slice(p, 1e9) - for i, c := range x { - if c == 0 { - return string(x[:i]) - } - } - return "" + return gostring(p) } //go:linkname syscall_syscall syscall.syscall diff --git a/src/runtime/string.go b/src/runtime/string.go index eaade640c4..a00976be59 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -325,6 +325,13 @@ func gostring(p *byte) string { return s } +// internal_syscall_gostring is a version of gostring for internal/syscall/unix. +// +//go:linkname internal_syscall_gostring internal/syscall/unix.gostring +func internal_syscall_gostring(p *byte) string { + return gostring(p) +} + func gostringn(p *byte, l int) string { if l == 0 { return "" -- 2.50.0