From a6cb9f21be1aa41396943df2a93437ab843e983d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 6 Dec 2009 09:56:18 +0000 Subject: Fix an off by one in findEndOfWord, which could scan past the end of the string in a corner case. llvm-svn: 90703 --- clang/lib/Frontend/TextDiagnosticPrinter.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'clang') diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp index f8bb21ddee9..61f8a70ffff 100644 --- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp @@ -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 &Str, - unsigned Length, unsigned Column, - unsigned Columns) { +static unsigned findEndOfWord(unsigned Start, + const llvm::SmallVectorImpl &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]); -- cgit v1.2.3