This commit is contained in:
parent
a4a29bfbc5
commit
72212331fb
|
@ -1248,7 +1248,7 @@ const Token* CheckUninitVar::isVariableUsage(bool cpp, const Token *vartok, cons
|
||||||
}
|
}
|
||||||
if (Token::simpleMatch(tok->astParent(), "=")) {
|
if (Token::simpleMatch(tok->astParent(), "=")) {
|
||||||
if (astIsLhs(tok)) {
|
if (astIsLhs(tok)) {
|
||||||
if (alloc == ARRAY || !derefValue || !derefValue->isUnaryOp("*"))
|
if (alloc == ARRAY || !derefValue || !derefValue->isUnaryOp("*") || !pointer)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
const Token* deref = derefValue->astOperand1();
|
const Token* deref = derefValue->astOperand1();
|
||||||
while (deref && deref->isCast())
|
while (deref && deref->isCast())
|
||||||
|
|
|
@ -1009,7 +1009,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
|
|
||||||
// assignment
|
// assignment
|
||||||
else if ((Token::Match(tok, "%name% [") && Token::simpleMatch(skipBracketsAndMembers(tok->next()), "=")) ||
|
else if ((Token::Match(tok, "%name% [") && Token::simpleMatch(skipBracketsAndMembers(tok->next()), "=")) ||
|
||||||
(Token::simpleMatch(tok, "* (") && Token::simpleMatch(tok->next()->link(), ") ="))) {
|
(tok->isUnaryOp("*") && Token::simpleMatch(tok->astParent(), "=") && Token::simpleMatch(tok->astOperand1(), "+"))) {
|
||||||
const Token *eq = tok;
|
const Token *eq = tok;
|
||||||
while (eq && !eq->isAssignmentOp())
|
while (eq && !eq->isAssignmentOp())
|
||||||
eq = eq->astParent();
|
eq = eq->astParent();
|
||||||
|
|
|
@ -75,6 +75,7 @@ private:
|
||||||
TEST_CASE(uninitvar11); // ticket #9123
|
TEST_CASE(uninitvar11); // ticket #9123
|
||||||
TEST_CASE(uninitvar12); // #10218 - stream read
|
TEST_CASE(uninitvar12); // #10218 - stream read
|
||||||
TEST_CASE(uninitvar13); // #9772
|
TEST_CASE(uninitvar13); // #9772
|
||||||
|
TEST_CASE(uninitvar14);
|
||||||
TEST_CASE(uninitvar_unconditionalTry);
|
TEST_CASE(uninitvar_unconditionalTry);
|
||||||
TEST_CASE(uninitvar_funcptr); // #6404
|
TEST_CASE(uninitvar_funcptr); // #6404
|
||||||
TEST_CASE(uninitvar_operator); // #6680
|
TEST_CASE(uninitvar_operator); // #6680
|
||||||
|
@ -3126,6 +3127,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninitvar14() { // #11832
|
||||||
|
const char code[] = "void f() {\n"
|
||||||
|
" int b;\n"
|
||||||
|
" *(&b) = 0;\n"
|
||||||
|
"}";
|
||||||
|
checkUninitVar(code);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void uninitvar_unconditionalTry() {
|
void uninitvar_unconditionalTry() {
|
||||||
// Unconditional scopes and try{} scopes
|
// Unconditional scopes and try{} scopes
|
||||||
checkUninitVar("int f() {\n"
|
checkUninitVar("int f() {\n"
|
||||||
|
|
|
@ -2640,6 +2640,12 @@ private:
|
||||||
" *(b+i) = 0;\n"
|
" *(b+i) = 0;\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable '*(b+i)' is assigned a value that is never used.\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable '*(b+i)' is assigned a value that is never used.\n", "", errout.str());
|
||||||
|
|
||||||
|
functionVariableUsage("void f() {\n" // #11832
|
||||||
|
" int b;\n"
|
||||||
|
" *(&b) = 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvar8() {
|
void localvar8() {
|
||||||
|
|
Loading…
Reference in New Issue