From fab17ba3bfaeb34391c41fefed80fc2740c423c1 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 25 Jun 2019 12:57:45 +1000 Subject: [PATCH] Copter: add sanity check when fetching GCS_MAVLink instance --- ArduCopter/GCS_Copter.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ArduCopter/GCS_Copter.h b/ArduCopter/GCS_Copter.h index 1ecc1d531d..5a899aa9fd 100644 --- a/ArduCopter/GCS_Copter.h +++ b/ArduCopter/GCS_Copter.h @@ -13,12 +13,20 @@ public: uint8_t num_gcs() const override { return ARRAY_SIZE(_chan); }; // return GCS link at offset ofs - GCS_MAVLINK_Copter &chan(const uint8_t ofs) override { + GCS_MAVLINK_Copter &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_Copter &chan(const uint8_t ofs) const override { + } + const GCS_MAVLINK_Copter &chan(uint8_t ofs) const override { + if (ofs >= num_gcs()) { + AP::internalerror().error(AP_InternalError::error_t::gcs_offset); + ofs = 0; + } return _chan[ofs]; - }; + } void update_vehicle_sensor_status_flags(void) override;