diff --git a/swri_serial_util/src/serial_port.cpp b/swri_serial_util/src/serial_port.cpp index 184a40e08..e7eff3490 100644 --- a/swri_serial_util/src/serial_port.cpp +++ b/swri_serial_util/src/serial_port.cpp @@ -305,6 +305,11 @@ namespace swri_serial_util { int bytes; ioctl(fd_, FIONREAD, &bytes); + if (bytes < 0) + { + error_msg_ = "Error getting number of available bytes from serial port: " + std::string(strerror(errno)); + return ERROR; + } to_read = static_cast(bytes); }