bugst / go-serial

A cross-platform serial library for go-lang.
BSD 3-Clause "New" or "Revised" License
618 stars 188 forks source link

Enumerator panics on windows when removing a device mid enumeration #138

Closed advisoft closed 1 year ago

advisoft commented 2 years ago

panic: runtime error: index out of range [0] with length 0

goroutine 883 [running]:\ngo.bug.st/serial/enumerator.retrievePortDetailsFromDevInfo(0xc00011f3b0, 0xc000121560, 0x5, 0x0)
/go/pkg/mod/go.bug.st/serial@v1.3.5/enumerator/usb_windows.go:351 +0x365
go.bug.st/serial/enumerator.nativeGetDetailedPortsList(0x0, 0x0, 0x0, 0x0, 0x0)
/go/pkg/mod/go.bug.st/serial@v1.3.5/enumerator/usb_windows.go:299 +0x1b1
go.bug.st/serial/enumerator.GetDetailedPortsList(...)
/go/pkg/mod/go.bug.st/serial@v1.3.5/enumerator/enumerator.go:31

I suspect N needs a zero check on line 350: image

per1234 commented 1 year ago

We have received multiple reports of this panic from users of the serial-discovery tool (via Arduino CLI + Arduino IDE):