diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index 5f4ca41b8a..3c82eab471 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -450,12 +450,12 @@ Mavlink::forward_message(const mavlink_message_t *msg, Mavlink *self) // might be nullptr if message is unknown if (meta) { // Extract target system and target component if set - if (meta->target_system_ofs != 0) { - target_system_id = ((uint8_t *)msg)[meta->target_system_ofs]; + if (meta->flags & MAV_MSG_ENTRY_FLAG_HAVE_TARGET_SYSTEM) { + target_system_id = (_MAV_PAYLOAD(msg))[meta->target_system_ofs]; } - if (meta->target_component_ofs != 0) { - target_component_id = ((uint8_t *)msg)[meta->target_component_ofs]; + if (meta->flags & MAV_MSG_ENTRY_FLAG_HAVE_TARGET_COMPONENT) { + target_component_id = (_MAV_PAYLOAD(msg))[meta->target_component_ofs]; } }