| 3689 | } |
| 3690 | |
| 3691 | void valueFlowUninit2_value() |
| 3692 | { |
| 3693 | valueFlowUninit("void f() {\n" |
| 3694 | " int i;\n" |
| 3695 | " if (x) {\n" |
| 3696 | " int y = -ENOMEM;\n" // assume constant ENOMEM is nonzero since it's negated |
| 3697 | " if (y != 0) return;\n" |
| 3698 | " i++;\n" |
| 3699 | " }\n" |
| 3700 | "}"); |
| 3701 | ASSERT_EQUALS("", errout_str()); |
| 3702 | |
| 3703 | valueFlowUninit("void f() {\n" |
| 3704 | " int i, y;\n" |
| 3705 | " if (x) {\n" |
| 3706 | " y = -ENOMEM;\n" // assume constant ENOMEM is nonzero since it's negated |
| 3707 | " if (y != 0) return;\n" |
| 3708 | " i++;\n" |
| 3709 | " }\n" |
| 3710 | "}"); |
| 3711 | ASSERT_EQUALS("", errout_str()); |
| 3712 | |
| 3713 | valueFlowUninit("void f() {\n" |
| 3714 | " int i, y;\n" |
| 3715 | " if (x) y = -ENOMEM;\n" // assume constant ENOMEM is nonzero since it's negated |
| 3716 | " else y = get_value(i);\n" |
| 3717 | " if (y != 0) return;\n" // <- condition is always true if i is uninitialized |
| 3718 | " i++;\n" |
| 3719 | "}"); |
| 3720 | ASSERT_EQUALS("", errout_str()); |
| 3721 | |
| 3722 | valueFlowUninit("void f(int x) {\n" |
| 3723 | " int i;\n" |
| 3724 | " if (!x) i = 0;\n" |
| 3725 | " if (!x || i>0) {}\n" // <- error |
| 3726 | "}"); |
| 3727 | ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:4:15]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); |
| 3728 | |
| 3729 | valueFlowUninit("void f(int x) {\n" |
| 3730 | " int i;\n" |
| 3731 | " if (x) i = 0;\n" |
| 3732 | " if (!x || i>0) {}\n" // <- no error |
| 3733 | "}"); |
| 3734 | ASSERT_EQUALS("", errout_str()); |
| 3735 | |
| 3736 | valueFlowUninit("void f(int x) {\n" |
| 3737 | " int i;\n" |
| 3738 | " if (!x) { }\n" |
| 3739 | " else i = 0;\n" |
| 3740 | " if (x || i>0) {}\n" |
| 3741 | "}"); |
| 3742 | ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:14]: (warning) Uninitialized variable: i [uninitvar]\n", errout_str()); |
| 3743 | |
| 3744 | valueFlowUninit("void f(int x) {\n" |
| 3745 | " int i;\n" |
| 3746 | " if (x) { }\n" |
| 3747 | " else i = 0;\n" |
| 3748 | " if (x || i>0) {}\n" // <- no error |
nothing calls this directly
no test coverage detected