]> granicus.if.org Git - clang/commitdiff
Harden Clang's cursor visitation logic against NULL declaration,
authorDouglas Gregor <dgregor@apple.com>
Thu, 14 Apr 2011 21:41:34 +0000 (21:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 14 Apr 2011 21:41:34 +0000 (21:41 +0000)
statement, and expression pointers. While these shouldn't happen, it's
better to be safe in libclang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129539 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndex.cpp

index 80fc7551d7f7717cc5593ecb1b529df42738a828..0aba04a48c6f3f3cff370939c0c55e13a38e37a9 100644 (file)
@@ -494,14 +494,25 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) {
 
   if (clang_isDeclaration(Cursor.kind)) {
     Decl *D = getCursorDecl(Cursor);
-    assert(D && "Invalid declaration cursor");
+    if (!D)
+      return false;
+
     return VisitAttributes(D) || Visit(D);
   }
 
-  if (clang_isStatement(Cursor.kind))
-    return Visit(getCursorStmt(Cursor));
-  if (clang_isExpression(Cursor.kind))
-    return Visit(getCursorExpr(Cursor));
+  if (clang_isStatement(Cursor.kind)) {
+    if (Stmt *S = getCursorStmt(Cursor))
+      return Visit(S);
+
+    return false;
+  }
+
+  if (clang_isExpression(Cursor.kind)) {
+    if (Expr *E = getCursorExpr(Cursor))
+      return Visit(E);
+
+    return false;
+  }
 
   if (clang_isTranslationUnit(Cursor.kind)) {
     CXTranslationUnit tu = getCursorTU(Cursor);