Add tests for #8399/#10646/#10833 (#5743)
This commit is contained in:
parent
7452e681dd
commit
233e27b579
|
@ -593,6 +593,20 @@ void memleak_LocalAlloc()
|
|||
// cppcheck-suppress memleak
|
||||
}
|
||||
|
||||
void memleak_dupenv_s() // #10646
|
||||
{
|
||||
char* pValue;
|
||||
size_t len;
|
||||
errno_t err = _dupenv_s(&pValue, &len, "pathext");
|
||||
if (err) return -1;
|
||||
printf("pathext = %s\n", pValue);
|
||||
free(pValue);
|
||||
err = _dupenv_s(&pValue, &len, "nonexistentvariable");
|
||||
if (err) return -1;
|
||||
printf("nonexistentvariable = %s\n", pValue);
|
||||
// cppcheck-suppress memleak
|
||||
}
|
||||
|
||||
void resourceLeak_CreateSemaphoreA()
|
||||
{
|
||||
HANDLE hSemaphore;
|
||||
|
|
|
@ -2933,6 +2933,13 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n",
|
||||
errout.str());
|
||||
|
||||
// #10833
|
||||
check("struct A { std::string s; };\n"
|
||||
"const std::string& f(A* a) {\n"
|
||||
" return a ? a->s : \"\";\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
|
||||
|
||||
check("std::span<int> f() {\n"
|
||||
" std::vector<int> v{};\n"
|
||||
" return v;\n"
|
||||
|
|
|
@ -490,6 +490,8 @@ private:
|
|||
dui.std = "c++11";
|
||||
// this is set by the production code via cppcheck::Platform::getLimitDefines()
|
||||
dui.defines.emplace_back("INT_MIN=-2147483648");
|
||||
dui.defines.emplace_back("INT32_MAX=2147483647");
|
||||
dui.defines.emplace_back("int32_t=int");
|
||||
|
||||
checkP("int fun(int x)\n"
|
||||
"{\n"
|
||||
|
@ -501,6 +503,13 @@ private:
|
|||
" fun(INT_MIN);\n"
|
||||
"}", settings, "test.cpp", dui);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Signed integer overflow for expression '-x'.\n", errout.str());
|
||||
|
||||
checkP("void f() {\n" // #8399
|
||||
" int32_t i = INT32_MAX;\n"
|
||||
" i << 1;\n"
|
||||
" i << 2;\n"
|
||||
"}", settings, "test.cpp", dui);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer overflow for expression 'i<<2'.\n", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue