Uninitvar: Moved testcases for avoiding extra warnings from TestValueFlow to TestUninitVar
This commit is contained in:
parent
08bc21199e
commit
eb50d19657
|
@ -86,6 +86,7 @@ private:
|
|||
TEST_CASE(syntax_error); // Ticket #5073
|
||||
TEST_CASE(trac_5970);
|
||||
TEST_CASE(valueFlowUninit);
|
||||
TEST_CASE(valueFlowUninitBreak);
|
||||
TEST_CASE(uninitvar_ipa);
|
||||
TEST_CASE(uninitvar_memberfunction);
|
||||
TEST_CASE(uninitvar_nonmember); // crash in ycmd test
|
||||
|
@ -4906,6 +4907,43 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
|
||||
valueFlowUninit("struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void copy_wcs(wcsstruct *wcsin) {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" memcpy(wcsin, x, sizeof(wcsstruct));\n" // <- warning
|
||||
" x->wcsprm = NULL;\n" // <- no warning
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
valueFlowUninit("struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void copy_wcs(wcsstruct *wcsin) {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" sizeof(x);\n"
|
||||
" x->wcsprm = NULL;\n" // <- Warn
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
valueFlowUninit("struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void init_wcs(wcsstruct *x) { if (x->wcsprm != NULL); }\n" // <- no warning
|
||||
"\n"
|
||||
"void copy_wcs() {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" x->wcsprm = NULL;\n" // <- warn here
|
||||
" init_wcs(x);\n" // <- no warning
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: x\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar_ipa() {
|
||||
// #8825
|
||||
valueFlowUninit("typedef struct {\n"
|
||||
|
|
|
@ -120,7 +120,6 @@ private:
|
|||
TEST_CASE(valueFlowSameExpression);
|
||||
|
||||
TEST_CASE(valueFlowUninit);
|
||||
TEST_CASE(valueFlowUninitBreak);
|
||||
|
||||
TEST_CASE(valueFlowConditionExpressions);
|
||||
|
||||
|
@ -4652,52 +4651,6 @@ private:
|
|||
ASSERT_EQUALS(0, values.size());
|
||||
}
|
||||
|
||||
void valueFlowUninitBreak() { // break uninit analysis to avoid extra warnings
|
||||
const char *code;
|
||||
std::list<ValueFlow::Value> values;
|
||||
|
||||
code = "struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void copy_wcs(wcsstruct *wcsin) {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" memcpy(wcsin, x, sizeof(wcsstruct));\n" // <- True positive
|
||||
" x->wcsprm = NULL;\n" // <- False positive
|
||||
"}";
|
||||
values = tokenValues(code, "x . wcsprm", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(0, values.size());
|
||||
|
||||
code = "struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void copy_wcs(wcsstruct *wcsin) {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" sizeof(x);\n"
|
||||
" x->wcsprm = NULL;\n" // <- Warn
|
||||
"}";
|
||||
values = tokenValues(code, "x . wcsprm", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(1, values.size());
|
||||
|
||||
code = "struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void init_wcs(wcsstruct *x) { if (x->wcsprm != NULL); }\n" // <- False positive
|
||||
"\n"
|
||||
"void copy_wcs() {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" x->wcsprm = NULL;\n" // <- True positive
|
||||
" init_wcs(x);\n" // <- False positive
|
||||
"}";
|
||||
values = tokenValues(code, "x . wcsprm != NULL", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(0, values.size());
|
||||
values = tokenValues(code, "x )", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(0, values.size());
|
||||
|
||||
}
|
||||
|
||||
void valueFlowConditionExpressions() {
|
||||
const char* code;
|
||||
|
||||
|
|
Loading…
Reference in New Issue