Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 717ca79

Browse filesBrowse files
knifterme-no-dev
authored andcommitted
espressif#3181 printf double vsnprintf() fix, malloc, va_end (espressif#3184)
* Use loc_buf for small strings, check for error return from vsnprintf * cleanup arg when bailing out of new * Use malloc/free instead of new/delete in printf * Return actual bytes written in printf * FIX: write before free
1 parent 07613b3 commit 717ca79
Copy full SHA for 717ca79

File tree

Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed

‎cores/esp32/Print.cpp

Copy file name to clipboardExpand all lines: cores/esp32/Print.cpp
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,24 @@ size_t Print::printf(const char *format, ...)
5252
va_list copy;
5353
va_start(arg, format);
5454
va_copy(copy, arg);
55-
size_t len = vsnprintf(NULL, 0, format, copy);
55+
int len = vsnprintf(temp, sizeof(loc_buf), format, copy);
5656
va_end(copy);
57+
if(len < 0) {
58+
va_end(arg);
59+
return 0;
60+
};
5761
if(len >= sizeof(loc_buf)){
58-
temp = new char[len+1];
62+
temp = (char*) malloc(len+1);
5963
if(temp == NULL) {
64+
va_end(arg);
6065
return 0;
6166
}
67+
len = vsnprintf(temp, len+1, format, arg);
6268
}
63-
len = vsnprintf(temp, len+1, format, arg);
64-
write((uint8_t*)temp, len);
6569
va_end(arg);
66-
if(len >= sizeof(loc_buf)){
67-
delete[] temp;
70+
len = write((uint8_t*)temp, len);
71+
if(temp != loc_buf){
72+
free(temp);
6873
}
6974
return len;
7075
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.