Skip to content
Merged
Changes from 3 commits
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
15 changes: 10 additions & 5 deletions cores/esp32/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,24 @@ size_t Print::printf(const char *format, ...)
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
size_t len = vsnprintf(NULL, 0, format, copy);
int len = vsnprintf(temp, sizeof(loc_buf), format, copy);
va_end(copy);
if(len < 0) {
va_end(arg);
return 0;
};
if(len >= sizeof(loc_buf)){
temp = new char[len+1];
temp = (char*) malloc(len+1);
if(temp == NULL) {
va_end(arg);
return 0;
}
len = vsnprintf(temp, len+1, format, arg);
}
len = vsnprintf(temp, len+1, format, arg);
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.

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;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ill add/fix that

va_end(arg);
if(len >= sizeof(loc_buf)){
delete[] temp;
if(len >= sizeof(loc_buf)) {
free(temp);
}
return len;
}
Expand Down