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>
This commit is contained in:
Nikolai Kosjar
2015-07-13 12:00:49 +02:00
parent bb549770a8
commit 0f00e08422

View File

@@ -1832,7 +1832,7 @@ NameAST *nameUnderCursor(const QList<AST *> &path)
bool canLookupDefinition(const CppQuickFixInterface &interface, const NameAST *nameAst) bool canLookupDefinition(const CppQuickFixInterface &interface, const NameAST *nameAst)
{ {
QTC_ASSERT(nameAst, return false); QTC_ASSERT(nameAst && nameAst->name, return false);
// Find the enclosing scope // Find the enclosing scope
unsigned line, column; unsigned line, column;
@@ -1909,7 +1909,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
QuickFixOperations &result) QuickFixOperations &result)
{ {
const NameAST *nameAst = nameUnderCursor(interface.path()); const NameAST *nameAst = nameUnderCursor(interface.path());
if (!nameAst) if (!nameAst || !nameAst->name)
return; return;
if (canLookupDefinition(interface, nameAst)) if (canLookupDefinition(interface, nameAst))
@@ -5852,7 +5852,7 @@ bool onConnectOrDisconnectCall(AST *ast, const ExpressionListAST **arguments)
return false; return false;
const IdExpressionAST *idExpr = call->base_expression->asIdExpression(); const IdExpressionAST *idExpr = call->base_expression->asIdExpression();
if (!idExpr) if (!idExpr || !idExpr->name || !idExpr->name->name)
return false; return false;
const ExpressionListAST *args = call->expression_list; const ExpressionListAST *args = call->expression_list;