From af7b1a3a23460bde5e479a280f8c68ee58b13fcd Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Tue, 27 May 2025 06:46:51 +1200 Subject: [PATCH] [api] Fix crash with gcc compiler on host (#8902) --- esphome/components/api/api_connection.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 27dd44ae86..b4646a2d7d 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -4,11 +4,11 @@ #include #include #include "esphome/components/network/util.h" +#include "esphome/core/application.h" #include "esphome/core/entity_base.h" #include "esphome/core/hal.h" #include "esphome/core/log.h" #include "esphome/core/version.h" -#include "esphome/core/application.h" #ifdef USE_DEEP_SLEEP #include "esphome/components/deep_sleep/deep_sleep_component.h" @@ -153,7 +153,11 @@ void APIConnection::loop() { } else { this->last_traffic_ = App.get_loop_component_start_time(); // read a packet - this->read_message(buffer.data_len, buffer.type, &buffer.container[buffer.data_offset]); + if (buffer.data_len > 0) { + this->read_message(buffer.data_len, buffer.type, &buffer.container[buffer.data_offset]); + } else { + this->read_message(0, buffer.type, nullptr); + } if (this->remove_) return; }