@@ -197,6 +197,15 @@ bool String::reserve(unsigned int size) {
197
197
return false ;
198
198
}
199
199
200
+ #ifdef DEBUG_ESP_PORT
201
+ static void identifyString (const String& badOne)
202
+ {
203
+ DEBUGV (" [String] '%." STR (OOM_STRING_BORDER_DISPLAY) " s ... %." STR (OOM_STRING_BORDER_DISPLAY) " s': " ,
204
+ badOne.c_str (),
205
+ badOne.length () > OOM_STRING_BORDER_DISPLAY? badOne.c_str () + std::max ((int )badOne.length () - OOM_STRING_BORDER_DISPLAY, OOM_STRING_BORDER_DISPLAY): " " );
206
+ }
207
+ #endif
208
+
200
209
bool String::changeBuffer (unsigned int maxStrLen) {
201
210
// Can we use SSO here to avoid allocation?
202
211
if (maxStrLen < sizeof (sso.buff ) - 1 ) {
@@ -218,16 +227,19 @@ bool String::changeBuffer(unsigned int maxStrLen) {
218
227
}
219
228
// Fallthrough to normal allocator
220
229
size_t newSize = (maxStrLen + 16 ) & (~0xf );
221
- #ifdef DEBUG_ESP_OOM
230
+ #ifdef DEBUG_ESP_PORT
222
231
if (!isSSO () && capacity () >= OOM_STRING_THRESHOLD_REALLOC_WARN && maxStrLen > capacity ()) {
223
232
// warn when badly re-allocating
224
- DEBUGV (" [String] Reallocating large String(%d -> %d bytes) '%." STR (OOM_STRING_BORDER_DISPLAY) " s ... %." STR (OOM_STRING_BORDER_DISPLAY) " s'\n " ,
225
- len (), maxStrLen, c_str (),
226
- len () > OOM_STRING_BORDER_DISPLAY? c_str () + std::max ((int )len () - OOM_STRING_BORDER_DISPLAY, OOM_STRING_BORDER_DISPLAY): " " );
233
+ identifyString (*this );
234
+ DEBUGV (" Reallocating large String(%d -> %d bytes)\n " , len (), maxStrLen);
227
235
}
228
236
#endif
229
237
// Make sure we can fit newsize in the buffer
230
238
if (newSize > CAPACITY_MAX) {
239
+ #ifdef DEBUG_ESP_PORT
240
+ identifyString (*this );
241
+ DEBUGV (" Maximum capacity reached (" STR (CAPACITY_MAX) " )\n " );
242
+ #endif
231
243
return false ;
232
244
}
233
245
uint16_t oldLen = len ();
@@ -247,6 +259,10 @@ bool String::changeBuffer(unsigned int maxStrLen) {
247
259
setBuffer (newbuffer);
248
260
return true ;
249
261
}
262
+ #ifdef DEBUG_ESP_PORT
263
+ identifyString (*this );
264
+ DEBUGV (" OOM: %d -> %d bytes\n " , isSSO () ? 0 : capacity (), newSize);
265
+ #endif
250
266
return false ;
251
267
}
252
268
@@ -804,7 +820,7 @@ void String::replace(const String &find, const String &replace) {
804
820
if (size == len ())
805
821
return ;
806
822
if (size > capacity () && !changeBuffer (size))
807
- return ; // XXX: tell user!
823
+ return ;
808
824
int index = len () - 1 ;
809
825
while (index >= 0 && (index = lastIndexOf (find, index )) >= 0 ) {
810
826
readFrom = wbuffer () + index + find.len ();
0 commit comments