From 73326bce07dd5ee58d32c974c2fdb6b08b442417 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 5 Apr 2026 11:56:43 -1000 Subject: [PATCH] Fix stale docstring and extract stack scan limit constant --- esphome/components/esp8266/crash_handler.cpp | 6 +++--- esphome/components/esp8266/crash_handler.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/esp8266/crash_handler.cpp b/esphome/components/esp8266/crash_handler.cpp index eb5d333cd9..5aeb6f6f2d 100644 --- a/esphome/components/esp8266/crash_handler.cpp +++ b/esphome/components/esp8266/crash_handler.cpp @@ -42,6 +42,7 @@ static inline uint32_t IRAM_ATTR recover_code_addr(uint32_t val) { return (val & // We use blocks 183-191 (last 9 blocks, 36 bytes) to minimize conflicts. static constexpr uint8_t RTC_CRASH_BASE = 183; static constexpr size_t MAX_BACKTRACE = 8; +static constexpr size_t STACK_SCAN_WORDS = 64; // Scan up to 256 bytes of stack // Magic word packs sentinel, version, and count into one uint32_t: // bits[31:16] = 0xDEAD (sentinel) @@ -225,9 +226,8 @@ extern "C" void IRAM_ATTR custom_crash_callback(struct rst_info * /*rst_info*/, auto *scan = reinterpret_cast(stack); auto *end = reinterpret_cast(stack_end); - // Limit scan to 64 words (256 bytes) to avoid excessive scanning - if (end > scan + 64) - end = scan + 64; + if (end > scan + STACK_SCAN_WORDS) + end = scan + STACK_SCAN_WORDS; for (; scan < end && count < MAX_BACKTRACE; scan++) { uint32_t val = *scan; diff --git a/esphome/components/esp8266/crash_handler.h b/esphome/components/esp8266/crash_handler.h index 78ba4711bf..def94fbbe9 100644 --- a/esphome/components/esp8266/crash_handler.h +++ b/esphome/components/esp8266/crash_handler.h @@ -8,7 +8,7 @@ namespace esphome::esp8266 { -/// Read crash data from rst_info and RTC user memory, then clear RTC data. +/// Check if previous boot was a crash and set validity flag. void crash_handler_read_and_clear(); /// Log crash data if a crash was detected on previous boot.