From 7dea0522f48641106f92b1511b9e62ee46f8e2dc Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 18 Mar 2011 21:45:27 -0400 Subject: Starting to distinguish between empty strings and invalid (null) ones. --- cores/arduino/WString.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cores/arduino/WString.cpp') diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 41c80e8..516bd20 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -114,7 +114,7 @@ inline void String::init(void) unsigned char String::reserve(unsigned int size) { - if (capacity >= size) return 1; + if (buffer && capacity >= size) return 1; if (changeBuffer(size)) { if (len == 0) buffer[0] = 0; return 1; @@ -139,11 +139,6 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) String & String::copy(const char *cstr, unsigned int length) { - if (length == 0) { - if (buffer) buffer[0] = 0; - len = 0; - return *this; - } if (!reserve(length)) { if (buffer) { free(buffer); @@ -204,6 +199,11 @@ String & String::operator = (const char *cstr) if (cstr) { copy(cstr, strlen(cstr)); } else { + if (buffer) { + free(buffer); + capacity = 0; + buffer = NULL; + } len = 0; } return *this; -- cgit v1.2.3-18-g5258