Skip to content

Commit aaddf0a

Browse files
committed
WString: make to be safer init state, in order to tolerate (potential) stray dtor calls
derived from esp8266#7553
1 parent a460cb7 commit aaddf0a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cores/esp8266/WString.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,19 @@ class String {
288288
enum { SSOSIZE = sizeof(struct _ptr) + 4 - 1 }; // Characters to allocate space for SSO, must be 12 or more
289289
struct _sso {
290290
char buff[SSOSIZE];
291-
unsigned char len : 7; // Ensure only one byte is allocated by GCC for the bitfields
292-
unsigned char isSSO : 1;
291+
unsigned char len : 7; // Ensure only one byte is allocated by GCC for the bitfields
292+
unsigned char isHeap : 1;
293293
} __attribute__((packed)); // Ensure that GCC doesn't expand the flag byte to a 32-bit word for alignment issues
294294
enum { CAPACITY_MAX = 65535 }; // If typeof(cap) changed from uint16_t, be sure to update this enum to the max value storable in the type
295295
union {
296296
struct _ptr ptr;
297297
struct _sso sso;
298298
};
299299
// Accessor functions
300-
inline bool isSSO() const { return sso.isSSO; }
300+
inline bool isSSO() const { return !sso.isHeap; }
301301
inline unsigned int len() const { return isSSO() ? sso.len : ptr.len; }
302302
inline unsigned int capacity() const { return isSSO() ? (unsigned int)SSOSIZE - 1 : ptr.cap; } // Size of max string not including terminal NUL
303-
inline void setSSO(bool set) { sso.isSSO = set; }
303+
inline void setSSO(bool set) { sso.isHeap = !set; }
304304
inline void setLen(int len) { if (isSSO()) sso.len = len; else ptr.len = len; }
305305
inline void setCapacity(int cap) { if (!isSSO()) ptr.cap = cap; }
306306
inline void setBuffer(char *buff) { if (!isSSO()) ptr.buff = buff; }

0 commit comments

Comments
 (0)