testuninitvar: use new checking instead of executionpath in various testcases
This commit is contained in:
parent
1de1aaa2f4
commit
239f0d4ab4
|
@ -139,26 +139,26 @@ private:
|
|||
|
||||
void uninitvar1() {
|
||||
// Ticket #2207 - False negative
|
||||
checkUninitVar("void foo() {\n"
|
||||
checkUninitVar2("void foo() {\n"
|
||||
" int a;\n"
|
||||
" b = c - a;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("void foo() {\n"
|
||||
checkUninitVar2("void foo() {\n"
|
||||
" int a;\n"
|
||||
" b = a - c;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
// Ticket #6455 - some compilers allow const variables to be uninitialized
|
||||
checkUninitVar("void foo() {\n"
|
||||
checkUninitVar2("void foo() {\n"
|
||||
" const int a;\n"
|
||||
" b = c - a;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("void foo() {\n"
|
||||
checkUninitVar2("void foo() {\n"
|
||||
" int *p;\n"
|
||||
" realloc(p,10);\n"
|
||||
"}");
|
||||
|
@ -178,63 +178,63 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// dereferencing uninitialized pointer..
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" Foo *p;\n"
|
||||
" p->abcd();\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" Foo<int> *p;\n"
|
||||
" p->abcd();\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
checkUninitVar("void f(Foo *p)\n"
|
||||
checkUninitVar2("void f(Foo *p)\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" p->a = malloc(4 * a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
" delete p;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
" delete [] p;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
" *p = 135;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
" p[0] = 135;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int *x;\n"
|
||||
" int y = *x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int *x;\n"
|
||||
" int &y(*x);\n"
|
||||
|
@ -261,14 +261,14 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f()\n"
|
||||
checkUninitVar2("void f()\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" a = 5 + a;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("void f()\n"
|
||||
checkUninitVar2("void f()\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
|
@ -282,35 +282,35 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f()\n"
|
||||
checkUninitVar2("void f()\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" bar(4 * a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
" if (i);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
" for (int x = 0; i < 10; x++);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
" for (int x = 0; x < 10; i++);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar("static int foo(int x)\n"
|
||||
checkUninitVar2("static int foo(int x)\n"
|
||||
"{\n"
|
||||
" int i;\n"
|
||||
" if (x)\n"
|
||||
|
@ -319,7 +319,7 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: i\n", errout.str());
|
||||
|
||||
checkUninitVar("static void foo()\n"
|
||||
checkUninitVar2("static void foo()\n"
|
||||
"{\n"
|
||||
" int ar[10];\n"
|
||||
" int i;\n"
|
||||
|
@ -342,17 +342,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #3597
|
||||
checkUninitVar("int f() {\n"
|
||||
checkUninitVar2("int f() {\n"
|
||||
" int a;\n"
|
||||
" int b = 1;\n"
|
||||
" (b += a) = 1;\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n","", errout.str());
|
||||
|
||||
checkUninitVar("int f() {\n"
|
||||
checkUninitVar2("int f() {\n"
|
||||
" int a,b,c;\n"
|
||||
" a = b = c;\n"
|
||||
"}");
|
||||
"}", "test.cpp", /*verify=*/ false);
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n", "", errout.str());
|
||||
|
||||
checkUninitVarB("static void foo()\n"
|
||||
|
@ -442,10 +442,9 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("int a() {\n"
|
||||
checkUninitVar2("int a() {\n"
|
||||
" int ret;\n"
|
||||
" int a = value >> ret;\n"
|
||||
" ret++;\n"
|
||||
"}\n",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout.str());
|
||||
|
@ -464,10 +463,9 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("int a() {\n"
|
||||
checkUninitVar2("void a() {\n"
|
||||
" int ret;\n"
|
||||
" int a = value << ret;\n"
|
||||
" return ret;\n"
|
||||
" a = value << ret;\n"
|
||||
"}\n",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: ret\n", errout.str());
|
||||
|
@ -520,7 +518,7 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void a()\n"
|
||||
checkUninitVar2("void a()\n"
|
||||
"{\n"
|
||||
" struct S *s;\n"
|
||||
" s->x = 0;\n"
|
||||
|
@ -588,7 +586,7 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f(int a)\n"
|
||||
checkUninitVar2("void f(int a)\n"
|
||||
"{\n"
|
||||
" if (a) {\n"
|
||||
" char *p;\n"
|
||||
|
@ -598,7 +596,7 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: p\n", errout.str());
|
||||
|
||||
// +=
|
||||
checkUninitVar("void f()\n"
|
||||
checkUninitVar2("void f()\n"
|
||||
"{\n"
|
||||
" int c;\n"
|
||||
" c += 2;\n"
|
||||
|
@ -981,7 +979,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #3098 - False negative uninitialized variable
|
||||
checkUninitVar("void f()\n"
|
||||
checkUninitVar2("void f()\n"
|
||||
"{\n"
|
||||
" char *c1,*c2;\n"
|
||||
" if(strcoll(c1,c2))\n"
|
||||
|
|
Loading…
Reference in New Issue