From 1362ca26c198082235f71192861656385a1eab20 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 28 Aug 2010 09:55:26 +0000 Subject: Returning a reference to a dummy character for indices beyond the string length (in operator[]). --- cores/arduino/WString.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cores') diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index d5ea11f..fd07c2d 100644 --- a/cores/arduino/WString.cpp +++ b/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 ]; } -- cgit v1.2.3-18-g5258