Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for #8399/#10646/#10833 #5743

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading