Skip to content

Commit db9e549

Browse files
cuiweixiegopherbot
authored andcommitted
crypto/x509/internal/macos: simplify code using unsafe.{SliceData,StringData}
Updates #54854 Change-Id: I8a64a1176cbe16489e1fd21c66a7abc7d8b8e9b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/428154 Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent ccf82d5 commit db9e549

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/crypto/x509/internal/macos/corefoundation.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ package macOS
1212
import (
1313
"errors"
1414
"internal/abi"
15-
"reflect"
1615
"runtime"
1716
"time"
1817
"unsafe"
@@ -64,7 +63,7 @@ const kCFStringEncodingUTF8 = 0x08000100
6463
//go:cgo_import_dynamic x509_CFDataCreate CFDataCreate "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
6564

6665
func BytesToCFData(b []byte) CFRef {
67-
p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&b)).Data)
66+
p := unsafe.Pointer(unsafe.SliceData(b))
6867
ret := syscall(abi.FuncPCABI0(x509_CFDataCreate_trampoline), kCFAllocatorDefault, uintptr(p), uintptr(len(b)), 0, 0, 0)
6968
runtime.KeepAlive(p)
7069
return CFRef(ret)
@@ -75,7 +74,7 @@ func x509_CFDataCreate_trampoline()
7574

7675
// StringToCFString returns a copy of the UTF-8 contents of s as a new CFString.
7776
func StringToCFString(s string) CFString {
78-
p := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data)
77+
p := unsafe.Pointer(unsafe.StringData(s))
7978
ret := syscall(abi.FuncPCABI0(x509_CFStringCreateWithBytes_trampoline), kCFAllocatorDefault, uintptr(p),
8079
uintptr(len(s)), uintptr(kCFStringEncodingUTF8), 0 /* isExternalRepresentation */, 0)
8180
runtime.KeepAlive(p)

0 commit comments

Comments
 (0)