From: Ted Kremenek Date: Thu, 29 Jul 2010 00:52:07 +0000 (+0000) Subject: Check for an invalid SourceLocation in clang_getCursor(). This avoids a possible... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a629ea42f6bc095190db2f3932b60a0be14f3d34;p=clang Check for an invalid SourceLocation in clang_getCursor(). This avoids a possible assertion failure in SourceManager in the call to Lexer::GetBeginningOfToken(). Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109713 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 19107333ee..1b3c6a2c73 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1838,12 +1838,17 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) { return clang_getNullCursor(); ASTUnit *CXXUnit = static_cast(TU); - ASTUnit::ConcurrencyCheck Check(*CXXUnit); // Translate the given source location to make it point at the beginning of // the token under the cursor. SourceLocation SLoc = cxloc::translateSourceLocation(Loc); + + // Guard against an invalid SourceLocation, or we may assert in one + // of the following calls. + if (SLoc.isInvalid()) + return clang_getNullCursor(); + SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(), CXXUnit->getASTContext().getLangOptions());