[cfe-commits] r109713 - /cfe/trunk/tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Wed Jul 28 17:52:07 PDT 2010


Author: kremenek
Date: Wed Jul 28 19:52:07 2010
New Revision: 109713

URL: http://llvm.org/viewvc/llvm-project?rev=109713&view=rev
Log:
Check for an invalid SourceLocation in clang_getCursor().  This avoids a possible assertion failure in SourceManager in the call to Lexer::GetBeginningOfToken().  Fixes <rdar://problem/8244873>.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=109713&r1=109712&r2=109713&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Jul 28 19:52:07 2010
@@ -1838,12 +1838,17 @@
     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());
   





More information about the cfe-commits mailing list