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