From 2f903c91ff946ba232b40370da6ad63ffa78f92e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 27 Feb 2026 12:45:00 -1000 Subject: [PATCH] Clarify that stubs are dead code at runtime and overflow is defensive --- esphome/components/esp32/printf_stubs.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/components/esp32/printf_stubs.cpp b/esphome/components/esp32/printf_stubs.cpp index 33098ea516..0b94b66967 100644 --- a/esphome/components/esp32/printf_stubs.cpp +++ b/esphome/components/esp32/printf_stubs.cpp @@ -33,15 +33,16 @@ namespace esphome::esp32 {} static constexpr size_t PRINTF_BUFFER_SIZE = 512; -// Write formatted buffer to stream, aborting on overflow. +// These stubs are essentially dead code at runtime — ESPHome replaces the +// ESP-IDF log handler, and the SDK's printf/fprintf calls only exist in +// debug/assert paths that are never reached in normal operation. +// The buffer overflow check is purely defensive and should never trigger. static int write_printf_buffer_(FILE *stream, char *buf, int len) { if (len < 0) { return len; } size_t write_len = len; if (write_len >= PRINTF_BUFFER_SIZE) { - // Output was truncated — flush what we have before aborting - // so the user sees context leading up to the overflow. fwrite(buf, 1, PRINTF_BUFFER_SIZE - 1, stream); esp_system_abort("printf buffer overflow; set enable_full_printf: true in esp32 advanced config"); }