use local buffer for printf if size is equal or less than 64

This commit is contained in:
me-no-dev 2016-10-10 17:37:34 +03:00
parent 3ecb32c4ba
commit 01961ef5c6

View File

@ -46,13 +46,16 @@ size_t Print::write(const uint8_t *buffer, size_t size)
size_t Print::printf(const char *format, ...) size_t Print::printf(const char *format, ...)
{ {
char * temp; char loc_buf[64];
char * temp = loc_buf;
va_list arg; va_list arg;
va_start(arg, format); va_start(arg, format);
size_t len = vsnprintf(NULL, 0, format, arg); size_t len = vsnprintf(NULL, 0, format, arg);
temp = new char[len+1]; if(len > 64){
if(temp == NULL) { temp = new char[len+1];
return 0; if(temp == NULL) {
return 0;
}
} }
len = vsnprintf(temp, len+1, format, arg); len = vsnprintf(temp, len+1, format, arg);
write((uint8_t*)temp, len); write((uint8_t*)temp, len);