Skip to content
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
15 changes: 15 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5395,6 +5395,21 @@ class TestBufferOverrun : public TestFixture {
" return p[10];\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("struct X {\n" // #2654
" int a;\n"
" char b;\n"
"};\n"
"void f() {\n"
" X s;\n"
" int* y = &s.a;\n"
" (void)y[0];\n"
" (void)y[1];\n"
" (void)y[2];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (error) The address of local variable 'a' is accessed at non-zero index.\n"
"[test.cpp:7] -> [test.cpp:10]: (error) The address of local variable 'a' is accessed at non-zero index.\n",
errout.str());
}

void checkPipeParameterSize() { // #3521
Expand Down
9 changes: 9 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8382,6 +8382,15 @@ class TestOther : public TestFixture {
" *reg = 34;\n"
"}");
ASSERT_EQUALS("test.cpp:2:style:C-style pointer casting\n", errout.str());

check("void f(std::map<int, int>& m, int key, int value) {\n" // #6379
" m[key] = value;\n"
" m[key] = value;\n"
"}\n");
ASSERT_EQUALS("test.cpp:3:style:Variable 'm[key]' is reassigned a value before the old one has been used.\n"
"test.cpp:2:note:m[key] is assigned\n"
"test.cpp:3:note:m[key] is overwritten\n",
errout.str());
}

void redundantVarAssignment_trivial() {
Expand Down
8 changes: 8 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5871,6 +5871,14 @@ class TestStl : public TestFixture {
true);
ASSERT_EQUALS("[test.cpp:3]: (style) Using sort with iterator 'v.begin()' that is always empty.\n", errout.str());

check("void f() {\n" // #1201
" std::vector<int> v1{ 0, 1 };\n"
" std::vector<int> v2;\n"
" std::copy(v1.begin(), v1.end(), v2.begin());\n"
"}\n",
true);
ASSERT_EQUALS("[test.cpp:4]: (style) Using copy with iterator 'v2.begin()' that is always empty.\n", errout.str());

check("void f() {\n"
" std::vector<int> v;\n"
" v.insert(v.end(), 1);\n"
Expand Down