summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-01-31 22:42:36 +0000
committerDouglas Gregor <dgregor@apple.com>2011-01-31 22:42:36 +0000
commit86af98444f97da6fa33908de83dd1a28b341a835 (patch)
tree2235dacff4b8cf460bf0bbe90e50f82e7f71b525 /clang/lib/Basic/SourceManager.cpp
parente5255935d5a6909f80a08bedf34a8760828949dd (diff)
downloadbcm5719-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.cpp13
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();
}
OpenPOWER on IntegriCloud