Skip to content

#3181 printf double vsnprintf() fix, malloc, va_end #3184

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

Merged
merged 6 commits into from
Sep 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cores/esp32/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ size_t Print::printf(const char *format, ...)
}
len = vsnprintf(temp, len+1, format, arg);
}
write((uint8_t*)temp, len);
va_end(arg);
if(len >= sizeof(loc_buf)) {
if(temp != loc_buf){
free(temp);
}
return len;
return write((uint8_t*)temp, len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't do it this way, the buffer has already been freed, free() will overwrite the content of temp with the delete chain links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops... absolutely right, a sec

Copy link
Contributor

@stickbreaker stickbreaker Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could:

if(temp != loc_buf){
     len = write((uint8_t*)temp,len);  
     free(temp);
}
else len=write((uint8_t*)temp,len);
return len;

Copy link
Contributor Author

@knifter knifter Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also want to write(temp) if temp == loc_buf
e: right, too soon. But see commit

}

size_t Print::print(const __FlashStringHelper *ifsh)
Expand Down