Skip to content
Open
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 @@ -906,7 +906,7 @@ bool CheckUninitVar::checkIfForWhileHead(const Token *startparentheses, const Va
continue;
uninitvarError(errorToken, errorToken->expressionString(), alloc);
}
return true;
return !Token::Match(tok->astParent(), "!|%comp%");
}
// skip sizeof / offsetof
if (isUnevaluated(tok))
Expand Down
20 changes: 19 additions & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ class TestUninitVar : public TestFixture {
" return;\n"
" char c = *s;\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Memory is allocated but not initialized: s\n", "", errout_str());
ASSERT_EQUALS("[test.cpp:6:15]: (error) Memory is allocated but not initialized: s [uninitdata]\n", errout_str());

// #3708 - false positive when using ptr typedef
checkUninitVar("void f() {\n"
Expand Down Expand Up @@ -2139,6 +2139,24 @@ class TestUninitVar : public TestFixture {
" *(p + i) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

checkUninitVar("int* f() {\n" // #14448
" int* p = (int*)malloc(4);\n"
" if (!p)\n"
" return nullptr;\n"
" if (*p) {}\n"
" return p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5:9]: (error) Memory is allocated but not initialized: *p [uninitdata]\n", errout_str());

checkUninitVar("int* f() {\n"
" int* p = (int*)malloc(4);\n"
" if (p == nullptr)\n"
" return nullptr;\n"
" if (*p) {}\n"
" return p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5:9]: (error) Memory is allocated but not initialized: *p [uninitdata]\n", errout_str());
}

// class / struct..
Expand Down
Loading