aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-08-18 10:46:57 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-08-18 09:44:40 +0000
commit45778539d8424a8556ce074020b992a248d6455f (patch)
tree2b49d4fa6b5e0000f0997ddd20a42224853331c8
parentbf6e9f05502bb8711a3787ac04f82f4bfb3e4559 (diff)
CppEditor: Fix crash with invalid switch/case statement
Task-number: QTCREATORBUG-14925 Change-Id: Iea2cf17070d9db48924e76f6c7febca0d52e4686 Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp15
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp12
2 files changed, 22 insertions, 5 deletions
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index cbc04f6a67..962afeddd0 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -514,6 +514,21 @@ void CppEditorPlugin::test_quickfix_data()
"}\n"
);
+ // Checks: Do not crash on incomplete case statetement.
+ QTest::newRow("CompleteSwitchCaseStatement_doNotCrashOnIncompleteCase")
+ << CppQuickFixFactoryPtr(new CompleteSwitchCaseStatement) << _(
+ "enum E {};\n"
+ "void f(E o)\n"
+ "{\n"
+ " @switch (o)\n"
+ " {\n"
+ " case\n"
+ " }\n"
+ "}\n"
+ ) << _(
+ ""
+ );
+
// Checks:
// 1. If the name does not start with ("m_" or "_") and does not
// end with "_", we are forced to prefix the getter with "get".
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index 736638ef92..28d711cf8e 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -2212,11 +2212,13 @@ public:
bool preVisit(AST *ast) {
if (CaseStatementAST *cs = ast->asCaseStatement()) {
foundCaseStatementLevel = true;
- if (ExpressionAST *expression = cs->expression->asIdExpression()) {
- QList<LookupItem> candidates = typeOfExpression(expression, document, scope);
- if (!candidates .isEmpty() && candidates.first().declaration()) {
- Symbol *decl = candidates.first().declaration();
- values << prettyPrint.prettyName(LookupContext::fullyQualifiedName(decl));
+ if (ExpressionAST *csExpression = cs->expression) {
+ if (ExpressionAST *expression = csExpression->asIdExpression()) {
+ QList<LookupItem> candidates = typeOfExpression(expression, document, scope);
+ if (!candidates .isEmpty() && candidates.first().declaration()) {
+ Symbol *decl = candidates.first().declaration();
+ values << prettyPrint.prettyName(LookupContext::fullyQualifiedName(decl));
+ }
}
}
return true;