From cfbba0af9033e3fde8316b5f0c58dd5da4052e3e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2026 16:18:01 -1000 Subject: [PATCH] Add comment about string literal pointer stability in compat save_state_ --- esphome/components/fan/fan.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index 563c0eff13..9301e0cea4 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -307,6 +307,8 @@ void Fan::save_state_() { } } else { // Compat: fall back to traits for deprecated path. Remove in 2026.11.0. + // Pointer comparison works because preset_mode_ and the compat vector both + // hold pointers to string literals in .rodata (stable addresses). auto traits = this->get_traits(); const auto &preset_modes = traits.supported_preset_modes(); for (size_t i = 0; i < preset_modes.size(); i++) {