diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-06 09:56:18 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-06 09:56:18 +0000 |
commit | a6cb9f21be1aa41396943df2a93437ab843e983d (patch) | |
tree | 141460c96bd22d754796aa6c9496ba97a287a78c /clang | |
parent | eddf1213e2ae7c163870108da5b088c0039af3ce (diff) | |
download | bcm5719-llvm-a6cb9f21be1aa41396943df2a93437ab843e983d.tar.gz bcm5719-llvm-a6cb9f21be1aa41396943df2a93437ab843e983d.zip |
Fix an off by one in findEndOfWord, which could scan past the end of the string in a corner case.
llvm-svn: 90703
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Frontend/TextDiagnosticPrinter.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
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<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]); |