Verify that interface and alternate numbers are 0-based indices, we rely
on this assumption in the config.
This commit is contained in:
@@ -228,7 +228,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
||||
Cap: int(cfg.bNumInterfaces),
|
||||
}
|
||||
c.Interfaces = make([]InterfaceInfo, 0, len(ifaces))
|
||||
for _, iface := range ifaces {
|
||||
for ifNum, iface := range ifaces {
|
||||
if iface.num_altsetting == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
||||
Cap: int(iface.num_altsetting),
|
||||
}
|
||||
descs := make([]InterfaceSetting, 0, len(alts))
|
||||
for _, alt := range alts {
|
||||
for altNum, alt := range alts {
|
||||
i := InterfaceSetting{
|
||||
Number: int(alt.bInterfaceNumber),
|
||||
Alternate: int(alt.bAlternateSetting),
|
||||
@@ -248,6 +248,12 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
||||
SubClass: Class(alt.bInterfaceSubClass),
|
||||
Protocol: Protocol(alt.bInterfaceProtocol),
|
||||
}
|
||||
if ifNum != i.Number {
|
||||
return nil, fmt.Errorf("config %d interface at index %d has number %d, USB standard states they should be identical", c.Config, ifNum, i.Number)
|
||||
}
|
||||
if altNum != i.Alternate {
|
||||
return nil, fmt.Errorf("config %d interface %d alternate settings at index %d has number %d, USB standard states they should be identical", c.Config, i.Number, altNum, i.Alternate)
|
||||
}
|
||||
var ends []C.struct_libusb_endpoint_descriptor
|
||||
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
|
||||
Data: uintptr(unsafe.Pointer(alt.endpoint)),
|
||||
|
Reference in New Issue
Block a user