Skip to content

Commit 01961ef

Browse files
committed
use local buffer for printf if size is equal or less than 64
1 parent 3ecb32c commit 01961ef

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cores/esp32/Print.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ size_t Print::write(const uint8_t *buffer, size_t size)
4646

4747
size_t Print::printf(const char *format, ...)
4848
{
49-
char * temp;
49+
char loc_buf[64];
50+
char * temp = loc_buf;
5051
va_list arg;
5152
va_start(arg, format);
5253
size_t len = vsnprintf(NULL, 0, format, arg);
53-
temp = new char[len+1];
54-
if(temp == NULL) {
55-
return 0;
54+
if(len > 64){
55+
temp = new char[len+1];
56+
if(temp == NULL) {
57+
return 0;
58+
}
5659
}
5760
len = vsnprintf(temp, len+1, format, arg);
5861
write((uint8_t*)temp, len);

0 commit comments

Comments
 (0)