Description
Hi,
I was using the Printf function in a StreamString and noticed that in some cases the end of the message when using a long statement got chopped off. Looking more carefully and using a debugger (I have been testing using a simulation of the ESP32) and single steppping through the code I noticed that the problem was seemed to be inside Print::printf().
Inside you have ``size_t Print::printf(const char format, ...)
{
char loc_buf[64];
char * temp = loc_buf;
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
size_t len = vsnprintf(NULL, 0, format, arg);
va_end(copy);
if(len >= sizeof(loc_buf)){
temp = new char[len+1];
if(temp == NULL) {
return 0;
}
}
len = vsnprintf(temp, len+1, format, arg);
write((uint8_t)temp, len);
va_end(arg);
if(len >= sizeof(loc_buf)){
delete[] temp;
}
But notice that you do the va_start and then a va_copy to create the copy of the arg argument list. Then you call vsprintf twice. I would think that the first one should be with "copy" as argument and the second time with "arg" as argument, but I see both cases using "arg" and none uses "copy". When I corrected my version here the problem went away,
So I would think we should change line 55 of Print.cpp to say "vsprintf(NULL, 0, format, copy);"
regards,
Glenn