Skip to content

Commit 7ea4eb4

Browse files
committed
fix String bug
length where returning something that is not 0 while buffer where NULL!?
1 parent 49536c7 commit 7ea4eb4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cores/esp8266/WString.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ICACHE_FLASH_ATTR String::~String() {
121121
if(buffer) {
122122
free(buffer);
123123
}
124+
init();
124125
}
125126

126127
// /*********************************************/
@@ -136,8 +137,7 @@ inline void String::init(void) {
136137
void ICACHE_FLASH_ATTR String::invalidate(void) {
137138
if(buffer)
138139
free(buffer);
139-
buffer = NULL;
140-
capacity = len = 0;
140+
init();
141141
}
142142

143143
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) {

cores/esp8266/WString.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ class String {
7676
// invalid string (i.e., "if (s)" will be true afterwards)
7777
unsigned char reserve(unsigned int size);
7878
inline unsigned int length(void) const {
79-
return len;
79+
if(buffer) {
80+
return len;
81+
} else {
82+
return 0;
83+
}
8084
}
8185

8286
// creates a copy of the assigned value. if the value is null or

0 commit comments

Comments
 (0)