Fix use of unsafe ptr #42444
Signed-off-by: Adam Williams <awilliams@mirantis.com>
This commit is contained in:
parent
2a562b1583
commit
9f0e268b00
1 changed files with 4 additions and 14 deletions
|
@ -8,9 +8,7 @@ import (
|
|||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
|
@ -294,19 +292,11 @@ func DriverTestChanges(t testing.TB, drivername string, driverOptions ...string)
|
|||
}
|
||||
|
||||
func writeRandomFile(path string, size uint64) error {
|
||||
buf := make([]int64, size/8)
|
||||
|
||||
r := rand.NewSource(0)
|
||||
for i := range buf {
|
||||
buf[i] = r.Int63()
|
||||
data := make([]byte, size)
|
||||
_, err := rand.Read(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Cast to []byte
|
||||
header := *(*reflect.SliceHeader)(unsafe.Pointer(&buf)) //nolint:govet // FIXME: unsafeptr: possible misuse of reflect.SliceHeader (govet) see https://github.com/moby/moby/issues/42444
|
||||
header.Len *= 8
|
||||
header.Cap *= 8
|
||||
data := *(*[]byte)(unsafe.Pointer(&header)) //nolint:govet // FIXME: unsafeptr: possible misuse of reflect.SliceHeader (govet) see https://github.com/moby/moby/issues/42444
|
||||
|
||||
return ioutil.WriteFile(path, data, 0700)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue