#7133 crash: Variable::declarationId().

This commit is contained in:
amai2012 2015-11-15 19:01:29 +01:00
parent ca8b15cd6b
commit f0bf749621
2 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -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() {