Add some tests (#4014)
* Test for #10454 * Test for #10493 * Test for #10069 * Test for #10228 * Fix test case
This commit is contained in:
parent
f323e8a6c6
commit
da1e2b22be
|
@ -3163,6 +3163,22 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(int a[10]) {\n" // #10069
|
||||
" int i = 0;\n"
|
||||
" for (i = 0; i < 10; i++)\n"
|
||||
" a[i] = i * 2;\n"
|
||||
"}\n"
|
||||
"void g() {\n"
|
||||
" int b[5];\n"
|
||||
" f(b);\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("test.cpp:8:warning:Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\n"
|
||||
"test.cpp:8:note:Function 'f' is called\n"
|
||||
"test.cpp:1:note:Declaration of 1st function argument.\n"
|
||||
"test.cpp:7:note:Passing buffer 'b' to function that is declared here\n"
|
||||
"test.cpp:8:note:Buffer 'b' is too small, the function 'f' expects a bigger buffer in 1st argument\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void possible_buffer_overrun_1() { // #3035
|
||||
|
|
|
@ -4086,6 +4086,14 @@ private:
|
|||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition '!a==!b' is always false\n", errout.str());
|
||||
|
||||
// #10454
|
||||
check("struct S {\n"
|
||||
" int f() const { return g() ? 0 : 1; }\n"
|
||||
" bool g() const { return u == 18446744073709551615ULL; }\n"
|
||||
" unsigned long long u{};\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void alwaysTrueSymbolic()
|
||||
|
|
|
@ -7939,6 +7939,15 @@ private:
|
|||
" return y;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #10228
|
||||
check("std::tuple<int, int> g();\n"
|
||||
"void h(int);\n"
|
||||
"void f() {\n"
|
||||
" auto [a, b] = g();\n"
|
||||
" auto l = [a = a]() { h(i); };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void redundantVarAssignment_loop() {
|
||||
|
|
|
@ -3981,6 +3981,21 @@ private:
|
|||
" std::string m;\n"
|
||||
"};\n", /*inconclusive*/ true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout.str());
|
||||
|
||||
check("struct S {\n" // #10493
|
||||
" void f(const char** pp);\n"
|
||||
" std::string s;\n"
|
||||
"};\n"
|
||||
"void S::f(const char** pp) {\n"
|
||||
" try {\n"
|
||||
" *pp = member.c_str();\n"
|
||||
" }\n"
|
||||
" catch (...) {\n"
|
||||
" s = \"xyz\";\n"
|
||||
" *pp = member.c_str();\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uselessCalls() {
|
||||
|
|
Loading…
Reference in New Issue