| 6749 | } |
| 6750 | |
| 6751 | void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value |
| 6752 | valueFlowUninit("struct wcsstruct {\n" |
| 6753 | " int *wcsprm;\n" |
| 6754 | "};\n" |
| 6755 | "\n" |
| 6756 | "void copy_wcs(wcsstruct *wcsin) {\n" |
| 6757 | " wcsstruct *x;\n" |
| 6758 | " memcpy(wcsin, x, sizeof(wcsstruct));\n" // <- warning |
| 6759 | " x->wcsprm = NULL;\n" // <- no warning |
| 6760 | "}"); |
| 6761 | ASSERT_EQUALS("[test.cpp:7:19]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); |
| 6762 | |
| 6763 | valueFlowUninit("struct wcsstruct {\n" |
| 6764 | " int *wcsprm;\n" |
| 6765 | "};\n" |
| 6766 | "\n" |
| 6767 | "void copy_wcs(wcsstruct *wcsin) {\n" |
| 6768 | " wcsstruct *x;\n" |
| 6769 | " sizeof(x);\n" |
| 6770 | " x->wcsprm = NULL;\n" // <- Warn |
| 6771 | "}"); |
| 6772 | ASSERT_EQUALS("[test.cpp:8:5]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); |
| 6773 | |
| 6774 | valueFlowUninit("struct wcsstruct {\n" |
| 6775 | " int *wcsprm;\n" |
| 6776 | "};\n" |
| 6777 | "\n" |
| 6778 | "void init_wcs(wcsstruct *x) { if (x->wcsprm != NULL); }\n" // <- no warning |
| 6779 | "\n" |
| 6780 | "void copy_wcs() {\n" |
| 6781 | " wcsstruct *x;\n" |
| 6782 | " x->wcsprm = NULL;\n" // <- warn here |
| 6783 | " init_wcs(x);\n" // <- no warning |
| 6784 | "}"); |
| 6785 | ASSERT_EQUALS("[test.cpp:9:5]: (error) Uninitialized variable: x [uninitvar]\n", errout_str()); |
| 6786 | } |
| 6787 | |
| 6788 | void uninitvar_ipa() { |
| 6789 | // #8825 |
nothing calls this directly
no test coverage detected