diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index e4b24a112f5..e5e91b98f22 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -496,21 +496,18 @@ int uartGetDebug() return s_uart_debug_nr; } -int log_printf(const char *format, ...) +int log_printfv(const char *format, va_list arg) { static char loc_buf[64]; char * temp = loc_buf; int len; - va_list arg; va_list copy; - va_start(arg, format); va_copy(copy, arg); len = vsnprintf(NULL, 0, format, copy); va_end(copy); if(len >= sizeof(loc_buf)){ temp = (char*)malloc(len+1); if(temp == NULL) { - va_end(arg); return 0; } } @@ -528,13 +525,22 @@ int log_printf(const char *format, ...) xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock); } #endif - va_end(arg); if(len >= sizeof(loc_buf)){ free(temp); } return len; } +int log_printf(const char *format, ...) +{ + int len; + va_list arg; + va_start(arg, format); + len = log_printfv(format, arg); + va_end(arg); + return len; +} + static void log_print_buf_line(const uint8_t *b, size_t len, size_t total_len){ for(size_t i = 0; i