diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-12-11 15:22:07 -0500 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-12-11 15:22:07 -0500 |
commit | 11dd06436d6144420cc6f5b5d9a926e7f34818b1 (patch) | |
tree | 1c1a19de19f6d2d23d1c4e68cef25046422eb7ad /cores/arduino | |
parent | 31fc07f33e1da63cadd516d6e45fd00f6b7895c5 (diff) |
Changing String append to use realloc(); thanks to Paul Stoffregen.
http://code.google.com/p/arduino/issues/detail?id=332
Diffstat (limited to 'cores/arduino')
-rw-r--r-- | cores/arduino/WString.cpp | 16 |
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; } |