Added regression test for #4816

Ran AStyle
This commit is contained in:
PKEuS 2015-07-23 20:53:50 +02:00
parent 795e5de903
commit e95800bed4
2 changed files with 2103 additions and 2089 deletions

View File

@ -72,6 +72,7 @@ private:
TEST_CASE(eraseAssignByFunctionCall);
TEST_CASE(eraseErase);
TEST_CASE(eraseByValue);
TEST_CASE(eraseIf);
TEST_CASE(eraseOnVector);
TEST_CASE(pushback1);
@ -1037,6 +1038,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void eraseIf() {
// #4816
check("void func(std::list<std::string> strlist) {\n"
" for (std::list<std::string>::iterator str = strlist.begin(); str != strlist.end(); str++) {\n"
" if (func2(*str)) {\n"
" strlist.erase(str);\n"
" if (strlist.empty())\n"
" return;\n"
" }\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Iterator 'str' used after element has been erased.\n", errout.str());
}
void eraseOnVector() {
check("void f(const std::vector<int>& m_ImplementationMap) {\n"

View File

@ -1667,7 +1667,7 @@ private:
"int f() {\n"
" int x;\n"
" return setvalue(x);\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
}
@ -1680,7 +1680,7 @@ private:
" f = 0.0;\n"
" }\n"
" printf (\"%f\",f);\n"
"}\n");
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: f\n", errout.str());
// Check for potential FP
@ -1691,7 +1691,7 @@ private:
" f = 0.0;\n"
" }\n"
" printf (\"%f\",f);\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
}
@ -2610,7 +2610,7 @@ private:
checkUninitVar("void f() {\n" // #4778 - cast address of uninitialized variable
" long a;\n"
" &a;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n" // #4717 - ({})
@ -2773,7 +2773,7 @@ private:
" Sink s2;\n"
" int n;\n"
" foo >> s2.v >> n;\n" // Initialized by operator>>
"}\n");
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized struct member: s.v\n", errout.str());
checkUninitVar("struct Fred { int a; };\n"
@ -2996,7 +2996,7 @@ private:
" if (x)\n"
" a = p;\n"
" return x ? 2*a : 0;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int f(int x) {\n"
@ -3004,13 +3004,13 @@ private:
" if (x)\n"
" a = p;\n"
" return y ? 2*a : 3*a;\n"
"}\n");
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("void f() {\n" // Don't crash
" int a;\n"
" dostuff(\"ab\" cd \"ef\", x?a:z);\n" // <- No AST is created for ?:
"}\n");
"}");
// Unknown => bail out..
checkUninitVar("void f(int x) {\n"
@ -3255,7 +3255,7 @@ private:
" struct PIXEL p1;\n"
" p1.color = 255;\n"
" return p1.red;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("struct AB { int a; int b; };\n"
@ -3531,7 +3531,7 @@ private:
" }\n"
" }\n"
" return x;\n"
"}\n");
"}");
TODO_ASSERT_EQUALS("error", "", errout.str());
checkUninitVar("int f(void) {\n"
@ -3542,7 +3542,7 @@ private:
" }\n"
" }\n"
" return 0;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f(void) {\n"
@ -3709,31 +3709,31 @@ private:
" struct t_udf_file *newf;\n"
" newf = malloc(sizeof(*newf));\n"
" if (!newf) return 0;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n"
" char *s = malloc(100);\n"
" if (s != NULL) { }\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n"
" char *s = malloc(100);\n"
" *s = x;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n"
" char *p = malloc(100);\n"
" p || assert_failed();\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n"
" char *p = malloc(100);\n"
" x = p;\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
// function parameter (treat it as initialized until malloc is used)
@ -3763,7 +3763,7 @@ private:
// analysis failed. varid 0.
checkUninitVar("void *vlc_custom_create (vlc_object_t *parent, size_t length, const char *typename) {\n"
" assert (length >= sizeof (vlc_object_t));\n"
"}\n");
"}");
ASSERT_EQUALS("", errout.str());
}