Skip to content

Commit

Permalink
Add tests for #4527, #10330 (#5734)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 7, 2023
1 parent 4538002 commit 785c537
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6306,6 +6306,34 @@ class TestUninitVar : public TestFixture {
" if ((b[0] = g()) == 0) {}\n"
"}");
ASSERT_EQUALS("", errout.str());

valueFlowUninit("void f(const char *x, char *y);\n" // #4527
"void g(char* b) {\n"
" char a[1000];\n"
" f(a, b);\n"
" printf(\"%s\", a);\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a\n", errout.str());

valueFlowUninit("void usage(const char *);\n" // #10330
"int main(int argc, char* argv[]) {\n"
" int user = 0;\n"
" struct passwd* pwd;\n"
" while (1) {\n"
" int c = getc();\n"
" if (c == -1)\n"
" break;\n"
" switch (c) {\n"
" case 'u': user = 123; break;\n"
" }\n"
" }\n"
" if (argc == 1)\n"
" usage(argv[0]);\n"
" if (user)\n"
" pwd = getpwnam(user);\n"
" if (pwd == NULL) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:15] -> [test.cpp:17]: (warning) Uninitialized variable: pwd\n", errout.str());
}

void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
Expand Down

0 comments on commit 785c537

Please sign in to comment.