MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / uninitvar_ipa

Method uninitvar_ipa

test/testuninitvar.cpp:6788–7012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6786 }
6787
6788 void uninitvar_ipa() {
6789 // #8825
6790 valueFlowUninit("typedef struct {\n"
6791 " int flags;\n"
6792 "} someType_t;\n"
6793 "void bar(const someType_t * const p) {\n"
6794 " if( (p->flags & 0xF000) == 0xF000){}\n"
6795 "}\n"
6796 "void f(void) {\n"
6797 " someType_t gVar;\n"
6798 " bar(&gVar);\n"
6799 "}");
6800 ASSERT_EQUALS("[test.cpp:9:9]: (error) Uninitialized variable: &gVar [uninitvar]\n", errout_str());
6801
6802 valueFlowUninit("typedef struct\n"
6803 "{\n"
6804 " int flags[3];\n"
6805 "} someType_t;\n"
6806 "void f(void) {\n"
6807 " someType_t gVar;\n"
6808 " if(gVar.flags[1] == 42){}\n"
6809 "}");
6810 // TODO : find bugs for member arrays
6811 TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: gVar.flags\n", "", errout_str());
6812
6813 valueFlowUninit("void foo() {\n" // #10293
6814 " union {\n"
6815 " struct hdr cm;\n"
6816 " char control[123];\n"
6817 " } u;\n"
6818 " char *x = u.control;\n" // <- no error
6819 "}");
6820 ASSERT_EQUALS("", errout_str());
6821
6822 valueFlowUninit("struct pc_data {\n"
6823 " struct {\n"
6824 " char * strefa;\n"
6825 " } wampiryzm;\n"
6826 "};\n"
6827 "void f() {\n"
6828 " struct pc_data *pcdata;\n"
6829 " if ( *pcdata->wampiryzm.strefa == '\\0' ) { }\n"
6830 "}");
6831 ASSERT_EQUALS("[test.cpp:8:11]: (error) Uninitialized variable: pcdata [uninitvar]\n", errout_str());
6832
6833 // # 9293
6834 valueFlowUninit("struct S {\n"
6835 " int x;\n"
6836 " int y;\n"
6837 "};\n"
6838 "\n"
6839 "void f() {\n"
6840 " struct S s1;\n"
6841 " int * x = &s1.x;\n"
6842 " struct S s2 = {*x, 0};\n"
6843 "}");
6844 ASSERT_EQUALS("[test.cpp:9:20]: (error) Uninitialized variable: *x [uninitvar]\n", errout_str());
6845

Callers

nothing calls this directly

Calls 1

valueFlowUninitFunction · 0.85

Tested by

no test coverage detected