]> granicus.if.org Git - clang/commitdiff
Fix an off by one in findEndOfWord, which could scan past the end of the string in...
authorDaniel Dunbar <daniel@zuster.org>
Sun, 6 Dec 2009 09:56:18 +0000 (09:56 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 6 Dec 2009 09:56:18 +0000 (09:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90703 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/TextDiagnosticPrinter.cpp

index f8bb21ddee9f6dc23c61fbc93d9c48e45b02178e..61f8a70fffffedbfbb3145ccc255a7b4bbdc6e8f 100644 (file)
@@ -497,12 +497,17 @@ static inline char findMatchingPunctuation(char c) {
 ///
 /// \returns the index pointing one character past the end of the
 /// word.
-unsigned findEndOfWord(unsigned Start,
-                       const llvm::SmallVectorImpl<char> &Str,
-                       unsigned Length, unsigned Column,
-                       unsigned Columns) {
+static unsigned findEndOfWord(unsigned Start,
+                              const llvm::SmallVectorImpl<char> &Str,
+                              unsigned Length, unsigned Column,
+                              unsigned Columns) {
+  assert(Start < Str.size() && "Invalid start position!");
   unsigned End = Start + 1;
 
+  // If we are already at the end of the string, take that as the word.
+  if (End == Str.size())
+    return End;
+
   // Determine if the start of the string is actually opening
   // punctuation, e.g., a quote or parentheses.
   char EndPunct = findMatchingPunctuation(Str[Start]);