Fix for error condition causing crash when range exceeds string length