From 80cf8edc3137bae5b0117a60a327782af632a6cb Mon Sep 17 00:00:00 2001 From: Benjamin Koch Date: Sat, 2 Jul 2022 17:03:31 +0200 Subject: [PATCH] cmsisDAP: fix crash in case hid device cannot be opened --- src/cmsisDAP.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmsisDAP.cpp b/src/cmsisDAP.cpp index e272a43..4078e05 100644 --- a/src/cmsisDAP.cpp +++ b/src/cmsisDAP.cpp @@ -144,6 +144,10 @@ CmsisDAP::CmsisDAP(int vid, int pid, uint8_t verbose):_verbose(verbose), _serial_number = wstring(dev_found[_device_idx]->serial_number); /* open the device */ _dev = hid_open_path(dev_found[_device_idx]->path); + if (!_dev) { + throw std::runtime_error( + std::string("Couldn't open device. Check permissions for ") + dev_found[_device_idx]->path); + } /* cleanup enumeration */ hid_free_enumeration(devs);