From f8077a96d75513ea4734fd63b2f3019f6e48c11b Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 28 Aug 2010 09:55:26 +0000 Subject: [PATCH] Returning a reference to a dummy character for indices beyond the string length (in operator[]). --- hardware/arduino/cores/arduino/WString.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/cores/arduino/WString.cpp b/hardware/arduino/cores/arduino/WString.cpp index d5ea11f0c..fd07c2d49 100644 --- a/hardware/arduino/cores/arduino/WString.cpp +++ b/hardware/arduino/cores/arduino/WString.cpp @@ -194,7 +194,11 @@ int String::operator>=( const String & rhs ) const char & String::operator[]( unsigned int index ) { - // need to check for valid index, to do later + static char dummy_writable_char; + if (index >= _length || !_buffer) { + dummy_writable_char = 0; + return dummy_writable_char; + } return _buffer[ index ]; }