Skip to content

Commit 44238f2

Browse files
committed
Fix go vet issue 'possible misuse of reflect.SliceHeader'
1 parent f0971a3 commit 44238f2

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

sqlite3_opt_serialize.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ func (c *SQLiteConn) Serialize(schema string) ([]byte, error) {
4242
return nil, fmt.Errorf("serialized database is too large (%d bytes)", sz)
4343
}
4444

45-
cBuf := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
46-
Data: uintptr(unsafe.Pointer(ptr)),
47-
Len: int(sz),
48-
Cap: int(sz),
49-
}))
45+
cBuf := make([]byte, int(sz))
46+
sh := (*reflect.SliceHeader)(unsafe.Pointer(&cBuf))
47+
sh.Data = uintptr(unsafe.Pointer(ptr))
5048

5149
res := make([]byte, int(sz))
5250
copy(res, cBuf)
@@ -65,12 +63,11 @@ func (c *SQLiteConn) Deserialize(b []byte, schema string) error {
6563
zSchema = C.CString(schema)
6664
defer C.free(unsafe.Pointer(zSchema))
6765

66+
6867
tmpBuf := (*C.uchar)(C.sqlite3_malloc64(C.sqlite3_uint64(len(b))))
69-
cBuf := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
70-
Data: uintptr(unsafe.Pointer(tmpBuf)),
71-
Len: len(b),
72-
Cap: len(b),
73-
}))
68+
cBuf := make([]byte, len(b))
69+
sh := (*reflect.SliceHeader)(unsafe.Pointer(&cBuf))
70+
sh.Data = uintptr(unsafe.Pointer(tmpBuf))
7471
copy(cBuf, b)
7572

7673
rc := C.sqlite3_deserialize(c.db, zSchema, tmpBuf, C.sqlite3_int64(len(b)),

0 commit comments

Comments
 (0)