aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2011-03-18 21:45:27 -0400
committerDavid A. Mellis <d.mellis@arduino.cc>2011-03-18 21:45:27 -0400
commit7dea0522f48641106f92b1511b9e62ee46f8e2dc (patch)
tree5bb53c95b207a9d352859b60cf3fb004abbbc37d /cores/arduino
parent45884b1231e43acdce51b381975977a3601e77d0 (diff)
Starting to distinguish between empty strings and invalid (null) ones.
Diffstat (limited to 'cores/arduino')
-rw-r--r--cores/arduino/WString.cpp12
-rw-r--r--cores/arduino/WString.h2
2 files changed, 7 insertions, 7 deletions
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;
diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h
index 6c07427..18b6541 100644
--- a/cores/arduino/WString.h
+++ b/cores/arduino/WString.h
@@ -43,7 +43,7 @@ class String
{
public:
// constructors
- String(const char *cstr = NULL);
+ String(const char *cstr = "");
String(const String &str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String(String &&rval);