From f8baf29b6ef2fd268e460449fc591532b72fa22f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 29 Feb 2024 17:18:33 +0200 Subject: [PATCH] lib/fs: use unsafe.Slice instead of deprecated reflect.SliceHeader --- lib/fs/fs_windows.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/fs/fs_windows.go b/lib/fs/fs_windows.go index af2076afd..c28e1bce7 100644 --- a/lib/fs/fs_windows.go +++ b/lib/fs/fs_windows.go @@ -89,11 +89,7 @@ func mmap(fd int, length int) ([]byte, error) { windows.CloseHandle(h) return nil, os.NewSyscallError("MapViewOfFile", errno) } - data := make([]byte, 0) - hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data)) - hdr.Data = addr - hdr.Len = length - hdr.Cap = hdr.Len + data := unsafe.Slice(addr, length) mmapByAddrLock.Lock() mmapByAddr[addr] = h @@ -105,8 +101,7 @@ func mmap(fd int, length int) ([]byte, error) { func mUnmap(data []byte) error { // flush is not needed, since we perform only reading operation. // In case of write, additional call FlushViewOfFile must be performed. - header := (*reflect.SliceHeader)(unsafe.Pointer(&data)) - addr := header.Data + addr := uintptr(unsafe.Pointer(&data[0])) mmapByAddrLock.Lock() h, ok := mmapByAddr[addr]