Skip to content

Commit

Permalink
Fix catch by value errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cvuchener committed May 10, 2019
1 parent 93fff51 commit d632b52
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/libhidpp/hidpp/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Device::Device (Dispatcher *dispatcher, DeviceIndex device_index):
nullptr);
_name = ireceiver.getDeviceName (device_index - 1);
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
if (e.errorCode () == HIDPP10::Error::InvalidValue) {
// the invalid value is the device index
throw HIDPP10::Error (HIDPP10::Error::UnknownDevice);
Expand All @@ -83,7 +83,7 @@ Device::Device (Dispatcher *dispatcher, DeviceIndex device_index):
auto params = report.parameterBegin ();
_version = std::make_tuple (params[0], params[1]);
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
// Valid HID++1.0 devices should send a "Invalid SubID" error.
if (e.errorCode () != HIDPP10::Error::InvalidSubID)
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/libhidpp/hidpp/DispatcherThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ void DispatcherThread::run ()
if (0 != _dev.readReport (raw_report))
processReport (std::move (raw_report));
}
catch (Report::InvalidReportID e) {
catch (Report::InvalidReportID &e) {
// There may be other reports on this device, just ignore them.
}
catch (Report::InvalidReportLength e) {
catch (Report::InvalidReportLength &e) {
Log::error () << "Ignored report with invalid length" << std::endl;
}
catch (std::exception &e) {
Expand Down
6 changes: 3 additions & 3 deletions src/libhidpp/hidpp/SimpleDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void SimpleDispatcher::listen ()
debug << "Ignored report while listening for events." << std::endl;
}
}
catch (Dispatcher::TimeoutError e) {
catch (Dispatcher::TimeoutError &e) {
// return when getReport is interrupted.
}
}
Expand All @@ -110,10 +110,10 @@ Report SimpleDispatcher::getReport (int timeout)
processEvent (report);
return report;
}
catch (Report::InvalidReportID e) {
catch (Report::InvalidReportID &e) {
// There may be other reports on this device, just ignore them.
}
catch (Report::InvalidReportLength e) {
catch (Report::InvalidReportLength &e) {
Log::error () << "Ignored report with invalid length" << std::endl;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/hidpp-check-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ int main (int argc, char *argv[])
return EXIT_FAILURE;
}
}
catch (HIDPP::Dispatcher::NoHIDPPReportException e) {
catch (HIDPP::Dispatcher::NoHIDPPReportException &e) {
Log::info () << "Device is not a HID++ device" << std::endl;
return EXIT_FAILURE;
}
catch (std::system_error e) {
catch (std::system_error &e) {
fprintf (stderr, "Failed to open %s: %s\n", path, e.what ());
return EXIT_FAILURE;
}
Expand Down
10 changes: 5 additions & 5 deletions src/tools/hidpp-list-devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ class DevicePrinter: public HID::DeviceMonitor
if (index == HIDPP::DefaultDevice && version == std::make_tuple (1, 0))
has_receiver_index = true;
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
if (e.errorCode () != HIDPP10::Error::UnknownDevice && e.errorCode () != HIDPP10::Error::InvalidSubID) {
Log::error ().printf ("Error while querying %s wireless device %d: %s\n",
path, index, e.what ());
}
}
catch (HIDPP20::Error e) {
catch (HIDPP20::Error &e) {
if (e.errorCode () != HIDPP20::Error::UnknownDevice) {
Log::error ().printf ("Error while querying %s device %d: %s\n",
path, index, e.what ());
}
}
catch (HIDPP::Dispatcher::TimeoutError e) {
catch (HIDPP::Dispatcher::TimeoutError &e) {
Log::warning ().printf ("Device %s (index %d) timed out\n",
path, index);
}
}

}
catch (HIDPP::Dispatcher::NoHIDPPReportException e) {
catch (HIDPP::Dispatcher::NoHIDPPReportException &e) {
}
catch (std::system_error e) {
catch (std::system_error &e) {
Log::warning ().printf ("Failed to open %s: %s\n", path, e.what ());
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/tools/hidpp-list-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void testRegister (HIDPP10::Device *dev, std::size_t register_size, uint8_t addr
printf (" %02hhx", value);
printf ("\n");
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
if (e.errorCode () != HIDPP10::Error::InvalidSubID &&
e.errorCode () != HIDPP10::Error::InvalidAddress) {
printf ("Register 0x%02hhx read %2lu: %s (0x%02hhx)\n",
Expand All @@ -127,14 +127,14 @@ void testRegister (HIDPP10::Device *dev, std::size_t register_size, uint8_t addr
printf (" %02hhx", value);
printf ("\n");
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
if (e.errorCode () != HIDPP10::Error::InvalidSubID &&
e.errorCode () != HIDPP10::Error::InvalidAddress) {
printf ("Register 0x%02hhx write %2lu: %s (0x%02hhx)\n",
address, register_size, e.what (), e.errorCode ());
}
}
catch (std::system_error e) {
catch (std::system_error &e) {
/* G5 does not support long writes and throw EPIPE */
if (e.code ().value () != EPIPE) {
throw e;
Expand Down Expand Up @@ -178,11 +178,11 @@ int main (int argc, char *argv[])
try {
dispatcher = std::make_unique<HIDPP::SimpleDispatcher> (path);
}
catch (HIDPP::Dispatcher::NoHIDPPReportException e) {
catch (HIDPP::Dispatcher::NoHIDPPReportException &e) {
printf ("%s is not a HID++ device\n", path);
return EXIT_FAILURE;
}
catch (std::system_error e) {
catch (std::system_error &e) {
fprintf (stderr, "Failed to open %s: %s\n", path, e.what ());
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -242,7 +242,7 @@ int main (int argc, char *argv[])
printf (" - LED Control\n");
}
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
printf ("Individual features: %s\n", e.what ());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp10-raw-command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int main (int argc, char *argv[])
params, &results);
}
}
catch (HIDPP10::Error e) {
catch (HIDPP10::Error &e) {
fprintf (stderr, "%s\n", e.what ());
return e.errorCode ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp20-call-function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main (int argc, char *argv[])
static_cast<unsigned int> (function),
params);
}
catch (HIDPP20::Error e) {
catch (HIDPP20::Error &e) {
fprintf (stderr, "Error code %d: %s\n", e.errorCode (), e.what ());
return e.errorCode ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp20-dump-page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main (int argc, char *argv[])
i += data.size ();
}
}
catch (HIDPP20::Error e) {
catch (HIDPP20::Error &e) {
fprintf (stderr, "HID++2 error %d: %s\n", e.errorCode (), e.what ());
return e.errorCode ();
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/hidpp20-mouse-event-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ int main (int argc, char *argv[])
try {
listener->addEventHandler (std::make_unique<ButtonHandler> (dev.get ()));
}
catch (HIDPP20::UnsupportedFeature e) {
catch (HIDPP20::UnsupportedFeature &e) {
printf ("%s\n", e.what ());
}
try {
listener->addEventHandler (std::make_unique<ProfileHandler> (dev.get ()));
}
catch (HIDPP20::UnsupportedFeature e) {
catch (HIDPP20::UnsupportedFeature &e) {
printf ("%s\n", e.what ());
}
listener->start();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp20-onboard-profiles-get-description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main (int argc, char *argv[])
}
printf (")\n");
}
catch (HIDPP20::Error e) {
catch (HIDPP20::Error &e) {
fprintf (stderr, "Error code %d: %s\n", e.errorCode (), e.what ());
return e.errorCode ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp20-reprog-controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int main (int argc, char *argv[])
return EXIT_FAILURE;
}
}
catch (Error e) {
catch (Error &e) {
fprintf (stderr, "Error code %d: %s\n", e.errorCode (), e.what ());
return e.errorCode ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp20-write-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main (int argc, char *argv[])

iop.memoryWriteEnd ();
}
catch (HIDPP20::Error e) {
catch (HIDPP20::Error &e) {
fprintf (stderr, "Error while writing data: %s (%d).\n", e.what (), e.errorCode ());
return e.errorCode ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hidpp20-write-page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main (int argc, char *argv[])
try {
iop.memoryWriteEnd ();
}
catch (HIDPP20::Error e) {
catch (HIDPP20::Error &e) {
if (e.errorCode () == HIDPP20::Error::HWError) {
fprintf (stderr, "memoryWriteEnd returned Hardware Error, maybe the CRC in wrong but the page is actually written.\n");
}
Expand Down

0 comments on commit d632b52

Please sign in to comment.