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