Skip to content

Bug in Print::printf() #2891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
glennramalho opened this issue Jun 13, 2019 · 2 comments · Fixed by #3060
Closed

Bug in Print::printf() #2891

glennramalho opened this issue Jun 13, 2019 · 2 comments · Fixed by #3060
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@glennramalho
Copy link

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

@everslick
Copy link
Contributor

I think you are right. Care to provide a PR?

@stale
Copy link

stale bot commented Aug 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 15, 2019
me-no-dev pushed a commit that referenced this issue Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants