File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 2525#include " WString.h"
2626#include " stdlib_noniso.h"
2727
28+ #define OOM_STRING_BORDER_DISPLAY 10
29+ #define OOM_STRING_THRESHOLD_REALLOC_WARN 128
30+
31+ #define __STRHELPER (x ) #x
32+ #define STR (x ) __STRHELPER(x) // stringifier
33+
2834/* ********************************************/
2935/* Constructors */
3036/* ********************************************/
@@ -178,6 +184,14 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
178184 }
179185 // Fallthrough to normal allocator
180186 size_t newSize = (maxStrLen + 16 ) & (~0xf );
187+ #ifdef DEBUG_ESP_OOM
188+ if (!isSSO () && capacity () >= OOM_STRING_THRESHOLD_REALLOC_WARN && maxStrLen > capacity ()) {
189+ // warn when badly re-allocating
190+ DEBUGV (" [offending String op %d->%d ('%." STR (OOM_STRING_BORDER_DISPLAY) " s ... %." STR (OOM_STRING_BORDER_DISPLAY) " s')]\n " ,
191+ len (), maxStrLen, c_str (),
192+ len () > OOM_STRING_BORDER_DISPLAY? c_str () + std::max ((int )len () - OOM_STRING_BORDER_DISPLAY, OOM_STRING_BORDER_DISPLAY): " " );
193+ }
194+ #endif
181195 // Make sure we can fit newsize in the buffer
182196 if (newSize > CAPACITY_MAX) {
183197 return 0 ;
You can’t perform that action at this time.
0 commit comments