From d728830b998402b0a6b81131240df58835a07fdf Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Thu, 30 Jan 2025 18:20:56 +0000 Subject: [PATCH] AP_AIS: fix multi part message decoding --- libraries/AP_AIS/AP_AIS.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/AP_AIS/AP_AIS.cpp b/libraries/AP_AIS/AP_AIS.cpp index afb141ec5356a..93ab9c0645314 100644 --- a/libraries/AP_AIS/AP_AIS.cpp +++ b/libraries/AP_AIS/AP_AIS.cpp @@ -145,21 +145,25 @@ void AP_AIS::update() } else if (_incoming.num == _incoming.total) { // last part of a multi part message uint8_t index = 0; - uint8_t msg_parts[_incoming.num - 1]; + + // We have the last part, need to find preceding fragments + const uint8_t parts = _incoming.num - 1; + + uint8_t msg_parts[parts]; for (uint8_t i = 0; i < AIVDM_BUFFER_SIZE; i++) { // look for the rest of the message from the start of the buffer // we assume the message has be received in the correct order if (_AIVDM_buffer[i].num == (index + 1) && _AIVDM_buffer[i].total == _incoming.total && _AIVDM_buffer[i].ID == _incoming.ID) { msg_parts[index] = i; index++; - if (index >= _incoming.num) { + if (index >= parts) { break; } } } // did we find the right number? - if (_incoming.num != index) { + if (parts != index) { // could not find all of the message, save messages #if HAL_LOGGING_ENABLED if (log_unsupported) {