Skip to content

Commit 233e27b

Browse files
Add tests for #8399/#10646/#10833 (#5743)
1 parent 7452e68 commit 233e27b

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

test/cfg/windows.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,20 @@ void memleak_LocalAlloc()
593593
// cppcheck-suppress memleak
594594
}
595595

596+
void memleak_dupenv_s() // #10646
597+
{
598+
char* pValue;
599+
size_t len;
600+
errno_t err = _dupenv_s(&pValue, &len, "pathext");
601+
if (err) return -1;
602+
printf("pathext = %s\n", pValue);
603+
free(pValue);
604+
err = _dupenv_s(&pValue, &len, "nonexistentvariable");
605+
if (err) return -1;
606+
printf("nonexistentvariable = %s\n", pValue);
607+
// cppcheck-suppress memleak
608+
}
609+
596610
void resourceLeak_CreateSemaphoreA()
597611
{
598612
HANDLE hSemaphore;

test/testautovariables.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,13 @@ class TestAutoVariables : public TestFixture {
29332933
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n",
29342934
errout.str());
29352935

2936+
// #10833
2937+
check("struct A { std::string s; };\n"
2938+
"const std::string& f(A* a) {\n"
2939+
" return a ? a->s : \"\";\n"
2940+
"}\n");
2941+
ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str());
2942+
29362943
check("std::span<int> f() {\n"
29372944
" std::vector<int> v{};\n"
29382945
" return v;\n"

test/testtype.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ class TestType : public TestFixture {
490490
dui.std = "c++11";
491491
// this is set by the production code via cppcheck::Platform::getLimitDefines()
492492
dui.defines.emplace_back("INT_MIN=-2147483648");
493+
dui.defines.emplace_back("INT32_MAX=2147483647");
494+
dui.defines.emplace_back("int32_t=int");
493495

494496
checkP("int fun(int x)\n"
495497
"{\n"
@@ -501,6 +503,13 @@ class TestType : public TestFixture {
501503
" fun(INT_MIN);\n"
502504
"}", settings, "test.cpp", dui);
503505
ASSERT_EQUALS("[test.cpp:3]: (error) Signed integer overflow for expression '-x'.\n", errout.str());
506+
507+
checkP("void f() {\n" // #8399
508+
" int32_t i = INT32_MAX;\n"
509+
" i << 1;\n"
510+
" i << 2;\n"
511+
"}", settings, "test.cpp", dui);
512+
ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer overflow for expression 'i<<2'.\n", errout.str());
504513
}
505514
};
506515

0 commit comments

Comments
 (0)