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/Basic/SourceManager.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/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 409851f108..e476cb2e29 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -531,12 +531,21 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile, llvm::StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { bool MyInvalid = false; - const llvm::MemoryBuffer *Buf = getBuffer(FID, &MyInvalid); + const SLocEntry &SLoc = getSLocEntry(FID.ID); + if (!SLoc.isFile()) { + if (Invalid) + *Invalid = true; + return "<<<<<INVALID SOURCE LOCATION>>>>>"; + } + + const llvm::MemoryBuffer *Buf + = SLoc.getFile().getContentCache()->getBuffer(Diag, *this, SourceLocation(), + &MyInvalid); if (Invalid) *Invalid = MyInvalid; if (MyInvalid) - return ""; + return "<<<<<INVALID SOURCE LOCATION>>>>>"; return Buf->getBuffer(); } |