diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-04-14 21:41:34 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-04-14 21:41:34 +0000 |
commit | 06d9b1ad0bca7230cbae57e3e3207dda77a9eac0 (patch) | |
tree | 9e93f058773b34ed30b187c0b79f430a8da655be | |
parent | 5da3c08728d3d1091f4f3fa01f9d813a45d150f5 (diff) |
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
-rw-r--r-- | tools/libclang/CIndex.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
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); |