An invalid pointer triggers a runtime failure when passed as argument in
Go1.7: runtime: bad pointer in frame github.com/kylelemons/gousb/usb.(*fakeLibusb).open at 0xc420045ce0: 0x1 fatal error: invalid stack pointer Use an arbitrary C-allocated pointer instead.
This commit is contained in:
@@ -19,7 +19,6 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -302,12 +301,12 @@ func newFakeLibusb() *fakeLibusb {
|
||||
handles: make(map[*libusbDevHandle]*libusbDevice),
|
||||
claims: make(map[*libusbDevice]map[uint8]bool),
|
||||
}
|
||||
for i, d := range fakeDevices {
|
||||
for _, d := range fakeDevices {
|
||||
// libusb does not export a way to allocate a new libusb_device struct
|
||||
// without using the full USB stack. Since the fake library uses the
|
||||
// libusbDevice only as an identifier, use arbitrary numbers pretending
|
||||
// to be pointers. The contents of these pointers is never accessed.
|
||||
fl.fakeDevices[(*libusbDevice)(unsafe.Pointer(uintptr(i)))] = &fakeDevice{
|
||||
// libusbDevice only as an identifier, use an arbitrary unique pointer.
|
||||
// The contents of these pointers is never accessed.
|
||||
fl.fakeDevices[(*libusbDevice)(newCPointer())] = &fakeDevice{
|
||||
desc: d,
|
||||
alt: 0,
|
||||
}
|
||||
|
@@ -421,7 +421,11 @@ func xfer_callback(cptr unsafe.Pointer) {
|
||||
close(ch)
|
||||
}
|
||||
|
||||
// for benchmarking
|
||||
// for benchmarking and testing
|
||||
func libusbSetDebug(c *libusbContext, lvl int) {
|
||||
C.libusb_set_debug((*C.libusb_context)(c), C.int(lvl))
|
||||
}
|
||||
|
||||
func newCPointer() unsafe.Pointer {
|
||||
return unsafe.Pointer(C.malloc(1))
|
||||
}
|
||||
|
Reference in New Issue
Block a user