From 01e78ed33327a4f8944f2b118f2c35dc237614e5 Mon Sep 17 00:00:00 2001 From: Teufelchen1 Date: Thu, 18 Apr 2024 17:18:01 +0200 Subject: [PATCH] cpu/esp: Handle format print errors --- cpu/esp_common/lib_printf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cpu/esp_common/lib_printf.c b/cpu/esp_common/lib_printf.c index 538683ef3b61..78bfa6805090 100644 --- a/cpu/esp_common/lib_printf.c +++ b/cpu/esp_common/lib_printf.c @@ -46,6 +46,16 @@ static int _lib_printf(int level, const char* tag, const char* format, va_list a int len = vsnprintf(_printf_buf, PRINTF_BUFSIZ - 1, format, arg); + if (len < 0) { + ESP_EARLY_LOGI(tag, "Failed to format print"); + return 0; + } + + /* Did the output get truncated? */ + if ((unsigned) len > PRINTF_BUFSIZ - 1) { + len = PRINTF_BUFSIZ - 1; + } + /* * Since ESP_EARLY_LOG macros add a line break at the end, a terminating * line break in the output must be removed if there is one.