From 7dc4f33c77acd90b3217b94e50965bbcefbcd55f Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 1 Mar 2013 03:26:00 +0000 Subject: In SourceManager::getFileIDLoaded(), add some sanity checks to make sure we don't enter an infinite loop. rdar://13120919 llvm-svn: 176331 --- clang/lib/Basic/SourceManager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'clang/lib/Basic/SourceManager.cpp') diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index ea95650..8fa648c 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/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; } -- cgit v1.1