Skip to content

Commit f8077a9

Browse files
committed
Returning a reference to a dummy character for indices beyond the string length (in operator[]).
1 parent e385676 commit f8077a9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hardware/arduino/cores/arduino/WString.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ int String::operator>=( const String & rhs ) const
194194

195195
char & String::operator[]( unsigned int index )
196196
{
197-
// need to check for valid index, to do later
197+
static char dummy_writable_char;
198+
if (index >= _length || !_buffer) {
199+
dummy_writable_char = 0;
200+
return dummy_writable_char;
201+
}
198202
return _buffer[ index ];
199203
}
200204

0 commit comments

Comments
 (0)