diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-01-31 22:42:36 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-01-31 22:42:36 +0000 |
commit | 3de84241d90f3dd280126fdf2c4651667151c967 (patch) | |
tree | e769d73be9f44876182fcd2418373133e440eb68 /lib/Lex/Lexer.cpp | |
parent | b6cfa24fe6c7a27e9bbaebc0cd28c857d11d6060 (diff) |
Harden Lexer::GetBeginningOfToken() against bogus source locations and
the disappearance/alteration of files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 5d9536f40d..7c94528c64 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -357,6 +357,9 @@ SourceLocation Lexer::GetBeginningOfToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts) { std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc); + if (LocInfo.first.isInvalid()) + return Loc; + bool Invalid = false; llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); if (Invalid) @@ -365,6 +368,9 @@ SourceLocation Lexer::GetBeginningOfToken(SourceLocation Loc, // Back up from the current location until we hit the beginning of a line // (or the buffer). We'll relex from that point. const char *BufStart = Buffer.data(); + if (LocInfo.second >= Buffer.size()) + return Loc; + const char *StrData = BufStart+LocInfo.second; if (StrData[0] == '\n' || StrData[0] == '\r') return Loc; |