From 6dd66e012b49f634541457aafffc2367e91d95e7 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 13 Oct 2021 14:41:31 +0200 Subject: [PATCH] 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 --- src/plugins/cppeditor/cppquickfixes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 8b9fdce1908..91974761c28 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -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: ;"