From 0f00e08422d452440660a7fa2bbccab1f8299939 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> Date: Mon, 13 Jul 2015 12:00:49 +0200 Subject: [PATCH] C++: Fix null pointer access for invalid code The code snippet provided in the bug report could not be parsed properly, thus Bind did not generate all expected symbols/names. The chunk in onConnectOrDisconnectCall() fixes the crash. The other chunks address triggered QTC_ASSERTs. Change-Id: Idf508b91b70659d38e59064d4922600f7b31daf8 Task-number: QTCREATORBUG-14709 Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com> --- src/plugins/cppeditor/cppquickfixes.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 082c45feb97..736638ef921 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -1832,7 +1832,7 @@ NameAST *nameUnderCursor(const QList<AST *> &path) bool canLookupDefinition(const CppQuickFixInterface &interface, const NameAST *nameAst) { - QTC_ASSERT(nameAst, return false); + QTC_ASSERT(nameAst && nameAst->name, return false); // Find the enclosing scope unsigned line, column; @@ -1909,7 +1909,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa QuickFixOperations &result) { const NameAST *nameAst = nameUnderCursor(interface.path()); - if (!nameAst) + if (!nameAst || !nameAst->name) return; if (canLookupDefinition(interface, nameAst)) @@ -5852,7 +5852,7 @@ bool onConnectOrDisconnectCall(AST *ast, const ExpressionListAST **arguments) return false; const IdExpressionAST *idExpr = call->base_expression->asIdExpression(); - if (!idExpr) + if (!idExpr || !idExpr->name || !idExpr->name->name) return false; const ExpressionListAST *args = call->expression_list; -- GitLab