From 14831247bce771964b816f5863582e17f3d5bfbf Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 18 Aug 2010 21:39:28 +0000 Subject: Adding some basic error checking to the String class (i.e. checking for a non-null buffer before modifying its contents). --- cores/arduino/WString.h | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'cores/arduino/WString.h') 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 ) -- cgit v1.2.3-18-g5258