-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
#3181 printf double vsnprintf() fix, malloc, va_end #3184
Conversation
cores/esp32/Print.cpp
Outdated
} | ||
len = vsnprintf(temp, len+1, format, arg); | ||
write((uint8_t*)temp, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just thought of something, This print function is used for many different subsystems. I think some of them may actually have cases where write()
can fail. instead of returning the number of characters to be written, actually return the true number.
int actualLen = write((uint8_t*)temp,len);
...
return actualLen;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill add/fix that
cores/esp32/Print.cpp
Outdated
free(temp); | ||
} | ||
return len; | ||
return write((uint8_t*)temp, len); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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
@knifter Found one more at line 162: size_t Print::print(struct tm * timeinfo, const char * format)
{
const char * f = format;
if(!f){
f = "%c";
}
char buf[64];
size_t written = strftime(buf, 64, f, timeinfo);
print(buf);
return written;
} Instead of Thanks for doing this. Every little bit helps! |
@stickbreaker that is unrelated though :) |
These are the changes mentioned in #3181