From eea6b4c9b925a3d7565a100760aff44720b114f3 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Wed, 11 Nov 2020 12:03:51 +0530 Subject: [PATCH] AP_HAL_SITL: handle uninitialised file descriptor --- libraries/AP_HAL_SITL/CANSocketIface.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/AP_HAL_SITL/CANSocketIface.cpp b/libraries/AP_HAL_SITL/CANSocketIface.cpp index d9b04ef6f0..602eb7b784 100644 --- a/libraries/AP_HAL_SITL/CANSocketIface.cpp +++ b/libraries/AP_HAL_SITL/CANSocketIface.cpp @@ -323,6 +323,9 @@ bool CANIface::_pollRead() int CANIface::_write(const AP_HAL::CANFrame& frame) const { + if (_fd < 0) { + return -1; + } errno = 0; const can_frame sockcan_frame = makeSocketCanFrame(frame); @@ -343,6 +346,9 @@ int CANIface::_write(const AP_HAL::CANFrame& frame) const int CANIface::_read(AP_HAL::CANFrame& frame, uint64_t& timestamp_us, bool& loopback) const { + if (_fd < 0) { + return -1; + } auto iov = iovec(); auto sockcan_frame = can_frame(); iov.iov_base = &sockcan_frame;