Skip to content

Commit dd950ed

Browse files
fix: use unsafe.Pointer directly in gralloc bridge FFI to satisfy go vet
Changed fnLock/fnLockYCbCr signatures from *uintptr to *unsafe.Pointer for output data pointers. This avoids the uintptr-to-unsafe.Pointer conversion that go vet flags as "possible misuse of unsafe.Pointer".
1 parent ccded32 commit dd950ed

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

gralloc/bridge/ffi.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type BufferHandle uintptr
2323
var (
2424
fnInit func() int32
2525
fnImport func(fds unsafe.Pointer, numFds int32, ints unsafe.Pointer, numInts int32) uintptr
26-
fnLock func(buffer uintptr, width, height int32, data *uintptr) int32
27-
fnLockYCbCr func(buffer uintptr, width, height int32, y, cb, cr *uintptr, yStride, cStride, chromaStep *uint32) int32
26+
fnLock func(buffer uintptr, width, height int32, data *unsafe.Pointer) int32
27+
fnLockYCbCr func(buffer uintptr, width, height int32, y, cb, cr *unsafe.Pointer, yStride, cStride, chromaStep *uint32) int32
2828
fnUnlock func(buffer uintptr)
2929
fnFree func(buffer uintptr)
3030
)
@@ -105,12 +105,12 @@ func ImportBuffer(fds []int32, ints []int32) (BufferHandle, error) {
105105
// LockGeneric locks a buffer for CPU read and copies the pixel data
106106
// into a Go byte slice. The buffer is unlocked before returning.
107107
func LockGeneric(h BufferHandle, width, height int32, bufSize int) ([]byte, error) {
108-
var dataPtr uintptr
108+
var dataPtr unsafe.Pointer
109109
if ret := fnLock(uintptr(h), width, height, &dataPtr); ret != 0 {
110110
return nil, fmt.Errorf("bridge_lock: error %d", ret)
111111
}
112112
result := make([]byte, bufSize)
113-
copy(result, unsafe.Slice((*byte)(unsafe.Pointer(dataPtr)), bufSize)) //nolint:govet // C bridge pointer
113+
copy(result, unsafe.Slice((*byte)(dataPtr), bufSize))
114114
fnUnlock(uintptr(h))
115115
return result, nil
116116
}
@@ -119,7 +119,7 @@ func LockGeneric(h BufferHandle, width, height int32, bufSize int) ([]byte, erro
119119
// planes (Y, Cb, Cr) into a Go byte slice. The buffer is unlocked
120120
// before returning.
121121
func LockYCbCr(h BufferHandle, width, height int32) ([]byte, error) {
122-
var yPtr, cbPtr, crPtr uintptr
122+
var yPtr, cbPtr, crPtr unsafe.Pointer
123123
var yStride, cStride, chromaStep uint32
124124
if ret := fnLockYCbCr(uintptr(h), width, height,
125125
&yPtr, &cbPtr, &crPtr,
@@ -134,12 +134,12 @@ func LockYCbCr(h BufferHandle, width, height int32) ([]byte, error) {
134134
crSize := int(cStride) * chromaHeight
135135

136136
result := make([]byte, ySize+cbSize+crSize)
137-
copy(result[:ySize], unsafe.Slice((*byte)(unsafe.Pointer(yPtr)), ySize)) //nolint:govet // C bridge pointer
138-
if cbPtr != 0 && cbSize > 0 {
139-
copy(result[ySize:ySize+cbSize], unsafe.Slice((*byte)(unsafe.Pointer(cbPtr)), cbSize)) //nolint:govet // C bridge pointer
137+
copy(result[:ySize], unsafe.Slice((*byte)(yPtr), ySize))
138+
if cbPtr != nil && cbSize > 0 {
139+
copy(result[ySize:ySize+cbSize], unsafe.Slice((*byte)(cbPtr), cbSize))
140140
}
141-
if crPtr != 0 && crSize > 0 {
142-
copy(result[ySize+cbSize:], unsafe.Slice((*byte)(unsafe.Pointer(crPtr)), crSize)) //nolint:govet // C bridge pointer
141+
if crPtr != nil && crSize > 0 {
142+
copy(result[ySize+cbSize:], unsafe.Slice((*byte)(crPtr), crSize))
143143
}
144144
fnUnlock(uintptr(h))
145145
return result, nil

0 commit comments

Comments
 (0)