Skip to content

Commit 30a823f

Browse files
committed
Starting to distinguish between empty strings and invalid (null) ones.
1 parent 2665025 commit 30a823f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

hardware/arduino/cores/arduino/WString.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ inline void String::init(void)
114114

115115
unsigned char String::reserve(unsigned int size)
116116
{
117-
if (capacity >= size) return 1;
117+
if (buffer && capacity >= size) return 1;
118118
if (changeBuffer(size)) {
119119
if (len == 0) buffer[0] = 0;
120120
return 1;
@@ -139,11 +139,6 @@ unsigned char String::changeBuffer(unsigned int maxStrLen)
139139

140140
String & String::copy(const char *cstr, unsigned int length)
141141
{
142-
if (length == 0) {
143-
if (buffer) buffer[0] = 0;
144-
len = 0;
145-
return *this;
146-
}
147142
if (!reserve(length)) {
148143
if (buffer) {
149144
free(buffer);
@@ -204,6 +199,11 @@ String & String::operator = (const char *cstr)
204199
if (cstr) {
205200
copy(cstr, strlen(cstr));
206201
} else {
202+
if (buffer) {
203+
free(buffer);
204+
capacity = 0;
205+
buffer = NULL;
206+
}
207207
len = 0;
208208
}
209209
return *this;

hardware/arduino/cores/arduino/WString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class String
4343
{
4444
public:
4545
// constructors
46-
String(const char *cstr = NULL);
46+
String(const char *cstr = "");
4747
String(const String &str);
4848
#ifdef __GXX_EXPERIMENTAL_CXX0X__
4949
String(String &&rval);

0 commit comments

Comments
 (0)