diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-03-01 03:26:00 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-03-01 03:26:00 +0000 |
commit | 7db4bb9226f303392934c91869afdeb4d153ca95 (patch) | |
tree | db94f54cdc6c000f8180e8c2a2258b0e8c367e7b /lib/Basic/SourceManager.cpp | |
parent | 4a68c7bc86bcaf44f6aee5a470c743b47c11716e (diff) |
In SourceManager::getFileIDLoaded(), add some sanity checks to make sure we don't enter an infinite loop.
rdar://13120919
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176331 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index ea9565006c..8fa648c730 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -840,10 +840,17 @@ FileID SourceManager::getFileIDLoaded(unsigned SLocOffset) const { ++NumProbes; unsigned MiddleIndex = (LessIndex - GreaterIndex) / 2 + GreaterIndex; const SrcMgr::SLocEntry &E = getLoadedSLocEntry(MiddleIndex); + if (E.getOffset() == 0) + return FileID(); // invalid entry. ++NumProbes; if (E.getOffset() > SLocOffset) { + // Sanity checking, otherwise a bug may lead to hanging in release build. + if (GreaterIndex == MiddleIndex) { + assert(0 && "binary search missed the entry"); + return FileID(); + } GreaterIndex = MiddleIndex; continue; } |