Address review: flush before abort, check fwrite errors, add test

This commit is contained in:
J. Nick Koston
2026-02-27 12:43:22 -10:00
parent a3a6ed3582
commit b2728cbd44
2 changed files with 9 additions and 4 deletions
+8 -4
View File
@@ -38,12 +38,16 @@ static int write_printf_buffer_(FILE *stream, char *buf, int len) {
if (len < 0) {
return len;
}
if (static_cast<size_t>(len) >= PRINTF_BUFFER_SIZE) {
// Output was truncated — this should not happen in normal operation.
// Abort to make the issue visible rather than silently losing output.
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");
}
fwrite(buf, 1, len, stream);
if (fwrite(buf, 1, write_len, stream) < write_len || ferror(stream)) {
return -1;
}
return len;
}
@@ -10,6 +10,7 @@ esp32:
use_full_certificate_bundle: false # Test CMN bundle (default)
include_builtin_idf_components:
- freertos # Test escape hatch (freertos is always included anyway)
enable_full_printf: false
disable_debug_stubs: true
disable_ocd_aware: true
disable_usb_serial_jtag_secondary: true