Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ const Token* CheckUninitVar::isVariableUsage(bool cpp, const Token *vartok, cons
}
if (Token::simpleMatch(tok->astParent(), "=")) {
if (astIsLhs(tok)) {
if (alloc == ARRAY || !derefValue || !derefValue->isUnaryOp("*"))
if (alloc == ARRAY || !derefValue || !derefValue->isUnaryOp("*") || !pointer)
return nullptr;
const Token* deref = derefValue->astOperand1();
while (deref && deref->isCast())
Expand Down
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const

// assignment
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;
while (eq && !eq->isAssignmentOp())
eq = eq->astParent();
Expand Down
10 changes: 10 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TestUninitVar : public TestFixture {
TEST_CASE(uninitvar11); // ticket #9123
TEST_CASE(uninitvar12); // #10218 - stream read
TEST_CASE(uninitvar13); // #9772
TEST_CASE(uninitvar14);
TEST_CASE(uninitvar_unconditionalTry);
TEST_CASE(uninitvar_funcptr); // #6404
TEST_CASE(uninitvar_operator); // #6680
Expand Down Expand Up @@ -3126,6 +3127,15 @@ class TestUninitVar : public TestFixture {
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() {
// Unconditional scopes and try{} scopes
checkUninitVar("int f() {\n"
Expand Down
6 changes: 6 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2640,6 +2640,12 @@ class TestUnusedVar : public TestFixture {
" *(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());

functionVariableUsage("void f() {\n" // #11832
" int b;\n"
" *(&b) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void localvar8() {
Expand Down