Skip to content

Commit 165d624

Browse files
log_printf: Restructured log_printf for wrapping (#7567)
1 parent 3af0b44 commit 165d624

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cores/esp32/esp32-hal-uart.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -496,21 +496,18 @@ int uartGetDebug()
496496
return s_uart_debug_nr;
497497
}
498498

499-
int log_printf(const char *format, ...)
499+
int log_printfv(const char *format, va_list arg)
500500
{
501501
static char loc_buf[64];
502502
char * temp = loc_buf;
503503
int len;
504-
va_list arg;
505504
va_list copy;
506-
va_start(arg, format);
507505
va_copy(copy, arg);
508506
len = vsnprintf(NULL, 0, format, copy);
509507
va_end(copy);
510508
if(len >= sizeof(loc_buf)){
511509
temp = (char*)malloc(len+1);
512510
if(temp == NULL) {
513-
va_end(arg);
514511
return 0;
515512
}
516513
}
@@ -528,13 +525,22 @@ int log_printf(const char *format, ...)
528525
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
529526
}
530527
#endif
531-
va_end(arg);
532528
if(len >= sizeof(loc_buf)){
533529
free(temp);
534530
}
535531
return len;
536532
}
537533

534+
int log_printf(const char *format, ...)
535+
{
536+
int len;
537+
va_list arg;
538+
va_start(arg, format);
539+
len = log_printfv(format, arg);
540+
va_end(arg);
541+
return len;
542+
}
543+
538544

539545
static void log_print_buf_line(const uint8_t *b, size_t len, size_t total_len){
540546
for(size_t i = 0; i<len; i++){

0 commit comments

Comments
 (0)