Skip to content

Commit 63f4021

Browse files
committed
Changing String append to use realloc(); thanks to Paul Stoffregen.
http://code.google.com/p/arduino/issues/detail?id=332
1 parent d7ecd5e commit 63f4021

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

hardware/arduino/cores/arduino/WString.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,16 @@ const String & String::operator+=( const String &other )
150150
_length += other._length;
151151
if ( _length > _capacity )
152152
{
153-
char *temp = _buffer;
154-
getBuffer( _length );
155-
if ( _buffer != NULL )
156-
strcpy( _buffer, temp );
157-
free(temp);
153+
char *temp = (char *)realloc(_buffer, _length + 1);
154+
if ( temp != NULL ) {
155+
_buffer = temp;
156+
_capacity = _length;
157+
} else {
158+
_length -= other._length;
159+
return *this;
160+
}
158161
}
159-
if ( _buffer != NULL )
160-
strcat( _buffer, other._buffer );
162+
strcat( _buffer, other._buffer );
161163
return *this;
162164
}
163165

0 commit comments

Comments
 (0)