From 01961ef5c64cb061b470ed6258540e880ca5a1b7 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 10 Oct 2016 17:37:34 +0300 Subject: [PATCH] use local buffer for printf if size is equal or less than 64 --- cores/esp32/Print.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cores/esp32/Print.cpp b/cores/esp32/Print.cpp index 34584c50..9f7b35da 100644 --- a/cores/esp32/Print.cpp +++ b/cores/esp32/Print.cpp @@ -46,13 +46,16 @@ size_t Print::write(const uint8_t *buffer, size_t size) size_t Print::printf(const char *format, ...) { - char * temp; + char loc_buf[64]; + char * temp = loc_buf; va_list arg; va_start(arg, format); size_t len = vsnprintf(NULL, 0, format, arg); - temp = new char[len+1]; - if(temp == NULL) { - return 0; + if(len > 64){ + temp = new char[len+1]; + if(temp == NULL) { + return 0; + } } len = vsnprintf(temp, len+1, format, arg); write((uint8_t*)temp, len);