aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/WString.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index 4de9296..db5a441 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -150,14 +150,16 @@ const String & String::operator+=( const String &other )
_length += other._length;
if ( _length > _capacity )
{
- char *temp = _buffer;
- getBuffer( _length );
- if ( _buffer != NULL )
- strcpy( _buffer, temp );
- free(temp);
+ char *temp = (char *)realloc(_buffer, _length + 1);
+ if ( temp != NULL ) {
+ _buffer = temp;
+ _capacity = _length;
+ } else {
+ _length -= other._length;
+ return *this;
+ }
}
- if ( _buffer != NULL )
- strcat( _buffer, other._buffer );
+ strcat( _buffer, other._buffer );
return *this;
}