Skip to content

Commit a6bfb89

Browse files
tklausergopherbot
authored andcommitted
unix: use unsafe.Slice in anyToSockaddr
Same as CL 471436 did in package syscall. Change-Id: Ic3f3a5ebb7ebe0cc7b6bbf377dd993cdbeaaa961 Reviewed-on: https://go-review.googlesource.com/c/sys/+/472015 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent c10701f commit a6bfb89

File tree

5 files changed

+5
-11
lines changed

5 files changed

+5
-11
lines changed

unix/syscall_aix.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
292292
break
293293
}
294294
}
295-
296-
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
297-
sa.Name = string(bytes)
295+
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
298296
return sa, nil
299297

300298
case AF_INET:

unix/syscall_bsd.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
245245
break
246246
}
247247
}
248-
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
249-
sa.Name = string(bytes)
248+
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
250249
return sa, nil
251250

252251
case AF_INET:

unix/syscall_linux.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
10151015
for n < len(pp.Path) && pp.Path[n] != 0 {
10161016
n++
10171017
}
1018-
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
1019-
sa.Name = string(bytes)
1018+
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
10201019
return sa, nil
10211020

10221021
case AF_INET:

unix/syscall_solaris.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
408408
for n < len(pp.Path) && pp.Path[n] != 0 {
409409
n++
410410
}
411-
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
412-
sa.Name = string(bytes)
411+
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
413412
return sa, nil
414413

415414
case AF_INET:

unix/syscall_zos_s390x.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ func anyToSockaddr(_ int, rsa *RawSockaddrAny) (Sockaddr, error) {
139139
for n < int(pp.Len) && pp.Path[n] != 0 {
140140
n++
141141
}
142-
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
143-
sa.Name = string(bytes)
142+
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
144143
return sa, nil
145144

146145
case AF_INET:

0 commit comments

Comments
 (0)