File tree 1 file changed +14
-0
lines changed
1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 25
25
#include " WString.h"
26
26
#include " stdlib_noniso.h"
27
27
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
+
28
34
/* ********************************************/
29
35
/* Constructors */
30
36
/* ********************************************/
@@ -178,6 +184,14 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) {
178
184
}
179
185
// Fallthrough to normal allocator
180
186
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
181
195
// Make sure we can fit newsize in the buffer
182
196
if (newSize > CAPACITY_MAX) {
183
197
return 0 ;
You can’t perform that action at this time.
0 commit comments