From b4de015706483bb0a2256e3e1191d71a3761943e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 13:42:57 -1000 Subject: [PATCH] [api] Use buf_start directly in noise write_protobuf_packet, add flow comment --- esphome/components/api/api_frame_helper.cpp | 1 + esphome/components/api/api_frame_helper_noise.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index d088a75c8a..5c5f1e8785 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -142,6 +142,7 @@ APIError APIFrameHelper::write_raw_iov_(const struct iovec *iov, int iovcnt, uin (iovcnt == 1) ? this->socket_->write(iov[0].iov_base, iov[0].iov_len) : this->socket_->writev(iov, iovcnt); if (sent == static_cast(total_write_len)) return APIError::OK; + // Partial write or -1: fall through to error check / enqueue below } } if (sent == -1) { diff --git a/esphome/components/api/api_frame_helper_noise.cpp b/esphome/components/api/api_frame_helper_noise.cpp index 0c0c069b53..156fcec314 100644 --- a/esphome/components/api/api_frame_helper_noise.cpp +++ b/esphome/components/api/api_frame_helper_noise.cpp @@ -504,7 +504,8 @@ APIError APINoiseFrameHelper::write_protobuf_packet(uint8_t type, ProtoWriteBuff APIError aerr = this->encrypt_noise_message_(buf_start, msg, iov); if (aerr != APIError::OK) return aerr; - return this->write_raw_fast_buf_(iov.iov_base, static_cast(iov.iov_len)); + // buf_start and iov.iov_base point to the same location + return this->write_raw_fast_buf_(buf_start, static_cast(iov.iov_len)); } APIError APINoiseFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, std::span messages) {