Do not assume interface numbers follow the slice indices. (#134)

Do not assume interface numbers follow the slice indices.

This is a continuation of
9ad54830f4
which tried to solve the problem of non-contiguous interface indices;
this commit modifies another code path that had the same assumption.
This commit is contained in:
Sebastian Zagrodzki
2024-09-13 20:43:01 +02:00
committed by GitHub
parent 606016adee
commit e840be9d06
4 changed files with 91 additions and 22 deletions

View File

@@ -29,6 +29,17 @@ type InterfaceDesc struct {
AltSettings []InterfaceSetting
}
func (i *InterfaceDesc) altSetting(alt int) (*InterfaceSetting, error) {
alts := make([]int, len(i.AltSettings))
for a, s := range i.AltSettings {
if s.Alternate == alt {
return &s, nil
}
alts[a] = s.Alternate
}
return nil, fmt.Errorf("alternate setting %d not found for %s, available alt settings: %v", alt, i, alts)
}
// String returns a human-readable description of the interface descriptor and
// its alternate settings.
func (i InterfaceDesc) String() string {