CppEditor: Fix possible crash in CompleteSwitchCaseStatement

There can be an unexpected null pointer if the built-in code model fails
to parse the code properly.

Fixes: QTCREATORBUG-26316
Change-Id: I5751be505b1182df17f58e1a174d645cef1e95cf
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-10-13 14:41:31 +02:00
parent 38b97b404a
commit 6dd66e012b

View File

@@ -2483,7 +2483,7 @@ void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface,
AST *ast = path.at(depth);
SwitchStatementAST *switchStatement = ast->asSwitchStatement();
if (switchStatement) {
if (!switchStatement->statement)
if (!switchStatement->statement || !switchStatement->symbol)
return;
CompoundStatementAST *compoundStatement = switchStatement->statement->asCompoundStatement();
if (!compoundStatement) // we ignore pathologic case "switch (t) case A: ;"