From: Douglas Gregor Date: Thu, 14 Apr 2011 21:41:34 +0000 (+0000) Subject: Harden Clang's cursor visitation logic against NULL declaration, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06d9b1ad0bca7230cbae57e3e3207dda77a9eac0;p=clang Harden Clang's cursor visitation logic against NULL declaration, 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 --- diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 80fc7551d7..0aba04a48c 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -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);