]> Cypherpunks repositories - gostls13.git/commitdiff
internal/syscall/unix: use runtime.gostring for Gostring
authorIan Lance Taylor <iant@golang.org>
Fri, 11 Nov 2022 20:42:51 +0000 (12:42 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 11 Nov 2022 23:24:12 +0000 (23:24 +0000)
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 <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>

src/internal/syscall/unix/net_darwin.go
src/runtime/string.go

index 98403596938641ec65794d547dd8f24d916d58dc..b9da4f1dc75bfdf3de93c4d57be68b26c33e8cd3 100644 (file)
@@ -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
index eaade640c411dd42a94a5becc027a394fc05173f..a00976be59b974d42845a3b06596ea05435f765f 100644 (file)
@@ -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 ""