Skip to content

Commit

Permalink
Add tests for #8399/#10646/#10833 (danmar#5743)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 8, 2023
1 parent 7452e68 commit 233e27b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/cfg/windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,13 @@ class TestAutoVariables : public TestFixture {
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"
Expand Down
9 changes: 9 additions & 0 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ class TestType : public TestFixture {
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"
Expand All @@ -501,6 +503,13 @@ class TestType : public TestFixture {
" 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());
}
};

Expand Down

0 comments on commit 233e27b

Please sign in to comment.