Skip to content

Commit

Permalink
unix: use unsafe.Slice in anyToSockaddr
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tklauser authored and gopherbot committed Feb 28, 2023
1 parent c10701f commit a6bfb89
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 11 deletions.
4 changes: 1 addition & 3 deletions unix/syscall_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
break
}
}

bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
sa.Name = string(bytes)
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
return sa, nil

case AF_INET:
Expand Down
3 changes: 1 addition & 2 deletions unix/syscall_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
break
}
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
sa.Name = string(bytes)
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
return sa, nil

case AF_INET:
Expand Down
3 changes: 1 addition & 2 deletions unix/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
for n < len(pp.Path) && pp.Path[n] != 0 {
n++
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
sa.Name = string(bytes)
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
return sa, nil

case AF_INET:
Expand Down
3 changes: 1 addition & 2 deletions unix/syscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
for n < len(pp.Path) && pp.Path[n] != 0 {
n++
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
sa.Name = string(bytes)
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
return sa, nil

case AF_INET:
Expand Down
3 changes: 1 addition & 2 deletions unix/syscall_zos_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func anyToSockaddr(_ int, rsa *RawSockaddrAny) (Sockaddr, error) {
for n < int(pp.Len) && pp.Path[n] != 0 {
n++
}
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
sa.Name = string(bytes)
sa.Name = string(unsafe.Slice((*byte)(unsafe.Pointer(&pp.Path[0])), n))
return sa, nil

case AF_INET:
Expand Down

0 comments on commit a6bfb89

Please sign in to comment.