From 80c74491450298bbb3159475cfbc50df9012817c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 25 Jun 2019 12:58:00 +1000 Subject: [PATCH] Plane: add sanity check when fetching GCS_MAVLink instance --- ArduPlane/GCS_Plane.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ArduPlane/GCS_Plane.h b/ArduPlane/GCS_Plane.h index 0338c58c70..e6cef69f8b 100644 --- a/ArduPlane/GCS_Plane.h +++ b/ArduPlane/GCS_Plane.h @@ -13,12 +13,20 @@ public: uint8_t num_gcs() const override { return ARRAY_SIZE(_chan); }; // return GCS link at offset ofs - GCS_MAVLINK_Plane &chan(const uint8_t ofs) override { + GCS_MAVLINK_Plane &chan(uint8_t ofs) override { + if (ofs >= num_gcs()) { + AP::internalerror().error(AP_InternalError::error_t::gcs_offset); + ofs = 0; + } return _chan[ofs]; - }; - const GCS_MAVLINK_Plane &chan(const uint8_t ofs) const override { + } + const GCS_MAVLINK_Plane &chan(uint8_t ofs) const override { + if (ofs >= num_gcs()) { + AP::internalerror().error(AP_InternalError::error_t::gcs_offset); + ofs = 0; + } return _chan[ofs]; - }; + } protected: