title: NSString substringWithRange crash
body: <p>I have this code:</p>
  
  <pre><code>- (void)splitAndSendString:(NSString *)string
               withAlignment:(UITextAlignment)alignment
           verticalExpansion:(NSUInteger)verticalExpansion
         horizontalExpansion:(NSUInteger)horizontalExpansion
                       inRed:(BOOL)isRed
            leftBumperString:(NSString *)leftString
           rightBumperString:(NSString *)rightString
                  lineLength:(NSUInteger)lineLength
  {
      NSInteger charactersLeftAfterString = lineLength - [string length] -
              [leftString length] - [rightString length];
  
     // if either of the bumpers is nil, then replace it with @""
     //so that we don't get "null" printed
     if (leftString == nil)  { leftString = @"";     }
     if (rightString == nil) { rightString = @"";    }
  
     if (charactersLeftAfterString &lt; 0) {
          NSInteger charactersAvailableForString =
             [string length] + charactersLeftAfterString;
          [self sendString:[NSString stringWithFormat:@"%@%@%@", leftString, [string substringWithRange:NSMakeRange(0, charactersAvailableForString)], rightString] withAlignment:UITextAlignmentLeft verticalExpansion:verticalExpansion horizontalExpansion:horizontalExpansion inRed:isRed];
     }
     //(a lot of other code here that isn't relevant)
  }
  </code></pre>
  
  <p>It's crashing on the sendString method, because of a bad NSRange. I don't understand how this is possible given charactersLeftAfterString is necessarily less than 0 given the condition of the if statement, so charactersAvailableForString is always less than the string length, so how can the range be longer than the string length?</p>