Skip to content

Commit

Permalink
Fix danmar#4478: FP: Uninitialized variable (danmar#6493)
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Jun 8, 2024
1 parent f1ddd1a commit 3e54980
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3415,6 +3415,8 @@ ExprUsage getExprUsage(const Token* tok, int indirect, const Settings& settings)
if (isUsedAsBool(tok, settings))
return ExprUsage::NotUsed;
}
if (tok->isUnaryOp("&") && !parent)
return ExprUsage::NotUsed;
if (indirect == 0) {
if (Token::Match(parent, "%cop%|%assign%|++|--") && parent->str() != "=" &&
!parent->isUnaryOp("&") &&
Expand Down
2 changes: 1 addition & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4304,7 +4304,7 @@ class TestUninitVar : public TestFixture {
" long a;\n"
" &a;\n"
"}");
TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Uninitialized variable: &a\n", errout_str());
ASSERT_EQUALS("", errout_str());

valueFlowUninit("void f() {\n" // #4717 - ({})
" int a = ({ long b = (long)(123); 2 + b; });\n"
Expand Down

0 comments on commit 3e54980

Please sign in to comment.