diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-08-18 21:39:28 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-08-18 21:39:28 +0000 |
commit | 14831247bce771964b816f5863582e17f3d5bfbf (patch) | |
tree | 894a393ec77a3826a6b6e5ef211e5db36a87274e /cores/arduino/WString.h | |
parent | 1f9520e226a1943d81ed7fd1f54ccd614a6b7204 (diff) |
Adding some basic error checking to the String class (i.e. checking for a non-null buffer before modifying its contents).
Diffstat (limited to 'cores/arduino/WString.h')
-rw-r--r-- | cores/arduino/WString.h | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index b4e160c..eede8ae 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -52,7 +52,7 @@ class String char operator []( unsigned int index ) const; char& operator []( unsigned int index ); //operator const char *() const { return _buffer; } - + // general methods char charAt( unsigned int index ) const; int compareTo( const String &anotherString ) const; @@ -89,7 +89,6 @@ class String unsigned int _length; // the String length (not counting the '\0') void getBuffer(unsigned int maxStrLen); - void doubleBuffer( ); private: @@ -100,15 +99,7 @@ inline void String::getBuffer(unsigned int maxStrLen) { _capacity = maxStrLen; _buffer = (char *) malloc(_capacity + 1); -} - -// double the buffer size -inline void String::doubleBuffer( ) -{ - char *temp = _buffer; - getBuffer( ++_capacity * 2 ); - strcpy( _buffer, temp ); - free(temp); + if (_buffer == NULL) _length = _capacity = 0; } inline String operator+( String lhs, const String &rhs ) |