From 282ba90f6281140fd8a13cf7e20af219cdf4cf06 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 12 Feb 2026 12:32:06 -0600 Subject: [PATCH] Address review feedback: add explicit includes and clarify comments - Add #include to both .cpp and .h for static_asserts - Clarify CompactString comment: explicitly note it is not trivially copyable, and that memcpy safety relies on validated layout property - Use memcpy_fn indirection to suppress both GCC -Wclass-memaccess and clang-tidy bugprone-undefined-memory-manipulation without platform-specific pragma guards --- esphome/components/wifi/wifi_component.cpp | 1 + esphome/components/wifi/wifi_component.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 99c8b5f228..52188b2621 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef USE_ESP32 #if (ESP_IDF_VERSION_MAJOR >= 5 && ESP_IDF_VERSION_MINOR >= 1) diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index f0ccc95abe..7ae8a2c18a 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -10,6 +10,7 @@ #include #include +#include #include #ifdef USE_LIBRETINY @@ -219,12 +220,14 @@ class CompactString { }; static_assert(sizeof(CompactString) == 20, "CompactString must be exactly 20 bytes"); -// CompactString is safe to memcpy for permutation-based sorting (no ownership duplication). -// Unlike libstdc++ std::string which uses a self-referential pointer (_M_p -> _M_local_buf) -// in SSO mode, CompactString stores either inline data or an external heap pointer in -// storage_[] — never a pointer to itself. These asserts guard that property. -static_assert(std::is_standard_layout::value, "CompactString must be standard layout for memcpy safety"); -static_assert(!std::is_polymorphic::value, "CompactString must not have vtable for memcpy safety"); +// CompactString is not trivially copyable (non-trivial destructor/copy for heap case). +// However, its layout has no self-referential pointers: storage_[] contains either inline +// data or an external heap pointer — never a pointer to itself. This is unlike libstdc++ +// std::string SSO where _M_p points to _M_local_buf within the same object. +// This property allows memcpy-based permutation sorting where each element ends up in +// exactly one slot (no ownership duplication). These asserts document that layout property. +static_assert(std::is_standard_layout::value, "CompactString must be standard layout"); +static_assert(!std::is_polymorphic::value, "CompactString must not have vtable"); class WiFiAP { friend class WiFiComponent;