Changing String append to use realloc(); thanks to Paul Stoffregen.

http://code.google.com/p/arduino/issues/detail?id=332
This commit is contained in:
David A. Mellis 2010-12-11 15:22:07 -05:00
parent d7ecd5e4e8
commit 63f4021447
1 changed files with 9 additions and 7 deletions

View File

@ -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;
}