aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/WString.cpp
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-08-28 09:55:26 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2010-08-28 09:55:26 +0000
commit1362ca26c198082235f71192861656385a1eab20 (patch)
tree2cb3b863b1adffefb0d6921c1731f6c26a5eb275 /cores/arduino/WString.cpp
parent14831247bce771964b816f5863582e17f3d5bfbf (diff)
Returning a reference to a dummy character for indices beyond the string length (in operator[]).
Diffstat (limited to 'cores/arduino/WString.cpp')
-rw-r--r--cores/arduino/WString.cpp6
1 files changed, 5 insertions, 1 deletions
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 ];
}