Skip to content

Commit 32c7b91

Browse files
Add tests for #1201, #2654, #6379 (#4518)
* Add test for #6541, avoid duplicate warning * Add test for #5475 * Fix test * Merge * Add test for #8666 * Fix #11239 checkLibraryCheckType with asm goto() (invalid varid) * Format * Add tests for #1201, #2654 * Fix test * Add test for #6379
1 parent 441f9b9 commit 32c7b91

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

test/testbufferoverrun.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5395,6 +5395,21 @@ class TestBufferOverrun : public TestFixture {
53955395
" return p[10];\n"
53965396
"}\n");
53975397
ASSERT_EQUALS("", errout.str());
5398+
5399+
check("struct X {\n" // #2654
5400+
" int a;\n"
5401+
" char b;\n"
5402+
"};\n"
5403+
"void f() {\n"
5404+
" X s;\n"
5405+
" int* y = &s.a;\n"
5406+
" (void)y[0];\n"
5407+
" (void)y[1];\n"
5408+
" (void)y[2];\n"
5409+
"}\n");
5410+
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (error) The address of local variable 'a' is accessed at non-zero index.\n"
5411+
"[test.cpp:7] -> [test.cpp:10]: (error) The address of local variable 'a' is accessed at non-zero index.\n",
5412+
errout.str());
53985413
}
53995414

54005415
void checkPipeParameterSize() { // #3521

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8382,6 +8382,15 @@ class TestOther : public TestFixture {
83828382
" *reg = 34;\n"
83838383
"}");
83848384
ASSERT_EQUALS("test.cpp:2:style:C-style pointer casting\n", errout.str());
8385+
8386+
check("void f(std::map<int, int>& m, int key, int value) {\n" // #6379
8387+
" m[key] = value;\n"
8388+
" m[key] = value;\n"
8389+
"}\n");
8390+
ASSERT_EQUALS("test.cpp:3:style:Variable 'm[key]' is reassigned a value before the old one has been used.\n"
8391+
"test.cpp:2:note:m[key] is assigned\n"
8392+
"test.cpp:3:note:m[key] is overwritten\n",
8393+
errout.str());
83858394
}
83868395

83878396
void redundantVarAssignment_trivial() {

test/teststl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5871,6 +5871,14 @@ class TestStl : public TestFixture {
58715871
true);
58725872
ASSERT_EQUALS("[test.cpp:3]: (style) Using sort with iterator 'v.begin()' that is always empty.\n", errout.str());
58735873

5874+
check("void f() {\n" // #1201
5875+
" std::vector<int> v1{ 0, 1 };\n"
5876+
" std::vector<int> v2;\n"
5877+
" std::copy(v1.begin(), v1.end(), v2.begin());\n"
5878+
"}\n",
5879+
true);
5880+
ASSERT_EQUALS("[test.cpp:4]: (style) Using copy with iterator 'v2.begin()' that is always empty.\n", errout.str());
5881+
58745882
check("void f() {\n"
58755883
" std::vector<int> v;\n"
58765884
" v.insert(v.end(), 1);\n"

0 commit comments

Comments
 (0)