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 | 86af98444f97da6fa33908de83dd1a28b341a835 (patch) | |
tree | 2235dacff4b8cf460bf0bbe90e50f82e7f71b525 /clang/lib/Basic/SourceManager.cpp | |
parent | e5255935d5a6909f80a08bedf34a8760828949dd (diff) | |
download | bcm5719-llvm-86af98444f97da6fa33908de83dd1a28b341a835.tar.gz bcm5719-llvm-86af98444f97da6fa33908de83dd1a28b341a835.zip |
Harden Lexer::GetBeginningOfToken() against bogus source locations and
the disappearance/alteration of files.
llvm-svn: 124616
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 409851f108c..e476cb2e299 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/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(); } |