From f0bf7496211c6b9ddea69a7392afdf4d1875a610 Mon Sep 17 00:00:00 2001 From: amai2012 Date: Sun, 15 Nov 2015 19:01:29 +0100 Subject: [PATCH] #7133 crash: Variable::declarationId(). --- lib/checkother.cpp | 5 +++-- test/testother.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index aef09625e..289bf5cb1 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -467,7 +467,7 @@ static bool checkExceptionHandling(const Token* tok) while (upperScope && upperScope->type != Scope::eTry && upperScope->type != Scope::eLambda && (!var || upperScope->nestedIn != var->scope()) && upperScope->isExecutable()) { upperScope = upperScope->nestedIn; } - if (upperScope && upperScope->type == Scope::eTry) { + if (var && upperScope && upperScope->type == Scope::eTry) { // Check all exception han const Token* tok2 = upperScope->classEnd; while (Token::simpleMatch(tok2, "} catch (")) { @@ -561,7 +561,8 @@ void CheckOther::checkRedundantAssignment() if (printWarning && scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok)) redundantAssignmentInSwitchError(it->second, tok, tok->str()); else if (printPerformance) { - const bool nonlocal = nonLocal(it->second->variable()); + // See #7133 + const bool nonlocal = it->second->variable() && nonLocal(it->second->variable()); if (printInconclusive || !nonlocal) // see #5089 - report inconclusive only when requested if (_tokenizer->isC() || checkExceptionHandling(tok)) // see #6555 to see how exception handling might have an impact redundantAssignmentError(it->second, tok, tok->str(), nonlocal); // Inconclusive for non-local variables diff --git a/test/testother.cpp b/test/testother.cpp index e2949df83..70189baf3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -148,6 +148,7 @@ private: TEST_CASE(incompleteArrayFill); TEST_CASE(redundantVarAssignment); + TEST_CASE(redundantVarAssignment_7133); TEST_CASE(redundantMemWrite); TEST_CASE(varFuncNullUB); @@ -5617,7 +5618,30 @@ private: " if (memptr)\n" " memptr = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'memptr' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Variable 'memptr' is reassigned a value before the old one has been used.\n", errout.str()); + } + + void redundantVarAssignment_7133() { + // #7133 + check("sal_Int32 impl_Export() {\n" + " try {\n" + " try {\n" + " uno::Sequence< uno::Any > aArgs(2);\n" + " beans::NamedValue aValue;\n" + " aValue.Name = \"DocumentHandler\";\n" + " aValue.Value <<= xDocHandler;\n" + " aArgs[0] <<= aValue;\n" + " aValue.Name = \"Model\";\n" + " aValue.Value <<= xDocumentComp;\n" + " aArgs[1] <<= aValue;\n" + " }\n" + " catch (const uno::Exception&) {\n" + " }\n" + " }\n" + " catch (const uno::Exception&) {\n" + " }\n" + "}", "test.cpp", false, true); + ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:9]: (performance) Variable 'Name' is reassigned a value before the old one has been used.\n", errout.str()); } void redundantMemWrite() {