Use TODO_ASSERT (#3704)

This commit is contained in:
chrchr-github 2022-01-18 22:03:52 +01:00 committed by GitHub
parent 55ff684f34
commit 089ca67d78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 51 deletions

View File

@ -1093,7 +1093,9 @@ private:
" struct s1 obj;\n"
" x(obj.delay, 123);\n"
"}");
// TODO CTU ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\n",
"",
errout.str());
check("struct s1 {\n"
" float a[0];\n"
@ -2317,7 +2319,9 @@ private:
" char x[2];\n"
" f1(x);\n"
"}");
// TODO CTU ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\n",
"",
errout.str());
}
void array_index_string_literal() {
@ -3780,7 +3784,9 @@ private:
check("void f() {\n"
" mymemset(\"abc\", 0, 20);\n"
"}", settings);
// TODO ASSERT_EQUALS("[test.cpp:2]: (error) Buffer is accessed out of bounds.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Buffer is accessed out of bounds.\n",
"",
errout.str());
check("void f() {\n"
" mymemset(temp, \"abc\", 4);\n"
@ -3852,7 +3858,9 @@ private:
" char buf[5];\n"
" a(buf);"
"}", settings);
// TODO CTU ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\n",
"",
errout.str());
}
void minsize_strlen() {

View File

@ -224,7 +224,9 @@ private:
ASSERT_EQUALS("FILESDIR=\"/some/path\"", importer.fileSettings.begin()->defines);
ASSERT_EQUALS(1, importer.fileSettings.begin()->includePaths.size());
ASSERT_EQUALS("/home/danielm/cppcheck 2/b/lib/", importer.fileSettings.begin()->includePaths.front());
// TODO ASSERT_EQUALS("/home/danielm/cppcheck 2/externals/", importer.fileSettings.begin()->includePaths.back());
TODO_ASSERT_EQUALS("/home/danielm/cppcheck 2/externals/",
"/home/danielm/cppcheck 2/b/lib/",
importer.fileSettings.begin()->includePaths.back());
}
void importCompileCommands8() const {

View File

@ -2978,7 +2978,9 @@ private:
" strcpy(str, \"b'\");\n"
" }\n"
"}", nullptr, false, false, false);
// TODO ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n",
"",
errout.str());
check("void foo(int a) {\n"
" char str[10];\n"
@ -2990,7 +2992,9 @@ private:
" strncpy(str, \"b'\");\n"
" }\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n",
"",
errout.str());
check("void foo(int a) {\n"
" char str[10];\n"
@ -3005,7 +3009,9 @@ private:
" z++;\n"
" }\n"
"}", nullptr, false, false, false);
// TODO ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n",
"",
errout.str());
check("void foo(int a) {\n"
" char str[10];\n"

View File

@ -2348,7 +2348,9 @@ private:
" int &j = i;\n"
" j = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'i' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("double foo()\n"
"{\n"
@ -2449,7 +2451,9 @@ private:
" for (int i = 0; i < 10; )\n"
" a[i++] = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
}
void localvar10() {
@ -2738,7 +2742,9 @@ private:
" a = b[c] = 0;\n"
" return a;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'b' is assigned a value that is never used.\n",
"",
errout.str());
}
void localvar24() { // ticket #1803
@ -2828,7 +2834,7 @@ private:
" C c;\n" // possibly some stream class
" if (c >>= x) {}\n"
"}");
// TODO ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (information) --check-library: Provide <type-checks><unusedvar> configuration for C\n", errout.str());
functionVariableUsage("void f(int x) {\n"
" C c;\n"
@ -3346,7 +3352,9 @@ private:
" int *b = &a;\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3354,7 +3362,9 @@ private:
" char *b = (char *)&a;\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3362,7 +3372,9 @@ private:
" char *b = (char *)(&a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3370,7 +3382,9 @@ private:
" const char *b = (const char *)&a;\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3378,7 +3392,9 @@ private:
" const char *b = (const char *)(&a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3386,7 +3402,9 @@ private:
" char *b = static_cast<char *>(&a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3394,7 +3412,9 @@ private:
" const char *b = static_cast<const char *>(&a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
// a is not a local variable and b is aliased to it
functionVariableUsage("int a;\n"
@ -3454,7 +3474,9 @@ private:
" int *b = a;\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3462,7 +3484,9 @@ private:
" char *b = (char *)a;\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3470,7 +3494,9 @@ private:
" char *b = (char *)(a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3478,7 +3504,9 @@ private:
" const char *b = (const char *)a;\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3486,7 +3514,9 @@ private:
" const char *b = (const char *)(a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3494,7 +3524,9 @@ private:
" char *b = static_cast<char *>(a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3502,7 +3534,9 @@ private:
" const char *b = static_cast<const char *>(a);\n"
" *b = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("int a[10];\n"
"void foo()\n"
@ -3601,7 +3635,9 @@ private:
" int *c = b;\n"
" *c = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'a' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3611,9 +3647,9 @@ private:
" int *d = b;\n"
" *d = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n"
// TODO "[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n"
// TODO "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n"
"[test.cpp:3]: (style) Unused variable: a\n",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3623,8 +3659,9 @@ private:
" c = b;\n"
" *c = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n"
// TODO "[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n"
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3636,15 +3673,19 @@ private:
" c = a;\n"
" *c = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:9]: (style) Variable 'a' is assigned a value that is never used.\n"
// TODO "[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:9]: (style) Variable 'a' is assigned a value that is never used.\n"
"[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
" int a[10], * b = a + 10;\n"
" b[-10] = 1;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b[-10]' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b[-10]' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3661,7 +3702,9 @@ private:
" int * c = b - 10;\n"
" c[1] = 3;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3669,7 +3712,9 @@ private:
" int * c = b - 10;\n"
" c[1] = c[0];\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'c[1]' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo() {\n" // #4022 - FP (a is assigned a value that is never used)
" int a[2], *b[2];\n"
@ -3745,8 +3790,8 @@ private:
" d = c;\n"
" *d = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: b\n"
// TODO "[test.cpp:10]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: b\n",
errout.str());
functionVariableUsage("int a[10];\n"
"void foo()\n"
@ -3758,8 +3803,10 @@ private:
" d = a; *d = 0;\n"
" d = c; *d = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n"
// TODO "[test.cpp:9]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n"
"[test.cpp:9]: (style) Variable 'c' is assigned a value that is never used.\n",
"",
errout.str());
}
void localvaralias2() { // ticket 1637
@ -3882,7 +3929,9 @@ private:
" }\n"
" b(srcdata);\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3895,7 +3944,9 @@ private:
" srcdata = vdata;\n"
" b(srcdata);\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'buf' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo(char *vdata)\n"
"{\n"
@ -3948,7 +3999,9 @@ private:
" }\n"
" b(srcdata);\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -3962,7 +4015,9 @@ private:
" srcdata = vdata;\n"
" b(srcdata);\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'buf' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -4203,7 +4258,9 @@ private:
" ref[0] = 123;\n"
"}",
"test.c");
// TODO ASSERT_EQUALS("[test.c:5]: (style) Variable 'foo' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.c:5]: (style) Variable 'foo' is assigned a value that is never used.\n",
"",
errout.str());
}
void localvaralias10() { // ticket 2004
@ -4883,20 +4940,26 @@ private:
"{\n"
" static int i = 0;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
" static int i(0);\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
" static int j = 0;\n"
" static int i(j);\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("int * foo(int x)\n"
"{\n"
@ -4906,7 +4969,9 @@ private:
" b[1] = 1;\n"
" return x ? a : c;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n",
"",
errout.str());
functionVariableUsage("void foo()\n"
"{\n"
@ -5173,7 +5238,9 @@ private:
" for ( int i = 0; i < 10; ++i )\n"
" p++;\n"
"}");
// TODO ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'p' is modified but its new value is never used.\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'p' is modified but its new value is never used.\n",
"",
errout.str());
}
void localvararray1() {