device: remove some unnecessary unsafe

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2020-06-22 12:58:01 -07:00 committed by David Crawshaw
parent 3c41141fb4
commit 31b574ef99

View file

@ -7,8 +7,8 @@ package device
import ( import (
"crypto/rand" "crypto/rand"
"encoding/binary"
"sync" "sync"
"unsafe"
) )
type IndexTableEntry struct { type IndexTableEntry struct {
@ -25,7 +25,8 @@ type IndexTable struct {
func randUint32() (uint32, error) { func randUint32() (uint32, error) {
var integer [4]byte var integer [4]byte
_, err := rand.Read(integer[:]) _, err := rand.Read(integer[:])
return *(*uint32)(unsafe.Pointer(&integer[0])), err // Arbitrary endianness; both are intrinsified by the Go compiler.
return binary.LittleEndian.Uint32(integer[:]), err
} }
func (table *IndexTable) Init() { func (table *IndexTable) Init() {