Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for #4527, #10330 #5734

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
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
Loading