Returning a reference to a dummy character for indices beyond the string length (in operator[]).

This commit is contained in:
David A. Mellis 2010-08-28 09:55:26 +00:00
parent 14831247bc
commit 1362ca26c1
1 changed files with 5 additions and 1 deletions

View File

@ -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 ];
}