]> granicus.if.org Git - clang/commitdiff
Check for an invalid SourceLocation in clang_getCursor(). This avoids a possible...
authorTed Kremenek <kremenek@apple.com>
Thu, 29 Jul 2010 00:52:07 +0000 (00:52 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 29 Jul 2010 00:52:07 +0000 (00:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109713 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndex.cpp

index 19107333ee3cf323b9d539da02bc5d4d57ae8d2f..1b3c6a2c73bcc3581efdd7e5a78dfe4cea989e64 100644 (file)
@@ -1838,12 +1838,17 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
     return clang_getNullCursor();
 
   ASTUnit *CXXUnit = static_cast<ASTUnit *>(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());