This commit is contained in:
chrchr-github 2023-12-07 12:16:53 +01:00 committed by GitHub
parent 453800211c
commit 785c537ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 0 deletions

View File

@ -6306,6 +6306,34 @@ private:
" 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