1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

fix String bug

length where returning something that is not 0 while buffer where NULL!?
This commit is contained in:
Markus Sattler 2015-12-10 17:37:09 +01:00
parent 49536c78d3
commit 7ea4eb452d
2 changed files with 7 additions and 3 deletions

View File

@ -121,6 +121,7 @@ ICACHE_FLASH_ATTR String::~String() {
if(buffer) { if(buffer) {
free(buffer); free(buffer);
} }
init();
} }
// /*********************************************/ // /*********************************************/
@ -136,8 +137,7 @@ inline void String::init(void) {
void ICACHE_FLASH_ATTR String::invalidate(void) { void ICACHE_FLASH_ATTR String::invalidate(void) {
if(buffer) if(buffer)
free(buffer); free(buffer);
buffer = NULL; init();
capacity = len = 0;
} }
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) { unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) {

View File

@ -76,7 +76,11 @@ class String {
// invalid string (i.e., "if (s)" will be true afterwards) // invalid string (i.e., "if (s)" will be true afterwards)
unsigned char reserve(unsigned int size); unsigned char reserve(unsigned int size);
inline unsigned int length(void) const { inline unsigned int length(void) const {
if(buffer) {
return len; return len;
} else {
return 0;
}
} }
// creates a copy of the assigned value. if the value is null or // creates a copy of the assigned value. if the value is null or