From 67a8ff0b27c30803313229263ff0f96d55a7d1f6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 20 Apr 2023 12:58:50 +0200 Subject: [PATCH] Add tests for # 6561, #6619, #7475 (#4988) * Add tests for #6925, #11042, #11494 * Format * Add tests for # 6561, #6619, #7475, --- test/testuninitvar.cpp | 21 +++++++++++++++++++++ test/testunusedvar.cpp | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b6e116a27..d08cd174d 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -5968,6 +5968,27 @@ private: " if (a[0]) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #6619 + valueFlowUninit("void f() {\n" + " int nok, i;\n" + " for (i = 1; i < 5; i++) {\n" + " if (i == 8)\n" + " nok = 8;\n" + " }\n" + " printf(\"nok = %d\\n\", nok);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:7]: (warning) Uninitialized variable: nok\n", errout.str()); + + // #7475 + valueFlowUninit("struct S {\n" + " int a, b, c;\n" + "} typedef s_t;\n" + "void f() {\n" + " s_t s;\n" + " printf(\"%d\", s.a);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s.a\n", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index d19c2eef3..c2405013f 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1640,6 +1640,14 @@ private: "\n" "input.skip(sizeof(struct Header));"); ASSERT_EQUALS("", errout.str()); + + checkStructMemberUsage("struct S { int a, b, c; };\n" // #6561 + "int f(FILE * fp) {\n" + " S s;\n" + " ::fread(&s, sizeof(S), 1, fp);\n" + " return s.b;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void structmember16() {