From 1d49151d3f097e2d11de36ab697f26150b8fe079 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 11:24:13 +0200 Subject: [PATCH 1/4] TestConstructors: added error IDs and columns to expected output --- test/testconstructors.cpp | 372 +++++++++++++++++++------------------- 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 086ddf5f574..b57d6d80305 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -54,7 +54,7 @@ class TestConstructors : public TestFixture { } void run() override { - // TODO: mNewTemplate = true; + mNewTemplate = true; TEST_CASE(simple1); TEST_CASE(simple2); TEST_CASE(simple3); @@ -241,14 +241,14 @@ class TestConstructors : public TestFixture { "private:\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); check("struct Fred\n" "{\n" "private:\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' does not declare a constructor although it has private member variables which likely require initialization.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:1]: (style) The struct 'Fred' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } @@ -281,9 +281,9 @@ class TestConstructors : public TestFixture { " Fred(Fred && other) {}\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the copy constructor.\n" - "[test.cpp:6]: (warning) Member variable 'Fred::i' is not initialized in the move constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the copy constructor. [uninitMemberVar]\n" + "[test.cpp:6:5]: (warning) Member variable 'Fred::i' is not initialized in the move constructor. [uninitMemberVar]\n", errout_str()); check("struct Fred\n" "{\n" @@ -292,9 +292,9 @@ class TestConstructors : public TestFixture { " Fred(Fred && other) {}\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n" - "[test.cpp:4]: (warning) Member variable 'Fred::i' is not initialized in the copy constructor.\n" - "[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the move constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the copy constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the move constructor. [uninitMemberVar]\n", errout_str()); } @@ -324,7 +324,7 @@ class TestConstructors : public TestFixture { "};\n" "Fred::Fred()\n" "{ }"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -342,7 +342,7 @@ class TestConstructors : public TestFixture { "{\n" " i = _i;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:8]: (warning, inconclusive) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:7]: (warning, inconclusive) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void simple5() { // ticket #2560 @@ -386,8 +386,8 @@ class TestConstructors : public TestFixture { " int x;\n" " int y;\n" "};"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Member variable 'A::y' is not initialized in the constructor.\n" - "[test.cpp:3]: (warning) Member variable 'A::y' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Member variable 'A::y' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:3:5]: (warning) Member variable 'A::y' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void simple7() { // ticket #4531 @@ -402,8 +402,8 @@ class TestConstructors : public TestFixture { check("struct Fred { int x; };\n" "class Barney { Fred fred; };\n" "class Wilma { struct Betty { int x; } betty; };"); - ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not declare a constructor although it has private member variables which likely require initialization.\n" - "[test.cpp:3]: (style) The class 'Wilma' does not declare a constructor although it has private member variables which likely require initialization.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:1]: (style) The class 'Barney' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n" + "[test.cpp:3:1]: (style) The class 'Wilma' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } void simple9() { // ticket #4574 @@ -423,7 +423,7 @@ class TestConstructors : public TestFixture { "private:\n" " int x;\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct S {\n" // #9391 " S() = default;\n" @@ -434,7 +434,7 @@ class TestConstructors : public TestFixture { " S& operator=(S&&) = default;\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Member variable 'S::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Member variable 'S::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void simple11() { // ticket #4536, #6214 @@ -451,8 +451,8 @@ class TestConstructors : public TestFixture { " int d, e{3};\n" " int f{4}, g;\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n" - "[test.cpp:3]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:3:5]: (warning) Member variable 'Fred::g' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void simple12() { // ticket #4620 @@ -532,8 +532,8 @@ class TestConstructors : public TestFixture { " S(const S& s) {}\n" " S& operator=(const S& s) { return *this; }\n" "};\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Member variable 'S::i' is not assigned in the copy constructor. Should it be copied?\n" - "[test.cpp:5]: (warning) Member variable 'S::i' is not assigned a value in 'S::operator='.\n", + ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Member variable 'S::i' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n" + "[test.cpp:5:8]: (warning) Member variable 'S::i' is not assigned a value in 'S::operator='. [operatorEqVarError]\n", errout_str()); check("struct S {\n" @@ -542,8 +542,8 @@ class TestConstructors : public TestFixture { " S(const S& s) {}\n" " S& operator=(const S& s) { return *this; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'S::i' is not initialized in the copy constructor.\n" - "[test.cpp:5]: (warning) Member variable 'S::i' is not assigned a value in 'S::operator='.\n", + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'S::i' is not initialized in the copy constructor. [uninitMemberVar]\n" + "[test.cpp:5:8]: (warning) Member variable 'S::i' is not assigned a value in 'S::operator='. [operatorEqVarError]\n", errout_str()); } @@ -573,8 +573,8 @@ class TestConstructors : public TestFixture { check("struct S {};\n" "class C1 { S& r; };\n" "class C2 { S* p; };\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) The class 'C1' does not declare a constructor although it has private member variables which likely require initialization.\n" - "[test.cpp:3]: (style) The class 'C2' does not declare a constructor although it has private member variables which likely require initialization.\n", + ASSERT_EQUALS("[test.cpp:2:1]: (style) The class 'C1' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n" + "[test.cpp:3:1]: (style) The class 'C2' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } @@ -584,7 +584,7 @@ class TestConstructors : public TestFixture { "{\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } void noConstructor2() { @@ -733,14 +733,14 @@ class TestConstructors : public TestFixture { " int i1 = 0;\n" " int i2;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'C::i2' is not initialized.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'C::i2' is not initialized. [uninitMemberVarPrivate]\n", errout_str()); check("class C {\n" "private:\n" " int i1;\n" " int i2;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) The class 'C' does not declare a constructor although it has private member variables which likely require initialization.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:1]: (style) The class 'C' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); check("class C {\n" "public:\n" @@ -749,7 +749,7 @@ class TestConstructors : public TestFixture { " int i1;\n" " int i2;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'C::i2' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'C::i2' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor." @@ -846,7 +846,7 @@ class TestConstructors : public TestFixture { " void operator=(const Fred &fred) { }\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); } void initvar_operator_eq3() { @@ -875,7 +875,7 @@ class TestConstructors : public TestFixture { " return *this\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("class Fred\n" "{\n" @@ -890,7 +890,7 @@ class TestConstructors : public TestFixture { " return *this\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("class Fred\n" "{\n" @@ -905,7 +905,7 @@ class TestConstructors : public TestFixture { " return *this\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("class Fred\n" "{\n" @@ -945,7 +945,7 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};",dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("struct Fred {\n" " std::vector ints;\n" @@ -953,7 +953,7 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};",dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("struct Fred {\n" " Data data;\n" @@ -961,7 +961,7 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};",dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); } void initvar_operator_eq7() { @@ -1003,8 +1003,8 @@ class TestConstructors : public TestFixture { " int d3_1;\n" " int d3_2;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'D3::d3_2' is not assigned a value in 'D3::operator='.\n" - "[test.cpp:13]: (warning) Member variable 'D3::d2' is not assigned a value in 'D3::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:9]: (warning) Member variable 'D3::d3_2' is not assigned a value in 'D3::operator='. [operatorEqVarError]\n" + "[test.cpp:13:9]: (warning) Member variable 'D3::d2' is not assigned a value in 'D3::operator='. [operatorEqVarError]\n", errout_str()); } void initvar_operator_eq9() { // ticket #13203 @@ -1043,7 +1043,7 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'S::m_data' is not assigned a value in 'S::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (warning) Member variable 'S::m_data' is not assigned a value in 'S::operator='. [operatorEqVarError]\n", errout_str()); } @@ -1152,8 +1152,8 @@ class TestConstructors : public TestFixture { " }\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::a' is not initialized in the constructor.\n" - "[test.cpp:16]: (warning) Member variable 'Fred::b' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13]: (warning) Member variable 'Fred::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:16:13]: (warning) Member variable 'Fred::b' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void initvar_chained_assign() { @@ -1235,7 +1235,7 @@ class TestConstructors : public TestFixture { "};\n" "Fred::Fred()\n" "{ }"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::s' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:7]: (warning) Member variable 'Fred::s' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -1303,7 +1303,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::U' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (warning) Member variable 'Fred::U' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -1314,8 +1314,8 @@ class TestConstructors : public TestFixture { " A(int n) { }\n" " A() : A(42) {}\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::number' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning) Member variable 'A::number' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A {\n" " int number;\n" @@ -1331,8 +1331,8 @@ class TestConstructors : public TestFixture { " A(int n) : A() { }\n" " A() {}\n" "};", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::number' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A {\n" " int number;\n" @@ -1348,8 +1348,8 @@ class TestConstructors : public TestFixture { " A(int n) { }\n" " A() : A{42} {}\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::number' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning) Member variable 'A::number' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A {\n" " int number;\n" @@ -1365,8 +1365,8 @@ class TestConstructors : public TestFixture { " A(int n) : A{} { }\n" " A() {}\n" "};", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::number' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A {\n" " int number;\n" @@ -1457,7 +1457,7 @@ class TestConstructors : public TestFixture { " Derived() {}\n" " void foo() override;\n" "};"); - ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Base::x' is not initialized in the constructor. Maybe it should be initialized directly in the class Base?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:3]: (warning) Member variable 'Base::x' is not initialized in the constructor. Maybe it should be initialized directly in the class Base? [uninitDerivedMemberVar]\n", errout_str()); check("struct A {\n" // #3462 " char ca;\n" @@ -1473,7 +1473,7 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'B::cb' is not assigned a value in 'B::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:8]: (warning) Member variable 'B::cb' is not assigned a value in 'B::operator='. [operatorEqVarError]\n", errout_str()); check("struct A {\n" " char ca;\n" @@ -1488,9 +1488,9 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'A::ca' is not assigned a value in 'A::operator='.\n" - "[test.cpp:9]: (warning) Member variable 'B::cb' is not assigned a value in 'B::operator='.\n" - "[test.cpp:9]: (warning) Member variable 'B::ca' is not assigned a value in 'B::operator='.\n", + ASSERT_EQUALS("[test.cpp:3:8]: (warning) Member variable 'A::ca' is not assigned a value in 'A::operator='. [operatorEqVarError]\n" + "[test.cpp:9:8]: (warning) Member variable 'B::cb' is not assigned a value in 'B::operator='. [operatorEqVarError]\n" + "[test.cpp:9:8]: (warning) Member variable 'B::ca' is not assigned a value in 'B::operator='. [operatorEqVarError]\n", errout_str()); check("class C : B {\n" // don't crash @@ -1576,9 +1576,9 @@ class TestConstructors : public TestFixture { "public:\n" " C() {}\n" "};"); - ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'S::all' is not initialized in the constructor. Maybe it should be initialized directly in the class S?\n" - "[test.cpp:13]: (warning) Member variable 'S::flag1' is not initialized in the constructor. Maybe it should be initialized directly in the class S?\n" - "[test.cpp:13]: (warning) Member variable 'S::flag2' is not initialized in the constructor. Maybe it should be initialized directly in the class S?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:5]: (warning) Member variable 'S::all' is not initialized in the constructor. Maybe it should be initialized directly in the class S? [uninitDerivedMemberVar]\n" + "[test.cpp:13:5]: (warning) Member variable 'S::flag1' is not initialized in the constructor. Maybe it should be initialized directly in the class S? [uninitDerivedMemberVar]\n" + "[test.cpp:13:5]: (warning) Member variable 'S::flag2' is not initialized in the constructor. Maybe it should be initialized directly in the class S? [uninitDerivedMemberVar]\n", errout_str()); } void initvar_private_constructor() { @@ -1592,7 +1592,7 @@ class TestConstructors : public TestFixture { "};\n" "Fred::Fred()\n" "{ }", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::var' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:7]: (warning) Member variable 'Fred::var' is not initialized in the constructor. [uninitMemberVarPrivate]\n", errout_str()); } { @@ -1628,7 +1628,7 @@ class TestConstructors : public TestFixture { " Fred() { };\n" " Fred(const Fred &) { };\n" "};", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:7]: (warning, inconclusive) Member variable 'Fred::var' is not assigned in the copy constructor. Should it be copied?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (warning, inconclusive) Member variable 'Fred::var' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n", errout_str()); check("class Fred\n" "{\n" @@ -1640,7 +1640,7 @@ class TestConstructors : public TestFixture { "};\n" "Fred::Fred() { };\n" "Fred::Fred(const Fred &) { };\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:10]: (warning, inconclusive) Member variable 'Fred::var' is not assigned in the copy constructor. Should it be copied?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:7]: (warning, inconclusive) Member variable 'Fred::var' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n", errout_str()); check("class Baz {};\n" // #8496 "class Bar {\n" @@ -1649,7 +1649,7 @@ class TestConstructors : public TestFixture { " Bar(const Bar& bar) {}\n" " int i;\n" "};\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Bar::i' is not initialized in the copy constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Bar::i' is not initialized in the copy constructor. [uninitMemberVar]\n", errout_str()); } void initvar_nested_constructor() { // ticket #1375 @@ -1678,10 +1678,10 @@ class TestConstructors : public TestFixture { "A::B::C::D::D(int z){}"); // Note that the example code is not compilable. The A constructor must // explicitly initialize A::b. A warning for A::b is not necessary. - ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable 'A::a' is not initialized in the constructor.\n" - "[test.cpp:21]: (warning) Member variable 'B::b' is not initialized in the constructor.\n" - "[test.cpp:22]: (warning) Member variable 'C::c' is not initialized in the constructor.\n" - "[test.cpp:23]: (warning) Member variable 'D::d' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:20:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:21:7]: (warning) Member variable 'B::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:22:10]: (warning) Member variable 'C::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:23:13]: (warning) Member variable 'D::d' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A {\n" "public:\n" @@ -1708,10 +1708,10 @@ class TestConstructors : public TestFixture { "A::B::C::D::D(const A::B::C::D & d){}"); // Note that the example code is not compilable. The A constructor must // explicitly initialize A::b. A warning for A::b is not necessary. - ASSERT_EQUALS("[test.cpp:20]: (warning) Member variable 'A::a' is not initialized in the constructor.\n" - "[test.cpp:21]: (warning) Member variable 'B::b' is not initialized in the constructor.\n" - "[test.cpp:22]: (warning) Member variable 'C::c' is not initialized in the constructor.\n" - "[test.cpp:23]: (warning) Member variable 'D::d' is not initialized in the copy constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:20:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:21:7]: (warning) Member variable 'B::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:22:10]: (warning) Member variable 'C::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:23:13]: (warning) Member variable 'D::d' is not initialized in the copy constructor. [uninitMemberVar]\n", errout_str()); check("class A {\n" "public:\n" @@ -1739,10 +1739,10 @@ class TestConstructors : public TestFixture { "A::B::C::D::D(const A::B::C::D::E & e){}"); // Note that the example code is not compilable. The A constructor must // explicitly initialize A::b. A warning for A::b is not necessary. - ASSERT_EQUALS("[test.cpp:21]: (warning) Member variable 'A::a' is not initialized in the constructor.\n" - "[test.cpp:22]: (warning) Member variable 'B::b' is not initialized in the constructor.\n" - "[test.cpp:23]: (warning) Member variable 'C::c' is not initialized in the constructor.\n" - "[test.cpp:24]: (warning) Member variable 'D::d' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:21:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:22:7]: (warning) Member variable 'B::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:23:10]: (warning) Member variable 'C::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:24:13]: (warning) Member variable 'D::d' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void initvar_nocopy1() { // ticket #2474 @@ -1823,9 +1823,9 @@ class TestConstructors : public TestFixture { " B(B &&){}\n" " const B& operator=(const B&){return *this;}\n" "};", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:11]: (warning, inconclusive) Member variable 'B::a' is not assigned in the copy constructor. Should it be copied?\n" - "[test.cpp:12]: (warning, inconclusive) Member variable 'B::a' is not assigned in the move constructor. Should it be moved?\n" - "[test.cpp:13]: (warning, inconclusive) Member variable 'B::a' is not assigned a value in 'B::operator='.\n", + ASSERT_EQUALS("[test.cpp:11:5]: (warning, inconclusive) Member variable 'B::a' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n" + "[test.cpp:12:5]: (warning, inconclusive) Member variable 'B::a' is not assigned in the move constructor. Should it be moved? [missingMemberCopy]\n" + "[test.cpp:13:14]: (warning, inconclusive) Member variable 'B::a' is not assigned a value in 'B::operator='. [operatorEqVarError]\n", errout_str()); check("class B\n" @@ -1843,7 +1843,7 @@ class TestConstructors : public TestFixture { " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" "};"); - ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not initialized in the move constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:5]: (warning) Member variable 'A::m_SemVar' is not initialized in the move constructor. [uninitMemberVar]\n", errout_str()); check("class B\n" "{\n" @@ -1906,9 +1906,9 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " const A& operator=(const A&){return *this;}\n" "};", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:12]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor.\n" - "[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not initialized in the copy constructor.\n" - "[test.cpp:14]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:12:5]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:13:5]: (warning) Member variable 'A::m_SemVar' is not initialized in the copy constructor. [uninitMemberVar]\n" + "[test.cpp:14:14]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='. [operatorEqVarError]\n", errout_str()); } void initvar_nocopy3() { // #3611 - unknown type is non-copyable @@ -1924,7 +1924,7 @@ class TestConstructors : public TestFixture { " A() {}\n" " A(const A& rhs) {}\n" "};", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Member variable 'A::b' is not assigned in the copy constructor. Should it be copied?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Member variable 'A::b' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n", errout_str()); } void initvar_nocopy4() { // #9247 @@ -2008,7 +2008,7 @@ class TestConstructors : public TestFixture { " *pa = 0;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'S::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'S::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct S {\n" " int a;\n" @@ -2017,7 +2017,7 @@ class TestConstructors : public TestFixture { " pa = 4;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'S::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'S::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void initvar_templateMember() { @@ -2081,7 +2081,7 @@ class TestConstructors : public TestFixture { "\n" "void Fred::operator=(const Fred &f)\n" "{ }", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:13]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:12]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); const Settings s = settingsBuilder().certainty(Certainty::inconclusive).severity(Severity::style).severity(Severity::warning).library("std.cfg").build(); check("struct S {\n" @@ -2107,7 +2107,7 @@ class TestConstructors : public TestFixture { " ECODES _code;\n" "};"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'Fred::_code' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:5]: (warning) Member variable 'Fred::_code' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A{};\n" @@ -2119,7 +2119,7 @@ class TestConstructors : public TestFixture { "private:\n" " float f;\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'B::f' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:3]: (warning) Member variable 'B::f' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class C\n" "{\n" @@ -2171,7 +2171,7 @@ class TestConstructors : public TestFixture { " };\n" " Bar bars[2];\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Foo::bars' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Foo::bars' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar4() { @@ -2255,7 +2255,7 @@ class TestConstructors : public TestFixture { " }\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:11]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='. [operatorEqVarError]\n", errout_str()); } void uninitVar9() { // ticket #1730 @@ -2269,7 +2269,7 @@ class TestConstructors : public TestFixture { "{\n" " SetMinSize( wxSize( 48,48 ) );\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Prefs::xasd' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (warning) Member variable 'Prefs::xasd' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar10() { // ticket #1993 @@ -2281,7 +2281,7 @@ class TestConstructors : public TestFixture { " int var2;\n" "};\n" "A::A() : var1(0) { }"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'A::var2' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:4]: (warning) Member variable 'A::var2' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar11() { @@ -2292,7 +2292,7 @@ class TestConstructors : public TestFixture { " int var;\n" "};\n" "A::A(int a) { }"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'A::var' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:4]: (warning) Member variable 'A::var' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar12() { // ticket #2078 @@ -2308,8 +2308,8 @@ class TestConstructors : public TestFixture { " {}\n" " int x, y;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Point::x' is not initialized in the constructor.\n" - "[test.cpp:4]: (warning) Member variable 'Point::y' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Point::x' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:4:5]: (warning) Member variable 'Point::y' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar13() { // ticket #1195 @@ -2320,7 +2320,7 @@ class TestConstructors : public TestFixture { " A()\n" " {}\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'A::ints' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'A::ints' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar14() { // ticket #2149 @@ -2335,7 +2335,7 @@ class TestConstructors : public TestFixture { "Foo::Foo()\n" "{\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:6]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // single namespace check("namespace Output\n" @@ -2351,7 +2351,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:10]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor outside namespace check("namespace Output\n" @@ -2383,7 +2383,7 @@ class TestConstructors : public TestFixture { "Output::Foo::Foo()\n" "{\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:14]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor outside namespace with using, #4792 check("namespace Output\n" @@ -2400,7 +2400,7 @@ class TestConstructors : public TestFixture { "Foo::Foo()\n" "{\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:29]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor in separate namespace check("namespace Output\n" @@ -2419,7 +2419,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:10]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor in different separate namespace check("namespace Output\n" @@ -2479,7 +2479,7 @@ class TestConstructors : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:15]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:15:14]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor in nested different separate namespace check("namespace A\n" @@ -2570,7 +2570,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'Bar::foo' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:5]: (warning) Member variable 'Bar::foo' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar17() { @@ -2601,7 +2601,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Bar::foo' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (warning) Member variable 'Bar::foo' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar18() { // ticket #2465 @@ -2653,7 +2653,7 @@ class TestConstructors : public TestFixture { " double bitsInData_;\n" " } obj;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct copy_protected;\n" "Object::MemFunc() {\n" @@ -2665,7 +2665,7 @@ class TestConstructors : public TestFixture { " } obj;\n" "};"); ASSERT_EQUALS( - "[test.cpp:5]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", + "[test.cpp:5:9]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct copy_protected;\n" @@ -2678,7 +2678,7 @@ class TestConstructors : public TestFixture { " } obj;\n" "};"); ASSERT_EQUALS( - "[test.cpp:5]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", + "[test.cpp:5:9]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2723,7 +2723,7 @@ class TestConstructors : public TestFixture { "Fred & Fred::clone(const Fred & other) {\n" " return *this;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:14]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); } void uninitVar23() { // ticket #3702 @@ -2741,11 +2741,11 @@ class TestConstructors : public TestFixture { "Fred::Fred(E e, struct F f) { }\n" "Fred::Fred(G g, H h) { }\n" "Fred::Fred(struct I i, struct J j) { }"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" - "[test.cpp:11]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" - "[test.cpp:12]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" - "[test.cpp:13]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" - "[test.cpp:14]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:11:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:12:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:13:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:14:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar24() { // ticket #3190 @@ -2773,9 +2773,9 @@ class TestConstructors : public TestFixture { "class Bar;\n" "class Sub;\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:9]: (warning, inconclusive) Member variable 'Sub::b' is not initialized in the constructor.\n" - "[test.cpp:12]: (warning) Member variable 'Sub::b' is not initialized in the constructor.\n" - "[test.cpp:20]: (warning) Member variable 'Sub::f' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (warning, inconclusive) Member variable 'Sub::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:12:11]: (warning) Member variable 'Sub::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:20:13]: (warning) Member variable 'Sub::f' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar25() { // ticket #4789 @@ -2821,24 +2821,24 @@ class TestConstructors : public TestFixture { " F(int x = 0, int y = 0, int z = 0);\n" "};\n" "F::F(int, int, int) { }\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'A::a' is not initialized in the constructor.\n" - "[test.cpp:7]: (warning) Member variable 'A::b' is not initialized in the constructor.\n" - "[test.cpp:7]: (warning) Member variable 'A::c' is not initialized in the constructor.\n" - "[test.cpp:14]: (warning) Member variable 'B::a' is not initialized in the constructor.\n" - "[test.cpp:14]: (warning) Member variable 'B::b' is not initialized in the constructor.\n" - "[test.cpp:14]: (warning) Member variable 'B::c' is not initialized in the constructor.\n" - "[test.cpp:21]: (warning) Member variable 'C::a' is not initialized in the constructor.\n" - "[test.cpp:21]: (warning) Member variable 'C::b' is not initialized in the constructor.\n" - "[test.cpp:21]: (warning) Member variable 'C::c' is not initialized in the constructor.\n" - "[test.cpp:28]: (warning) Member variable 'D::a' is not initialized in the constructor.\n" - "[test.cpp:28]: (warning) Member variable 'D::b' is not initialized in the constructor.\n" - "[test.cpp:28]: (warning) Member variable 'D::c' is not initialized in the constructor.\n" - "[test.cpp:35]: (warning) Member variable 'E::a' is not initialized in the constructor.\n" - "[test.cpp:35]: (warning) Member variable 'E::b' is not initialized in the constructor.\n" - "[test.cpp:35]: (warning) Member variable 'E::c' is not initialized in the constructor.\n" - "[test.cpp:42]: (warning) Member variable 'F::a' is not initialized in the constructor.\n" - "[test.cpp:42]: (warning) Member variable 'F::b' is not initialized in the constructor.\n" - "[test.cpp:42]: (warning) Member variable 'F::c' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:7:4]: (warning) Member variable 'A::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:7:4]: (warning) Member variable 'A::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:14:4]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:14:4]: (warning) Member variable 'B::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:14:4]: (warning) Member variable 'B::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:21:4]: (warning) Member variable 'C::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:21:4]: (warning) Member variable 'C::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:21:4]: (warning) Member variable 'C::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:28:4]: (warning) Member variable 'D::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:28:4]: (warning) Member variable 'D::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:28:4]: (warning) Member variable 'D::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:35:4]: (warning) Member variable 'E::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:35:4]: (warning) Member variable 'E::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:35:4]: (warning) Member variable 'E::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:42:4]: (warning) Member variable 'F::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:42:4]: (warning) Member variable 'F::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:42:4]: (warning) Member variable 'F::c' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar26() { @@ -2916,8 +2916,8 @@ class TestConstructors : public TestFixture { " void foo() { }\n" " void foo() const { i = 0; }\n" "};"); - ASSERT_EQUALS("[test.cpp:18]: (warning) Member variable 'C::i' is not initialized in the constructor.\n" - "[test.cpp:25]: (warning) Member variable 'D::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:18:5]: (warning) Member variable 'C::i' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:25:5]: (warning) Member variable 'D::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar30() { // ticket #6417 @@ -2964,7 +2964,7 @@ class TestConstructors : public TestFixture { " if (1) {}\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:4]: (warning) Member variable 'Foo::member' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Foo {\n" " friend class Bar;\n" " int member;\n" @@ -2974,7 +2974,7 @@ class TestConstructors : public TestFixture { " while (1) {}\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:4]: (warning) Member variable 'Foo::member' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Foo {\n" " friend class Bar;\n" " int member;\n" @@ -2984,7 +2984,7 @@ class TestConstructors : public TestFixture { " for (;;) {}\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:4]: (warning) Member variable 'Foo::member' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar33() { // ticket #10295 @@ -2996,7 +2996,7 @@ class TestConstructors : public TestFixture { " };\n" "};\n" "app::B::B(void){}"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'B::x' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:9]: (warning) Member variable 'B::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar34() { // ticket #10841 @@ -3005,7 +3005,7 @@ class TestConstructors : public TestFixture { " B() { a->f(); }\n" " A* a;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVar35() { @@ -3029,7 +3029,7 @@ class TestConstructors : public TestFixture { "private:\n" " char name[255];\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'John::name' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'John::name' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class John\n" "{\n" @@ -3076,7 +3076,7 @@ class TestConstructors : public TestFixture { " John() { }\n" " A (*a)[5];\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'John::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'John::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVarArray2() { @@ -3167,7 +3167,7 @@ class TestConstructors : public TestFixture { "public:\n" " Foo() { }\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::array' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Foo::array' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Foo\n" "{\n" @@ -3203,7 +3203,7 @@ class TestConstructors : public TestFixture { "public:\n" " IxExprListT() {}\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'IxExprListT::eArr' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (warning) Member variable 'IxExprListT::eArr' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct sRAIUnitDefBL {\n" " sRAIUnitDefBL();\n" " ~sRAIUnitDefBL();\n" @@ -3212,7 +3212,7 @@ class TestConstructors : public TestFixture { " sRAIUnitDef() {}\n" " sRAIUnitDefBL *List[35];\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'sRAIUnitDef::List' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:3]: (warning) Member variable 'sRAIUnitDef::List' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVarArray10() { // #11650 @@ -3229,10 +3229,10 @@ class TestConstructors : public TestFixture { "S() {}\n" "};\n", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'S::a' is not initialized in the constructor.\n" - "[test.cpp:10]: (warning) Member variable 'S::b' is not initialized in the constructor.\n" - "[test.cpp:10]: (warning) Member variable 'S::c' is not initialized in the constructor.\n" - "[test.cpp:10]: (warning) Member variable 'S::d' is not initialized in the constructor.\n", + ASSERT_EQUALS("[test.cpp:10:1]: (warning) Member variable 'S::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:10:1]: (warning) Member variable 'S::b' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:10:1]: (warning) Member variable 'S::c' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:10:1]: (warning) Member variable 'S::d' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3297,7 +3297,7 @@ class TestConstructors : public TestFixture { " float get() const;\n" "};\n" "float Fred::get() const { return g; }"); - ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (warning) Member variable 'Fred::g' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVarStruct1() { // ticket #2172 @@ -3327,7 +3327,7 @@ class TestConstructors : public TestFixture { " A() {\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'A::b' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:5]: (warning) Member variable 'A::b' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A\n" "{\n" @@ -3359,7 +3359,7 @@ class TestConstructors : public TestFixture { " Fred()\n" " { }\n" "};"); - ASSERT_EQUALS("[test.cpp:11]: (warning) Member variable 'Fred::p' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:5]: (warning) Member variable 'Fred::p' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct POINT\n" "{\n" @@ -3439,7 +3439,7 @@ class TestConstructors : public TestFixture { " Fred() : data_type(0)\n" " { }\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Fred::data' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (warning) Member variable 'Fred::data' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitMissingFuncDef() { @@ -3473,7 +3473,7 @@ class TestConstructors : public TestFixture { "private:\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown non-member function check("class Fred\n" @@ -3483,7 +3483,7 @@ class TestConstructors : public TestFixture { "private:\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown non-member function check("class ABC { };\n" @@ -3494,7 +3494,7 @@ class TestConstructors : public TestFixture { "private:\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown member functions and unknown static functions check("class ABC {\n" @@ -3514,7 +3514,7 @@ class TestConstructors : public TestFixture { "private:\n" " int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown overloaded member functions check("class Fred : private ABC {\n" @@ -3540,7 +3540,7 @@ class TestConstructors : public TestFixture { " unsigned int i;\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitVarEnum2() { // ticket #8146 @@ -3607,13 +3607,13 @@ class TestConstructors : public TestFixture { " char c;\n" " Foo() { memset(p, 0, sizeof(int)); }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Foo::c' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Foo::c' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct Foo {\n" " int i;\n" " char c;\n" " Foo() { memset(&i, 0, sizeof(int)); }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Foo::c' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Foo::c' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct Foo { int f; };\n" "struct Bar { int b; };\n" "struct FooBar {\n" @@ -3627,7 +3627,7 @@ class TestConstructors : public TestFixture { " FooBar foobar;\n" " return foobar.foo.f + foobar.bar.b;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:3]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct Foo { int f; };\n" "struct Bar { int b; };\n" "struct FooBar {\n" @@ -3641,7 +3641,7 @@ class TestConstructors : public TestFixture { " FooBar foobar;\n" " return foobar.foo.f + foobar.bar.b;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:3]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // #7755 check("struct A {\n" @@ -3669,7 +3669,7 @@ class TestConstructors : public TestFixture { " int foo;\n" " Foo() { }\n" "};", dinit(CheckOptions, $.s = &s)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Foo::foo' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Foo::foo' is not initialized in the constructor. [uninitMemberVarPrivate]\n", errout_str()); } } @@ -3683,7 +3683,7 @@ class TestConstructors : public TestFixture { " explicit Foo(int _i) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Foo::foo' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:14]: (warning) Member variable 'Foo::foo' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3767,7 +3767,7 @@ class TestConstructors : public TestFixture { "\n" " double d;\n" "};"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", "", errout_str()); } void uninitFunction2() { @@ -3793,7 +3793,7 @@ class TestConstructors : public TestFixture { "\n" " double d;\n" "};"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", "", errout_str()); } void uninitFunction3() { @@ -3819,7 +3819,7 @@ class TestConstructors : public TestFixture { "\n" " double d;\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitFunction4() { @@ -3845,7 +3845,7 @@ class TestConstructors : public TestFixture { "\n" " double d;\n" "};"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", "", errout_str()); } void uninitFunction5() { // #4072 - FP about struct that is initialized in function @@ -3871,7 +3871,7 @@ class TestConstructors : public TestFixture { " A() { Init( B ); };\n" " void Init(const Structure& S) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'A::B' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (warning) Member variable 'A::B' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } void uninitSameClassName() { @@ -3922,8 +3922,8 @@ class TestConstructors : public TestFixture { "A::B::B()\n" "{\n" "}"); - ASSERT_EQUALS("[test.cpp:18]: (warning) Member variable 'B::j' is not initialized in the constructor.\n" - "[test.cpp:22]: (warning) Member variable 'B::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:18:4]: (warning) Member variable 'B::j' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:22:7]: (warning) Member variable 'B::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Ticket #1700 check("namespace n1\n" @@ -3965,7 +3965,7 @@ class TestConstructors : public TestFixture { " Foo() { }\n" "};\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (warning) Member variable 'Foo::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:10]: (warning) Member variable 'Foo::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("namespace n1\n" "{\n" @@ -4026,7 +4026,7 @@ class TestConstructors : public TestFixture { " void init(int value)\n" " { }\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'A::i' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (warning) Member variable 'A::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class bar {\n" // #9887 " int length;\n" @@ -4068,8 +4068,8 @@ class TestConstructors : public TestFixture { " return *this;\n" " }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::a' is not initialized in the copy constructor.\n" - "[test.cpp:5]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::a' is not initialized in the copy constructor. [uninitMemberVar]\n" + "[test.cpp:5:9]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='. [operatorEqVarError]\n", errout_str()); } void uninitVarPointer() { // #3801 @@ -4080,28 +4080,28 @@ class TestConstructors : public TestFixture { " A* a;\n" " B() { }\n" "};"); - ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" " A* a;\n" " B() { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" " const A* a;\n" " B() { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" " A* const a;\n" " B() { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Test {\n" // #8498 "public:\n" @@ -4140,8 +4140,8 @@ class TestConstructors : public TestFixture { " B() { }\n" " B(B& b) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the constructor.\n" - "[test.cpp:5]: (warning) Member variable 'B::a' is not initialized in the copy constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:5:5]: (warning) Member variable 'B::a' is not initialized in the copy constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" @@ -4155,8 +4155,8 @@ class TestConstructors : public TestFixture { " B() { }\n" " B(B& b) { }\n" "};"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'B::a' is not initialized in the constructor.\n" - "[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the copy constructor.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n" + "[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the copy constructor. [uninitMemberVar]\n", errout_str()); check("struct B {\n" " const int a;\n" @@ -4217,7 +4217,7 @@ class TestConstructors : public TestFixture { " }\n" "};", dinit(CheckOptions, $.inconclusive = true)); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'C::x' is not initialized in the constructor.\n", - "[test.cpp:3]: (warning) Member variable 'C::x' is not initialized in the constructor.\n", errout_str()); + "[test.cpp:3:5]: (warning) Member variable 'C::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct C {\n" " int x;\n" @@ -4231,7 +4231,7 @@ class TestConstructors : public TestFixture { " }\n" "};", dinit(CheckOptions, $.inconclusive = true)); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'C::x' is not initialized in the constructor.\n", - "[test.cpp:3]: (warning) Member variable 'C::x' is not initialized in the constructor.\n", errout_str()); + "[test.cpp:3:5]: (warning) Member variable 'C::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct C {\n" " int x;\n" From 8343407445489a88e073333e5d928b512e03f47b Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 11:55:18 +0200 Subject: [PATCH 2/4] TestStl: added error IDs and columns to expected output --- test/teststl.cpp | 751 ++++++++++++++++++++++++----------------------- 1 file changed, 376 insertions(+), 375 deletions(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index cf369b44416..2a92cc52455 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -35,7 +35,7 @@ class TestStl : public TestFixture { /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).severity(Severity::performance).library("std.cfg").build(); void run() override { - // TODO: mNewTemplate = true; + mNewTemplate = true; TEST_CASE(outOfBounds); TEST_CASE(outOfBoundsSymbolic); TEST_CASE(outOfBoundsIndexExpression); @@ -951,7 +951,7 @@ class TestStl : public TestFixture { " int x = textline[col];\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds.\n", + "[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\n", errout_str()); } @@ -989,7 +989,7 @@ class TestStl : public TestFixture { " auto it = v.begin();\n" " return *it;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Out of bounds access in expression 'it' because 'v' is empty.\n", + ASSERT_EQUALS("[test.cpp:4:13]: (error) Out of bounds access in expression 'it' because 'v' is empty. [containerOutOfBounds]\n", errout_str()); check("int f() {\n" @@ -998,7 +998,7 @@ class TestStl : public TestFixture { " auto it = v.begin() + 1;\n" " return *it;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning\n", + ASSERT_EQUALS("[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 1 from the beginning [containerOutOfBounds]\n", errout_str()); check("int f() {\n" @@ -1015,7 +1015,7 @@ class TestStl : public TestFixture { " auto it = v.end() - 2;\n" " return *it;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end\n", + ASSERT_EQUALS("[test.cpp:5:13]: (error) Out of bounds access in 'it', if 'v' size is 1 and 'it' is at position 2 from the end [containerOutOfBounds]\n", errout_str()); check("void g(int);\n" @@ -1032,7 +1032,7 @@ class TestStl : public TestFixture { " std::vector::iterator it = vec.begin();\n" " *it = 1;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Out of bounds access in expression 'it' because 'vec' is empty.\n", + ASSERT_EQUALS("[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -1040,7 +1040,7 @@ class TestStl : public TestFixture { " auto it = vec.begin();\n" " *it = 1;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Out of bounds access in expression 'it' because 'vec' is empty.\n", + ASSERT_EQUALS("[test.cpp:4:6]: (error) Out of bounds access in expression 'it' because 'vec' is empty. [containerOutOfBounds]\n", errout_str()); } @@ -1052,7 +1052,7 @@ class TestStl : public TestFixture { " for (std::list::iterator it = l1.begin(); it != l2.end(); ++it)\n" " { }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:40]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); check("void f()\n" @@ -1062,7 +1062,7 @@ class TestStl : public TestFixture { " for (std::list::iterator it = l1.begin(); l2.end() != it; ++it)\n" " { }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l2' and 'l1' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:52]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\n", errout_str()); check("struct C { std::list l1; void func(); };\n" @@ -1082,7 +1082,7 @@ class TestStl : public TestFixture { " for (std::list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\n" " { }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:54]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1097,7 +1097,7 @@ class TestStl : public TestFixture { " ++it;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); check("void foo()\n" @@ -1110,7 +1110,7 @@ class TestStl : public TestFixture { " ++it;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Iterators of different containers 'l2' and 'l1' are used together.\n", + ASSERT_EQUALS("[test.cpp:6:12]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1122,8 +1122,8 @@ class TestStl : public TestFixture { " std::list::iterator it = l1.begin();\n" " l2.insert(it, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n" - "[test.cpp:6]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'.\n", + ASSERT_EQUALS("[test.cpp:6:5]: (error) Same iterator is used with different containers 'l1' and 'l2'. [iterators1]\n" + "[test.cpp:6:5]: (error) Iterator 'it' referring to container 'l1' is used with container 'l2'. [mismatchingContainerIterator]\n", errout_str()); check("void foo() {\n" // #5803 @@ -1180,7 +1180,7 @@ class TestStl : public TestFixture { "{\n" " std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Iterators of different containers 'ints1' and 'ints2' are used together.\n", + ASSERT_EQUALS("[test.cpp:3:47]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1210,7 +1210,7 @@ class TestStl : public TestFixture { "{\n" " std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Iterators of different containers 'ints1' and 'ints2' are used together.\n", + ASSERT_EQUALS("[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\n", errout_str()); check("void foo(std::vector ints1, std::vector ints2)\n" @@ -1225,21 +1225,21 @@ class TestStl : public TestFixture { "{\n" " std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Iterators of different containers 'ints1' and 'ints2' are used together.\n", + ASSERT_EQUALS("[test.cpp:3:56]: (error) Iterators of different containers 'ints1' and 'ints2' are used together. [mismatchingContainers]\n", errout_str()); check("void foo(std::vector ints1, std::vector ints2)\n" "{\n" " std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Iterators of different containers 'ints2' and 'ints1' are used together.\n", + ASSERT_EQUALS("[test.cpp:3:84]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\n", errout_str()); check("void foo(std::vector ints1, std::vector ints2)\n" "{\n" " std::vector::iterator it = std::find_first_of(foo.bar.begin(), foo.bar.end()-6, ints2.begin(), ints1.end());\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Iterators of different containers 'ints2' and 'ints1' are used together.\n", + ASSERT_EQUALS("[test.cpp:3:90]: (error) Iterators of different containers 'ints2' and 'ints1' are used together. [mismatchingContainers]\n", errout_str()); check("void foo(std::vector ints1, std::vector ints2)\n" @@ -1259,8 +1259,8 @@ class TestStl : public TestFixture { "}"); ASSERT_EQUALS( // TODO "[test.cpp:2]: (error) Iterators of different containers are used together.\n" // TODO "[test.cpp:3]: (error) Iterators of different containers are used together.\n" - "[test.cpp:4]: (error) Iterators of different containers 'tp3' and 'a' are used together.\n" - "[test.cpp:5]: (error) Iterators of different containers 'tp4' and 'b' are used together.\n", + "[test.cpp:4:26]: (error) Iterators of different containers 'tp3' and 'a' are used together. [mismatchingContainers]\n" + "[test.cpp:5:26]: (error) Iterators of different containers 'tp4' and 'b' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1329,7 +1329,7 @@ class TestStl : public TestFixture { " if (it != s2.end()) continue;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 's1' and 's2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:39]: (error) Iterators of different containers 's1' and 's2' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1352,7 +1352,7 @@ class TestStl : public TestFixture { " std::map::const_iterator it = map1.find(123);\n" " if (it == map2.end()) { }" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Iterators of different containers 'map1' and 'map2' are used together.\n", + ASSERT_EQUALS("[test.cpp:4:45]: (error) Iterators of different containers 'map1' and 'map2' are used together. [mismatchingContainers]\n", errout_str()); check("void f() {\n" @@ -1361,7 +1361,7 @@ class TestStl : public TestFixture { " std::map::const_iterator it = map1.find(123);\n" " if (map2.end() == it) { }" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'map2' and 'map1' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:9]: (error) Iterators of different containers 'map2' and 'map1' are used together. [mismatchingContainers]\n", errout_str()); check("void f(std::string &s) {\n" @@ -1384,7 +1384,7 @@ class TestStl : public TestFixture { " while (it!=a.end())\n" " ++it;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Iterators of different containers 't' and 'a' are used together.\n", + ASSERT_EQUALS("[test.cpp:8:10]: (error) Iterators of different containers 't' and 'a' are used together. [mismatchingContainers]\n", errout_str()); // #4062 @@ -1446,7 +1446,7 @@ class TestStl : public TestFixture { " ++it1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); check("void foo()\n" @@ -1460,7 +1460,7 @@ class TestStl : public TestFixture { " ++it2;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Iterators of different containers 'l2' and 'l1' are used together.\n", + ASSERT_EQUALS("[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\n", errout_str()); check("void foo()\n" @@ -1474,7 +1474,7 @@ class TestStl : public TestFixture { " ++it1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:6:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); check("void foo()\n" @@ -1488,7 +1488,7 @@ class TestStl : public TestFixture { " ++it1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:35]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1505,7 +1505,7 @@ class TestStl : public TestFixture { " ++it1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); check("void foo()\n" @@ -1551,7 +1551,7 @@ class TestStl : public TestFixture { " ++it1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1584,7 +1584,7 @@ class TestStl : public TestFixture { " {\n" " }\n" "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:5]: (error) Dangerous comparison using operator< on iterator.\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:5:15]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\n", errout_str()); } void iterator19() { @@ -1600,7 +1600,7 @@ class TestStl : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes.\n", + "[test.cpp:7:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\n", errout_str()); check("void foo()\n" @@ -1616,7 +1616,8 @@ class TestStl : public TestFixture { "}"); TODO_ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are defined in different scopes.\n", - "[test.cpp:7] -> [test.cpp:7]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes.\n[test.cpp:7]: (error) Dangerous comparison using operator< on iterator.\n", + "[test.cpp:7:19] -> [test.cpp:7:13]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\n" + "[test.cpp:7:22]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\n", errout_str()); check("void foo()\n" @@ -1632,7 +1633,7 @@ class TestStl : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:8] -> [test.cpp:4]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes.\n", + "[test.cpp:8:13] -> [test.cpp:4:36]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\n", errout_str()); check("void foo()\n" @@ -1648,7 +1649,7 @@ class TestStl : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:8] -> [test.cpp:7]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes.\n", + "[test.cpp:8:13] -> [test.cpp:7:40]: (error) Same iterator is used with containers 'l1' that are temporaries or defined in different scopes. [iterators3]\n", errout_str()); check("std::set g() {\n" @@ -1659,7 +1660,7 @@ class TestStl : public TestFixture { " if (g().find(2) == g().end()) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:6]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes.\n", + "[test.cpp:6:17] -> [test.cpp:6:10]: (error) Same iterator is used with containers 'g()' that are temporaries or defined in different scopes. [iterators3]\n", errout_str()); check("std::set f() {\n" // #5804 @@ -1670,7 +1671,7 @@ class TestStl : public TestFixture { " for (std::set::iterator it = f().begin(); it != f().end(); ++it) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:6]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes.\n", + "[test.cpp:6:53] -> [test.cpp:6:41]: (error) Same iterator is used with containers 'f()' that are temporaries or defined in different scopes. [iterators3]\n", errout_str()); } @@ -1687,7 +1688,7 @@ class TestStl : public TestFixture { " ++it1;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Iterators of different containers 'l2' and 'l1' are used together.\n", + ASSERT_EQUALS("[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\n", errout_str()); check("std::list l3;\n" @@ -1725,8 +1726,8 @@ class TestStl : public TestFixture { " {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n" - "[test.cpp:6]: (error) Iterators of different containers 'l2' and 'l1' are used together.\n", + ASSERT_EQUALS("[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n" + "[test.cpp:6:36]: (error) Iterators of different containers 'l2' and 'l1' are used together. [mismatchingContainers]\n", errout_str()); check("void foo()\n" @@ -1739,8 +1740,8 @@ class TestStl : public TestFixture { " {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n" - "[test.cpp:5]: (error) Iterators of different containers 'l1' and 'l2' are used together.\n", // duplicate + ASSERT_EQUALS("[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n" + "[test.cpp:5:36]: (error) Iterators of different containers 'l1' and 'l2' are used together. [mismatchingContainers]\n", // duplicate errout_str()); } @@ -1778,19 +1779,19 @@ class TestStl : public TestFixture { check("void f(int a, int b) {\n" " if (std::for_each(&a, &b + 1, [](auto) {})) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers 'a' and 'b' are used together.\n", + ASSERT_EQUALS("[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\n", errout_str()); check("void f(int a, int b) {\n" " if (std::for_each(&a, &b, [](auto) {})) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers 'a' and 'b' are used together.\n", + ASSERT_EQUALS("[test.cpp:2:22]: (error) Iterators of different containers 'a' and 'b' are used together. [mismatchingContainers]\n", errout_str()); check("void f(int a) {\n" " if (std::for_each(&a, &a, [](auto) {})) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:21]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); check("void f(int a) {\n" " if (std::for_each(&a, &a + 1, [](auto) {})) {}\n" @@ -1859,7 +1860,7 @@ class TestStl : public TestFixture { " }\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:10]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:24]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); } void iterator29() @@ -1872,7 +1873,7 @@ class TestStl : public TestFixture { " while (it != g().end())\n" " it = v.erase(it);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g()' is used with container 'v'. [mismatchingContainerIterator]\n", errout_str()); check("std::vector& g(int);\n" "void f(int i, int j) {\n" @@ -1881,7 +1882,7 @@ class TestStl : public TestFixture { " while (it != g(j).end())\n" " it = r.erase(it);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:14]: (error) Iterator 'it' referring to container 'g(j)' is used with container 'r'. [mismatchingContainerIterator]\n", errout_str()); check("std::vector& g();\n" "void f() {\n" @@ -1925,8 +1926,8 @@ class TestStl : public TestFixture { " std::string b;\n" " return t.s.a.c_str() == b.c_str();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Iterators of different containers 's.a' and 'b' are used together.\n" - "[test.cpp:13]: (error) Iterators of different containers 't.s.a' and 'b' are used together.\n", + ASSERT_EQUALS("[test.cpp:9:13]: (error) Iterators of different containers 's.a' and 'b' are used together. [mismatchingContainers]\n" + "[test.cpp:13:15]: (error) Iterators of different containers 't.s.a' and 'b' are used together. [mismatchingContainers]\n", errout_str()); } @@ -1936,7 +1937,7 @@ class TestStl : public TestFixture { "void foo() {\n" " (void)std::find(f().begin(), g().end(), 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Iterators of different containers 'f()' and 'g()' are used together.\n", + ASSERT_EQUALS("[test.cpp:4:22]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\n", errout_str()); check("std::vector& f();\n" @@ -1944,7 +1945,7 @@ class TestStl : public TestFixture { "void foo() {\n" " if(f().begin() == g().end()) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Iterators of different containers 'f()' and 'g()' are used together.\n", + ASSERT_EQUALS("[test.cpp:4:9]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\n", errout_str()); check("std::vector& f();\n" @@ -1952,7 +1953,7 @@ class TestStl : public TestFixture { "void foo() {\n" " auto size = f().end() - g().begin();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Iterators of different containers 'f()' and 'g()' are used together.\n", + ASSERT_EQUALS("[test.cpp:4:18]: (error) Iterators of different containers 'f()' and 'g()' are used together. [mismatchingContainers]\n", errout_str()); check("struct A {\n" @@ -1963,7 +1964,7 @@ class TestStl : public TestFixture { " (void)std::find(A().f().begin(), A().g().end(), 0);\n" "}"); ASSERT_EQUALS( - "[test.cpp:6]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together.\n", + "[test.cpp:6:26]: (error) Iterators of different containers 'A().f()' and 'A().g()' are used together. [mismatchingContainers]\n", errout_str()); check("struct A {\n" @@ -1974,7 +1975,7 @@ class TestStl : public TestFixture { " (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\n" "}"); ASSERT_EQUALS( - "[test.cpp:6]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together.\n", + "[test.cpp:6:27]: (error) Iterators of different containers 'A{}.f()' and 'A{}.g()' are used together. [mismatchingContainers]\n", errout_str()); check("std::vector& f();\n" @@ -1982,7 +1983,7 @@ class TestStl : public TestFixture { "void foo() {\n" " (void)std::find(begin(f()), end(g()), 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:28]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together. [mismatchingContainerExpression]\n", errout_str()); check("struct A {\n" " std::vector& f();\n" @@ -2022,7 +2023,7 @@ class TestStl : public TestFixture { " (void)std::find(begin(f()), end(f()) - 1, 0);\n" " (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Dereference of an invalid iterator: f().end()+1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:30]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\n", errout_str()); check("std::vector& f();\n" "void foo() {\n" @@ -2031,8 +2032,8 @@ class TestStl : public TestFixture { " if(f().begin()+1 == f().end()) {}\n" " if(f().begin()+1 == f().end()+1) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Dereference of an invalid iterator: f().end()+1\n" - "[test.cpp:6]: (error) Dereference of an invalid iterator: f().end()+1\n", + ASSERT_EQUALS("[test.cpp:4:32]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\n" + "[test.cpp:6:34]: (error) Dereference of an invalid iterator: f().end()+1 [derefInvalidIterator]\n", errout_str()); check("std::vector& f();\n" @@ -2042,8 +2043,8 @@ class TestStl : public TestFixture { " if(std::begin(f())+1 == std::end(f())) {}\n" " if(std::begin(f())+1 == std::end(f())+1) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Dereference of an invalid iterator: std::end(f())+1\n" - "[test.cpp:6]: (error) Dereference of an invalid iterator: std::end(f())+1\n", + ASSERT_EQUALS("[test.cpp:4:40]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\n" + "[test.cpp:6:42]: (error) Dereference of an invalid iterator: std::end(f())+1 [derefInvalidIterator]\n", errout_str()); check("template\n" @@ -2097,35 +2098,35 @@ class TestStl : public TestFixture { check("void f(std::vector v) {\n" " std::for_each(v.begin(), v.begin(), [](int){});\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); check("std::vector& g();\n" "void f() {\n" " std::for_each(g().begin(), g().begin(), [](int){});\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:28]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); check("void f(std::vector v) {\n" " std::for_each(v.end(), v.end(), [](int){});\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:24]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); check("std::vector& g();\n" "void f() {\n" " std::for_each(g().end(), g().end(), [](int){});\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:26]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); check("std::vector::iterator g();\n" "void f(std::vector v) {\n" " std::for_each(g(), g(), [](int){});\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:20]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); check("void f(std::vector::iterator it) {\n" " std::for_each(it, it, [](int){});\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (style) Same iterators expression are used for algorithm. [sameIteratorExpression]\n", errout_str()); } void mismatchingContainerIterator() { @@ -2134,13 +2135,13 @@ class TestStl : public TestFixture { " a.insert(b.end(), value);\n" " return a;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Iterator 'b.end()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\n", errout_str()); check("std::vector f(std::vector a, std::vector b) {\n" " a.erase(b.begin());\n" " return a;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (error) Iterator 'b.begin()' referring to container 'b' is used with container 'a'. [mismatchingContainerIterator]\n", errout_str()); // #9973 check("void f() {\n" @@ -2154,7 +2155,7 @@ class TestStl : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); // #10012 check("struct a {\n" @@ -2286,27 +2287,27 @@ class TestStl : public TestFixture { " std::vector v;\n" " v.erase(v.begin());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); check("void f() {\n" " std::vector v;\n" " v.erase(v.end());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.end()' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); check("void f() {\n" " std::vector v;\n" " auto it = v.begin();\n" " v.erase(it);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); check("void f() {\n" " std::vector v{ 1, 2, 3 };\n" " auto it = v.end();\n" " v.erase(it);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:7]: (error) Calling function 'erase()' on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); check("void f() {\n" " std::vector v{ 1, 2, 3 };\n" @@ -2325,22 +2326,22 @@ class TestStl : public TestFixture { " std::vector v{ 1, 2, 3 };\n" " v.erase(v.begin() - 1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds.\n" - "[test.cpp:3]: (error) Dereference of an invalid iterator: v.begin()-1\n", + ASSERT_EQUALS("[test.cpp:3:7]: (error) Calling function 'erase()' on the iterator 'v.begin()-1' which is out of bounds. [eraseIteratorOutOfBounds]\n" + "[test.cpp:3:23]: (error) Dereference of an invalid iterator: v.begin()-1 [derefInvalidIterator]\n", errout_str()); check("void f(std::vector& v, std::vector::iterator it) {\n" " if (it == v.end()) {}\n" " v.erase(it);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n", errout_str()); check("void f() {\n" " std::vector v;\n" " ((v).erase)(v.begin());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:3:10]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); } @@ -2354,7 +2355,7 @@ class TestStl : public TestFixture { " ints.erase(iter);\n" " std::cout << (*iter) << std::endl;\n" "}", dinit(CheckOptions, $.inconclusive = true)); - TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid.\n", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:5:22] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\n", errout_str()); // #6554 "False positive eraseDereference - erase in while() loop" check("typedef std::map packetMap;\n" @@ -2403,8 +2404,8 @@ class TestStl : public TestFixture { " ints.erase(iter);\n" " std::cout << iter->first << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n" - "[test.cpp:6]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\n" + "[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); // Reverse iterator @@ -2416,8 +2417,8 @@ class TestStl : public TestFixture { " ints.erase(iter);\n" " std::cout << iter->first << std::endl;\n" "}"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n" - "[test.cpp:6]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:7:18] -> [test.cpp:6:5]: (error) Iterator 'iter' used after element has been erased. [eraseDereference]\n" + "[test.cpp:6:10]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds. [eraseIteratorOutOfBounds]\n", errout_str()); } @@ -2429,7 +2430,7 @@ class TestStl : public TestFixture { " ints.erase(iter);\n" " std::cout << (*iter) << std::endl;\n" "}", dinit(CheckOptions, $.inconclusive = true)); - TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid.\n", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:4:27] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:20]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\n", errout_str()); check("void f() {\n" " auto x = *myList.begin();\n" @@ -2457,7 +2458,7 @@ class TestStl : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:6]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty.\n", + "[test.cpp:6:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\n", errout_str()); check("void foo(std::vector foo) {\n" @@ -2465,21 +2466,21 @@ class TestStl : public TestFixture { " foo.at(ii) = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) When ii==foo.size(), foo.at(ii) is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\n", errout_str()); check("void foo(std::string& foo) {\n" " for (unsigned int ii = 0; ii <= foo.length(); ++ii) {\n" " foo[ii] = 'x';\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) When ii==foo.size(), foo[ii] is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\n", errout_str()); check("void foo(std::string& foo, unsigned int ii) {\n" " if (ii <= foo.length()) {\n" " foo[ii] = 'x';\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) When ii==foo.size(), foo[ii] is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\n", errout_str()); check("void foo(std::string& foo, unsigned int ii) {\n" " do {\n" @@ -2487,7 +2488,7 @@ class TestStl : public TestFixture { " ++i;\n" " } while(ii <= foo.length());\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) When ii==foo.size(), foo[ii] is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\n", errout_str()); check("void foo(std::string& foo, unsigned int ii) {\n" " if (anything()) {\n" @@ -2495,7 +2496,7 @@ class TestStl : public TestFixture { " foo[ii] = 'x';\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) When ii==foo.size(), foo[ii] is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) When ii==foo.size(), foo[ii] is out of bounds. [stlOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" @@ -2519,7 +2520,7 @@ class TestStl : public TestFixture { " foo.at(ii) = 0;\n" " }\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (error) When ii==foo.size(), foo.at(ii) is out of bounds.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3:11]: (error) When ii==foo.size(), foo.at(ii) is out of bounds. [stlOutOfBounds]\n", "", errout_str()); } void STLSizeNoErr() { @@ -2562,7 +2563,7 @@ class TestStl : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:11]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty.\n", + "[test.cpp:11:16]: (error) Out of bounds access in expression 'foo[ii]' because 'foo' is empty. [containerOutOfBounds]\n", errout_str()); } @@ -2589,7 +2590,7 @@ class TestStl : public TestFixture { check("void f(const std::vector &v) {\n" " v[-11] = 123;\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Array index -11 is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:3]: (error) Array index -11 is out of bounds. [negativeContainerIndex]\n", errout_str()); check("int f(int x, const std::vector& a) {\n" " if (!(x < 5))\n" @@ -2681,8 +2682,8 @@ class TestStl : public TestFixture { " foo.erase(it);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Iterator 'it' used after element has been erased.\n" - "[test.cpp:7] -> [test.cpp:8]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n" + "[test.cpp:7:5] -> [test.cpp:8:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); check("void f(std::list &ints)\n" "{\n" @@ -2744,7 +2745,7 @@ class TestStl : public TestFixture { " foo.erase(it);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); check("void f()\n" "{\n" @@ -2754,7 +2755,7 @@ class TestStl : public TestFixture { " foo.erase(it);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); check("void f()\n" "{\n" @@ -2764,7 +2765,7 @@ class TestStl : public TestFixture { " foo.erase(it);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); check("void f()\n" "{\n" @@ -2774,7 +2775,7 @@ class TestStl : public TestFixture { " foo.erase(++it);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:6:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); } void erase5() { @@ -2788,7 +2789,7 @@ class TestStl : public TestFixture { " foo.erase(it);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:8:22]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); } void erase6() { @@ -2814,7 +2815,7 @@ class TestStl : public TestFixture { " break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); check("void f()\n" "{\n" @@ -2837,7 +2838,7 @@ class TestStl : public TestFixture { " return;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:5:18]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); } @@ -2938,7 +2939,7 @@ class TestStl : public TestFixture { "}"); TODO_ASSERT_EQUALS( "[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\n", - "[test.cpp:5] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:7] -> [test.cpp:5] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:5]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid.\n", + "[test.cpp:5:24] -> [test.cpp:7:13] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:7:13] -> [test.cpp:5:31] -> [test.cpp:9:21] -> [test.cpp:3:22] -> [test.cpp:5:28]: (error, inconclusive) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\n", errout_str()); } @@ -3027,7 +3028,7 @@ class TestStl : public TestFixture { " ints.erase(iter);\n" " ints.erase(iter);\n" "}", dinit(CheckOptions, $.inconclusive = true)); - TODO_ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid.\n", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:4] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:1:31] -> [test.cpp:4:22] -> [test.cpp:5:10] -> [test.cpp:1:27] -> [test.cpp:6:16]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\n", errout_str()); } void eraseByValue() { @@ -3046,7 +3047,7 @@ class TestStl : public TestFixture { " foo.erase(*it);\n" " return *it;\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Iterator 'it' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12] -> [test.cpp:3:5]: (error) Iterator 'it' used after element has been erased. [eraseDereference]\n", errout_str()); check("void f(std::set foo)\n" "{\n" @@ -3068,7 +3069,7 @@ class TestStl : public TestFixture { " m_ImplementationMap.erase(*aIt);\n" " m_ImplementationMap.erase(aIt);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Invalid iterator: aIt\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Invalid iterator: aIt [invalidIterator1]\n", errout_str()); check("void f(const std::list& m_ImplementationMap) {\n" " std::list::iterator aIt = m_ImplementationMap.begin();\n" @@ -3090,7 +3091,7 @@ class TestStl : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Iterator 'str' used after element has been erased.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5] -> [test.cpp:4:26]: (error) Iterator 'str' used after element has been erased. [eraseDereference]\n", errout_str()); } void eraseOnVector() { @@ -3099,7 +3100,7 @@ class TestStl : public TestFixture { " v.erase(something(unknown));\n" // All iterators become invalidated when erasing from std::vector " v.erase(aIt);\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'v' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:13]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("void f(std::vector& v) {\n" " std::vector::iterator aIt = v.begin();\n" @@ -3107,7 +3108,7 @@ class TestStl : public TestFixture { " v.erase(bIt);\n" // All iterators become invalidated when erasing from std::vector " aIt = v.erase(aIt);\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:4] -> [test.cpp:1] -> [test.cpp:5]: (error) Using iterator to local container 'v' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27] -> [test.cpp:2:45] -> [test.cpp:4:7] -> [test.cpp:1:26] -> [test.cpp:5:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback1() { @@ -3117,7 +3118,7 @@ class TestStl : public TestFixture { " foo.push_back(123);\n" " *it;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:1] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:35] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:32] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback2() { @@ -3144,7 +3145,7 @@ class TestStl : public TestFixture { " foo.push_back(123);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:6] -> [test.cpp:8] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'foo' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback4() { @@ -3156,7 +3157,7 @@ class TestStl : public TestFixture { " ints.push_back(2);\n" " *first;\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:7]: (error) Using pointer to local variable 'ints' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:18] -> [test.cpp:6:10] -> [test.cpp:3:22] -> [test.cpp:7:6]: (error) Using pointer to local variable 'ints' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback5() { @@ -3189,7 +3190,7 @@ class TestStl : public TestFixture { " v.push_back(10);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:6] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'v' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("void f()\n" "{\n" @@ -3202,7 +3203,7 @@ class TestStl : public TestFixture { " v.push_back(10);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8] -> [test.cpp:8] -> [test.cpp:6] -> [test.cpp:9] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'v' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:49] -> [test.cpp:8:17] -> [test.cpp:8:17] -> [test.cpp:6:56] -> [test.cpp:9:15] -> [test.cpp:3:22] -> [test.cpp:6:53]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback7() { @@ -3216,7 +3217,7 @@ class TestStl : public TestFixture { " foo.push_back(123);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:6] -> [test.cpp:8] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'foo' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback8() { @@ -3232,8 +3233,8 @@ class TestStl : public TestFixture { " sum += *it;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n" - "[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:8]: (error) Using iterator to local container 'ints' that may be invalid.\n", + ASSERT_EQUALS("[test.cpp:10:13]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n" + "[test.cpp:4:52] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:8:35]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\n", errout_str()); } @@ -3264,7 +3265,7 @@ class TestStl : public TestFixture { " foo.reserve(100);\n" " *it = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:1] -> [test.cpp:5]: (error) Using iterator to local container 'foo' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:3:52] -> [test.cpp:4:9] -> [test.cpp:1:26] -> [test.cpp:5:6]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\n", errout_str()); // in loop check("void f()\n" @@ -3277,7 +3278,7 @@ class TestStl : public TestFixture { " foo.reserve(123);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:6] -> [test.cpp:8] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'foo' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:24] -> [test.cpp:6:31] -> [test.cpp:8:13] -> [test.cpp:3:22] -> [test.cpp:6:28]: (error) Using iterator to local container 'foo' that may be invalid. [invalidContainer]\n", errout_str()); } void pushback11() { @@ -3308,7 +3309,7 @@ class TestStl : public TestFixture { " }\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:6] -> [test.cpp:3] -> [test.cpp:9]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid.\n", + "[test.cpp:4:54] -> [test.cpp:6:13] -> [test.cpp:3:25] -> [test.cpp:9:10]: (error, inconclusive) Using iterator to local container 'vec' that may be invalid. [invalidContainer]\n", errout_str()); } @@ -3329,7 +3330,7 @@ class TestStl : public TestFixture { " ints.insert(ints.begin(), 1);\n" " ++iter;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:1] -> [test.cpp:5]: (error) Using iterator to local container 'ints' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:30] -> [test.cpp:3:49] -> [test.cpp:4:10] -> [test.cpp:1:26] -> [test.cpp:5:7]: (error) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\n", errout_str()); check("void f()\n" "{\n" @@ -3346,7 +3347,7 @@ class TestStl : public TestFixture { " ints.insert(iter, 1);\n" " ints.insert(iter, 2);\n" "}", dinit(CheckOptions, $.inconclusive = true)); - TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid.\n", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Using iterator to local container 'ints' that may be invalid.\n", "[test.cpp:4:49] -> [test.cpp:5:10] -> [test.cpp:3:22] -> [test.cpp:6:17]: (error, inconclusive) Using iterator to local container 'ints' that may be invalid. [invalidContainer]\n", errout_str()); check("void* f(const std::vector& bars) {\n" " std::vector::iterator i = bars.begin();\n" @@ -3354,14 +3355,14 @@ class TestStl : public TestFixture { " void* v = &i->foo;\n" " return v;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'bars' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:16]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\n", errout_str()); check("Foo f(const std::vector& bars) {\n" " std::vector::iterator i = bars.begin();\n" " bars.insert(Bar());\n" " return i->foo;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'bars' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:35] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:31] -> [test.cpp:4:12]: (error) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\n", errout_str()); check("void f(const std::vector& bars) {\n" " for(std::vector::iterator i = bars.begin(); i != bars.end(); ++i) {\n" @@ -3377,7 +3378,7 @@ class TestStl : public TestFixture { " i = bars.insert(i, bar);\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:36] -> [test.cpp:2:50] -> [test.cpp:3:14] -> [test.cpp:1:32] -> [test.cpp:4:25]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\n", errout_str()); // TODO: This shouldn't be inconclusive check("void* f(const std::vector& bars) {\n" @@ -3387,7 +3388,7 @@ class TestStl : public TestFixture { " void* v = &i->foo;\n" " return v;\n" "}"); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:37] -> [test.cpp:2:46] -> [test.cpp:3:10] -> [test.cpp:1:33] -> [test.cpp:4:21]: (error, inconclusive) Using iterator to local container 'bars' that may be invalid. [invalidContainer]\n", errout_str()); } void insert2() { @@ -3420,15 +3421,15 @@ class TestStl : public TestFixture { " std::list l;\n" " l.pop_front();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty.\n" - "[test.cpp:5]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty.\n", + ASSERT_EQUALS("[test.cpp:3:15]: (error) Out of bounds access in expression 'v.pop_back()' because 'v' is empty. [containerOutOfBounds]\n" + "[test.cpp:5:16]: (error) Out of bounds access in expression 'l.pop_front()' because 'l' is empty. [containerOutOfBounds]\n", errout_str()); check("void f(std::vector& v) {\n" " if (v.empty()) {}\n" " v.pop_back();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds.\n", + ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:15]: (warning) Either the condition 'v.empty()' is redundant or expression 'v.pop_back()' causes access out of bounds. [containerOutOfBounds]\n", errout_str()); check("void f(std::vector& v) {\n" @@ -3451,14 +3452,14 @@ class TestStl : public TestFixture { " ;\n" "}"); - ASSERT_EQUALS_MSG("[test.cpp:4]: (error) Dangerous comparison using operator< on iterator.\n", errout_str(), stlCont[i]); + ASSERT_EQUALS_MSG("[test.cpp:4:25]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\n", errout_str(), stlCont[i]); } check("void f() {\n" " std::forward_list::iterator it;\n" " for (it = ab.begin(); ab.end() > it; ++it) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous comparison using operator< on iterator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\n", errout_str()); // #5926 no FP Dangerous comparison using operator< on iterator on std::deque check("void f() {\n" @@ -3497,7 +3498,7 @@ class TestStl : public TestFixture { " static set::const_iterator current;\n" " return 25 > current->bar;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid iterator 'current' used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Invalid iterator 'current' used. [eraseDereference]\n", errout_str()); } void stlBoundaries4() { @@ -3506,7 +3507,7 @@ class TestStl : public TestFixture { " std::forward_list>>::iterator it;\n" " for (it = ab.begin(); ab.end() > it; ++it) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous comparison using operator< on iterator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:36]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\n", errout_str()); // don't crash check("void f() {\n" @@ -3520,7 +3521,7 @@ class TestStl : public TestFixture { " for (it = ab.begin(); ab.end() > it; ++it) {}\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous comparison using operator< on iterator.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:40]: (error) Dangerous comparison using operator< on iterator. [stlBoundaries]\n", errout_str()); } void stlBoundaries5() { @@ -3540,7 +3541,7 @@ class TestStl : public TestFixture { " iterator i;\n" " return i.foo();;\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:8]: (error, inconclusive) Invalid iterator 'i' used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:12]: (error, inconclusive) Invalid iterator 'i' used. [eraseDereference]\n", errout_str()); } void stlBoundaries6() { // #7106 @@ -3565,56 +3566,56 @@ class TestStl : public TestFixture { "{\n" " if (s.find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (pointer) check("void f(std::set *s)\n" "{\n" " if ((*s).find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (pointer) check("void f(std::set *s)\n" "{\n" " if (s->find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (array-like pointer) check("void f(std::set *s)\n" "{\n" " if (s[0].find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (array) check("void f(std::set s [10])\n" "{\n" " if (s[0].find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (undefined length array) check("void f(std::set s [])\n" "{\n" " if (s[0].find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (vector) check("void f(std::vector > s)\n" "{\n" " if (s[0].find(12)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // error (assignment) check("void f(std::set s)\n" "{\n" " if (a || (x = s.find(12))) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // ok (simple) check("void f(std::set s)\n" @@ -3678,7 +3679,7 @@ class TestStl : public TestFixture { "{\n" " if (std::find(a,b,c)) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked. [stlIfFind]\n", errout_str()); // ok check("void f()\n" @@ -3713,35 +3714,35 @@ class TestStl : public TestFixture { "{\n" " if (s.find(\"abc\")) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\n", errout_str()); // error (pointer) check("void f(const std::string *s)\n" "{\n" " if ((*s).find(\"abc\")) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\n", errout_str()); // error (pointer) check("void f(const std::string *s)\n" "{\n" " if (s->find(\"abc\")) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\n", errout_str()); // error (vector) check("void f(const std::vector &s)\n" "{\n" " if (s[0].find(\"abc\")) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\n", errout_str()); // #3162 check("void f(const std::string& s1, const std::string& s2)\n" "{\n" " if ((!s1.empty()) && (0 == s1.find(s2))) { }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:32]: (performance) Inefficient usage of string::find() in condition; string::starts_with() could be faster. [stlIfStrFind]\n", errout_str()); // #4102 check("void f(const std::string &define) {\n" @@ -3789,7 +3790,7 @@ class TestStl : public TestFixture { " if (x.size() == 0) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:7]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3801,7 +3802,7 @@ class TestStl : public TestFixture { " if (x.size() == 0) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3813,7 +3814,7 @@ class TestStl : public TestFixture { " if (x.size() == 0) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3825,7 +3826,7 @@ class TestStl : public TestFixture { " if (0 == x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3837,7 +3838,7 @@ class TestStl : public TestFixture { " if (x.size() != 0) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3849,7 +3850,7 @@ class TestStl : public TestFixture { " if (0 != x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3861,7 +3862,7 @@ class TestStl : public TestFixture { " if (x.size() > 0) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3873,7 +3874,7 @@ class TestStl : public TestFixture { " if (0 < x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3885,7 +3886,7 @@ class TestStl : public TestFixture { " if (x.size() >= 1) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3897,7 +3898,7 @@ class TestStl : public TestFixture { " if (x.size() < 1) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3909,7 +3910,7 @@ class TestStl : public TestFixture { " if (1 <= x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3921,7 +3922,7 @@ class TestStl : public TestFixture { " if (1 > x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3933,7 +3934,7 @@ class TestStl : public TestFixture { " if (x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3945,7 +3946,7 @@ class TestStl : public TestFixture { " if (!x.size()) {}\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3964,7 +3965,7 @@ class TestStl : public TestFixture { " fun(!x.size());\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -3976,7 +3977,7 @@ class TestStl : public TestFixture { " fun(a && x.size());\n" "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); - ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", errout_str()); check(code); ASSERT_EQUALS("", errout_str()); } @@ -4014,8 +4015,8 @@ class TestStl : public TestFixture { "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); ASSERT_EQUALS( - "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n" - "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", // duplicate + "[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n" + "[test.cpp:10:11]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", // duplicate errout_str()); check(code); @@ -4037,8 +4038,8 @@ class TestStl : public TestFixture { "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); ASSERT_EQUALS( - "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n" - "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", // duplicate + "[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n" + "[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", // duplicate errout_str()); } @@ -4056,8 +4057,8 @@ class TestStl : public TestFixture { "}"; check(code, dinit(CheckOptions, $.cppstandard = Standards::CPP03)); ASSERT_EQUALS( - "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n" - "[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", // duplicate + "[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n" + "[test.cpp:10:14]: (performance) Possible inefficient checking for 'x' emptiness. [stlSize]\n", // duplicate errout_str()); check(code); @@ -4088,7 +4089,7 @@ class TestStl : public TestFixture { " if (haystack.find(needle) != haystack.end())\n" " haystack.remove(needle);" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Redundant checking of STL container element existence before removing it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Redundant checking of STL container element existence before removing it. [redundantIfRemove]\n", errout_str()); } void missingInnerComparison1() { @@ -4099,7 +4100,7 @@ class TestStl : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Missing bounds check for extra iterator increment in loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:2:71]: (warning) Missing bounds check for extra iterator increment in loop. [StlMissingComparison]\n", errout_str()); check("void f(std::map &ints) {\n" " for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\n" @@ -4152,7 +4153,7 @@ class TestStl : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("function f1(std::list &l1) {\n" " for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\n" @@ -4162,7 +4163,7 @@ class TestStl : public TestFixture { " }\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:23]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); } void missingInnerComparison5() { @@ -4188,50 +4189,50 @@ class TestStl : public TestFixture { " std::string errmsg;\n" " throw errmsg.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after throwing exception. [stlcstrthrow]\n", errout_str()); check("const char *get_msg() {\n" " std::string errmsg;\n" " return errmsg.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("const char *get_msg() {\n" " std::ostringstream errmsg;\n" " return errmsg.str().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("const char *get_msg() {\n" " std::string errmsg;\n" " return std::string(\"ERROR: \" + errmsg).c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("const char *get_msg() {\n" " std::string errmsg;\n" " return (\"ERROR: \" + errmsg).c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("const char *get_msg() {\n" " std::string errmsg;\n" " return (\"ERROR: \" + std::string(\"crash me\")).c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("void f() {\n" " std::ostringstream errmsg;\n" " const char *c = errmsg.str().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("std::string f();\n" "\n" "void foo() {\n" " const char *c = f().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("class Foo {\n" " const char *f();\n" @@ -4240,7 +4241,7 @@ class TestStl : public TestFixture { " std::string s;\n" " return s.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("class Foo {\n" " std::string GetVal() const;\n" @@ -4249,7 +4250,7 @@ class TestStl : public TestFixture { " Foo f;\n" " return f.GetVal().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("const char* foo() {\n" " static std::string text;\n" @@ -4263,13 +4264,13 @@ class TestStl : public TestFixture { " std::string errmsg;\n" " return errmsg.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\n", errout_str()); check("const std::string& get_msg() {\n" " std::string errmsg;\n" " return errmsg.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\n", errout_str()); check("class Foo {\n" " std::string GetVal() const;\n" @@ -4278,7 +4279,7 @@ class TestStl : public TestFixture { " Foo f;\n" " return f.GetVal().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\n", errout_str()); check("std::string get_msg() {\n" " std::string errmsg;\n" @@ -4311,13 +4312,13 @@ class TestStl : public TestFixture { " Foo4(str.c_str(), str.c_str());\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:11]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant.\n" - "[test.cpp:14]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:15]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant.\n" - "[test.cpp:16]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant.\n" - "[test.cpp:17]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:17]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:15:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:16:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:17:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 2 is slow and redundant. [stlcstrParam]\n", errout_str()); check("void Foo1(const std::string& str) {}\n" "void Foo2(char* c, const std::string str) {}\n" @@ -4340,9 +4341,9 @@ class TestStl : public TestFixture { " Foo::sfunc(str.c_str());\n" " foo.func(str.c_str());\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:11]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n", + ASSERT_EQUALS("[test.cpp:9:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:10:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:11:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n", errout_str()); check("void f(const std::string& s);\n" // #8336 @@ -4361,12 +4362,12 @@ class TestStl : public TestFixture { " f(t.u.s.c_str());\n" " f(N::O::s.c_str());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:11]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:12]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:13]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n" - "[test.cpp:14]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant.\n", + ASSERT_EQUALS("[test.cpp:9:9]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:10:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:11:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:12:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:13:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n" + "[test.cpp:14:5]: (performance) Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam]\n", errout_str()); check("void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\n" @@ -4400,7 +4401,7 @@ class TestStl : public TestFixture { "{\n" " return hello().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("class Fred {\n" " std::string hello();\n" @@ -4414,7 +4415,7 @@ class TestStl : public TestFixture { "{\n" " return hello().c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:11]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:11:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); // #4183 - using MyStringClass.c_str() check("void a(const std::string &str);\n" @@ -4447,7 +4448,7 @@ class TestStl : public TestFixture { " const InternalMapInfo* mapInfo = &internal_getMapInfo;\n" " return mapInfo->author.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant. [stlcstrReturn]\n", errout_str()); check("struct InternalMapInfo {\n" " std::string author;\n" @@ -4456,7 +4457,7 @@ class TestStl : public TestFixture { " const InternalMapInfo mapInfo = internal_getMapInfo;\n" " return mapInfo.author.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("struct S {\n" // #7656 " std::string data;\n" @@ -4476,7 +4477,7 @@ class TestStl : public TestFixture { " std::string &ref = s.data;\n" " return ref.c_str();\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("void f(const wchar_t* w, int i = 0, ...);\n" // #10357 "void f(const std::string& s, int i = 0);\n" @@ -4491,7 +4492,7 @@ class TestStl : public TestFixture { " }\n" " std::string m;\n" "};\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]\n", errout_str()); check("struct S {\n" // #10493 " void f(const char** pp);\n" @@ -4512,29 +4513,29 @@ class TestStl : public TestFixture { " std::string b(a.c_str());\n" " return b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Constructing a std::string from the result of c_str() is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\n", errout_str()); check("std::string f(const std::string& a) {\n" " std::string b{ a.c_str() };\n" " return b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Constructing a std::string from the result of c_str() is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\n", errout_str()); check("std::string f(const std::string& a) {\n" " std::string b = a.c_str();\n" " return b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Assigning the result of c_str() to a std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:17]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\n", errout_str()); check("std::string g(const std::string& a, const std::string& b) {\n" " return a + b.c_str();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n", errout_str()); check("std::string g(const std::string& a, const std::string& b) {\n" " return a.c_str() + b;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n", errout_str()); check("std::vector v;\n" // don't crash "int i;\n" @@ -4558,13 +4559,13 @@ class TestStl : public TestFixture { " auto it = t.v.begin()\n" " strm << it->c_str();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n" - "[test.cpp:8]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n" - "[test.cpp:9]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n" - "[test.cpp:10]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n" - "[test.cpp:11]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n" - "[test.cpp:12]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n" - "[test.cpp:14]: (performance) Passing the result of c_str() to a stream is slow and redundant.\n", + ASSERT_EQUALS("[test.cpp:7:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n" + "[test.cpp:8:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n" + "[test.cpp:9:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n" + "[test.cpp:10:19]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n" + "[test.cpp:11:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n" + "[test.cpp:12:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n" + "[test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n", errout_str()); check("struct S { std::string str; };\n" @@ -4576,15 +4577,15 @@ class TestStl : public TestFixture { " else\n" " str = u.t[0].s.str.c_str();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (performance) Assigning the result of c_str() to a std::string is slow and redundant.\n" - "[test.cpp:8]: (performance) Assigning the result of c_str() to a std::string is slow and redundant.\n", + ASSERT_EQUALS("[test.cpp:6:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\n" + "[test.cpp:8:9]: (performance) Assigning the result of c_str() to a std::string is slow and redundant. [stlcstrAssignment]\n", errout_str()); check("void f(std::string_view);\n" // #11547 "void g(const std::string & s) {\n" " f(s.c_str());\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant.\n", + ASSERT_EQUALS("[test.cpp:3:5]: (performance) Passing the result of c_str() to a function that takes std::string_view as argument no. 1 is slow and redundant. [stlcstrParam]\n", errout_str()); check("std::string_view f(const std::string& s) {\n" @@ -4595,8 +4596,8 @@ class TestStl : public TestFixture { " std::string_view sv{ s.c_str() };\n" " return sv;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant.\n" - "[test.cpp:6]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant.\n", + ASSERT_EQUALS("[test.cpp:2:22]: (performance) Assigning the result of c_str() to a std::string_view is slow and redundant. [stlcstrAssignment]\n" + "[test.cpp:6:22]: (performance) Constructing a std::string_view from the result of c_str() is slow and redundant. [stlcstrConstructor]\n", errout_str()); check("void f(const std::string& s) {\n" // #11819 @@ -4629,7 +4630,7 @@ class TestStl : public TestFixture { " s1.swap(s2);\n" " s2.swap(s2);\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)'\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)' [uselessCallsSwap]\n", errout_str()); check("void f()\n" "{\n" @@ -4639,7 +4640,7 @@ class TestStl : public TestFixture { " s1.compare(s2.c_str());\n" " s1.compare(0, s1.size(), s1);\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:16]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0. [uselessCallsCompare]\n", errout_str()); // #7370 False positive uselessCallsCompare on unknown type check("class ReplayIteratorImpl{\n" @@ -4662,11 +4663,11 @@ class TestStl : public TestFixture { " s1 = s2.substr(0,std::string::npos);\n" " s1 = s2.substr(x+5-n, 0);\n" "};"); - ASSERT_EQUALS("[test.cpp:5]: (performance) Ineffective call of function \'substr\' because it returns a copy of " - "the object. Use operator= instead.\n" - "[test.cpp:8]: (performance) Ineffective call of function \'substr\' because it returns a copy of " - "the object. Use operator= instead.\n" - "[test.cpp:9]: (performance) Ineffective call of function \'substr\' because it returns an empty string.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (performance) Ineffective call of function \'substr\' because it returns a copy of " + "the object. Use operator= instead. [uselessCallsSubstr]\n" + "[test.cpp:8:10]: (performance) Ineffective call of function \'substr\' because it returns a copy of " + "the object. Use operator= instead. [uselessCallsSubstr]\n" + "[test.cpp:9:10]: (performance) Ineffective call of function \'substr\' because it returns an empty string. [uselessCallsSubstr]\n", errout_str()); check("void f()\n" "{\n" @@ -4691,7 +4692,7 @@ class TestStl : public TestFixture { " v.empty();\n" " return v.empty();\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead?\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Ineffective call of function 'empty()'. Did you intend to call 'clear()' instead? [uselessCallsEmpty]\n", errout_str()); check("void f() {\n" // #4938 " OdString str;\n" @@ -4715,9 +4716,9 @@ class TestStl : public TestFixture { " a.erase(std::remove(a.begin(), a.end(), val));\n" " std::remove(\"foo.txt\");\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of std::remove() ignored. Elements remain in container.\n" - "[test.cpp:3]: (warning) Return value of std::remove_if() ignored. Elements remain in container.\n" - "[test.cpp:4]: (warning) Return value of std::unique() ignored. Elements remain in container.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5]: (warning) Return value of std::remove() ignored. Elements remain in container. [uselessCallsRemove]\n" + "[test.cpp:3:5]: (warning) Return value of std::remove_if() ignored. Elements remain in container. [uselessCallsRemove]\n" + "[test.cpp:4:5]: (warning) Return value of std::unique() ignored. Elements remain in container. [uselessCallsRemove]\n", errout_str()); // #4431 - fp check("bool f() {\n" @@ -4736,49 +4737,49 @@ class TestStl : public TestFixture { " s = s.substr(0, s.size() - 1);\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead.\n", + ASSERT_EQUALS("[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\n", errout_str()); check("std::string f(std::string s, std::size_t start, std::size_t end, const std::string& i) {\n" " s = s.substr(0, start) + i + s.substr(end + 1);\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead.\n", + ASSERT_EQUALS("[test.cpp:2:9]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use replace() instead. [uselessCallsSubstr]\n", errout_str()); check("std::string f(std::string s, std::size_t end) {\n" " s = { s.begin(), s.begin() + end };\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\n", errout_str()); check("std::list f(std::list l, std::size_t end) {\n" " l = { l.begin(), l.begin() + end };\n" " return l;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (performance) Inefficient constructor call: container 'l' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\n", errout_str()); check("std::string f(std::string s, std::size_t end) {\n" " s = std::string{ s.begin(), s.begin() + end };\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\n", errout_str()); check("std::string f(std::string s, std::size_t end) {\n" " s = std::string(s.begin(), s.begin() + end);\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (performance) Inefficient constructor call: container 's' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\n", errout_str()); check("std::vector f(std::vector v, std::size_t end) {\n" " v = std::vector(v.begin(), v.begin() + end);\n" " return v;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (performance) Inefficient constructor call: container 'v' is assigned a partial copy of itself. Use erase() or resize() instead. [uselessCallsConstructor]\n", errout_str()); } @@ -4804,7 +4805,7 @@ class TestStl : public TestFixture { " std::cout << *i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); check("void foo(std::string::iterator& i) {\n" " if(foo) { bar(); }\n" @@ -4812,7 +4813,7 @@ class TestStl : public TestFixture { " std::cout << *i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test suggested correction doesn't report an error check("void foo(std::string::iterator& i) {\n" @@ -4829,7 +4830,7 @@ class TestStl : public TestFixture { " i ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); check("void foo(std::string::iterator& i) {\n" " do {\n" @@ -4837,7 +4838,7 @@ class TestStl : public TestFixture { " i ++;\n" " } while (std::isalpha(*i) && i != str.end());\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:27]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test "while" with "||" case check("void foo(std::string::iterator& i) {\n" @@ -4846,7 +4847,7 @@ class TestStl : public TestFixture { " i ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test fix for "while" with "||" case check("void foo(std::string::iterator& i) {\n" @@ -4864,7 +4865,7 @@ class TestStl : public TestFixture { " i ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test "for" with "||" case check("void foo(std::string::iterator& i) {\n" @@ -4873,7 +4874,7 @@ class TestStl : public TestFixture { " i ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test that a dereference outside the condition part of a "for" // loop does not result in a false positive @@ -4891,7 +4892,7 @@ class TestStl : public TestFixture { " std::cout << *i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:28]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test that dereference of different variable doesn't trigger a false positive check("void foo(const char* c, std::string::iterator& i) {\n" @@ -4908,7 +4909,7 @@ class TestStl : public TestFixture { " i ++;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:25]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); // Test that mixed "&&" and "||" don't result in a false positive check("void foo(std::string::iterator& i) {\n" @@ -4923,26 +4924,26 @@ class TestStl : public TestFixture { " std::vector ::iterator i = v.end();\n" " *i=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); check("void f() {\n" " std::vector v;\n" " std::vector ::iterator i = std::end(v);\n" " *i=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v) {\n" " std::vector ::iterator i = v.end();\n" " *i=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v) {\n" " std::vector ::iterator i = v.end();\n" " *(i+1)=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dereference of an invalid iterator: i+1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (error) Dereference of an invalid iterator: i+1 [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v) {\n" " std::vector ::iterator i = v.end();\n" @@ -4954,13 +4955,13 @@ class TestStl : public TestFixture { " std::vector ::iterator i = v.begin();\n" " *(i-1)=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dereference of an invalid iterator: i-1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v) {\n" " std::vector ::iterator i = std::begin(v);\n" " *(i-1)=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dereference of an invalid iterator: i-1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:8]: (error) Dereference of an invalid iterator: i-1 [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v, bool b) {\n" " std::vector ::iterator i = v.begin();\n" @@ -4968,7 +4969,7 @@ class TestStl : public TestFixture { " i = v.end();\n" " *i=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:6]: (warning) Possible dereference of an invalid iterator: i [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v, bool b) {\n" " std::vector ::iterator i = v.begin();\n" @@ -4976,7 +4977,7 @@ class TestStl : public TestFixture { " i = v.end();\n" " *(i+1)=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i+1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i+1 [derefInvalidIterator]\n", errout_str()); check("void f(std::vector v, bool b) {\n" " std::vector ::iterator i = v.begin();\n" @@ -4984,7 +4985,7 @@ class TestStl : public TestFixture { " i = v.end();\n" " *(i-1)=0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i-1\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (warning) Possible dereference of an invalid iterator: i-1 [derefInvalidIterator]\n", errout_str()); check("int f(std::vector v, int pos) {\n" " if (pos >= 0)\n" @@ -4997,28 +4998,28 @@ class TestStl : public TestFixture { " if (it != v.end()) {}\n" " return *it;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:4:13]: (warning) Either the condition 'it!=v.end()' is redundant or there is possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(std::vector & v) {\n" " std::vector::iterator i= v.begin();\n" " if(i == v.end() && *(i+1) == *i) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n" - "[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:3:27]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n" + "[test.cpp:3:10] -> [test.cpp:3:35]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(std::vector & v) {\n" " std::vector::iterator i= v.begin();\n" " if(i == v.end() && *i == *(i+1)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i.\n" - "[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:3:25]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i. [derefInvalidIteratorRedundantCheck]\n" + "[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(std::vector & v) {\n" " std::vector::iterator i= v.begin();\n" " if(i != v.end() && *i == *(i+1)) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:3:33]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(std::vector & v) {\n" " std::vector::iterator i= v.begin();\n" @@ -5026,14 +5027,14 @@ class TestStl : public TestFixture { " if (*(i+1) == *i) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:16]: (warning) Either the condition 'i!=v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(std::vector & v) {\n" " std::vector::iterator i= v.begin();\n" " if(i == v.end()) { return; }\n" " if (*(i+1) == *i) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:12]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(std::vector & v) {\n" " std::vector::iterator i= v.begin();\n" @@ -5052,7 +5053,7 @@ class TestStl : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:37] -> [test.cpp:4:30]: (warning) Either the condition '(i+1)!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+2. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(int v, std::map &items) {\n" " for (auto it = items.begin(); it != items.end();)\n" @@ -5094,7 +5095,7 @@ class TestStl : public TestFixture { " if(i == v.end() && bar(*(i+1)) ) {}\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:4]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", + "[test.cpp:4:10] -> [test.cpp:4:31]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n", errout_str()); // #10657 @@ -5128,7 +5129,7 @@ class TestStl : public TestFixture { " e.clear();\n" " auto f = *e[d].begin();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty.\n", + ASSERT_EQUALS("[test.cpp:9:23]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty. [containerOutOfBounds]\n", errout_str()); // #10151 @@ -5138,7 +5139,7 @@ class TestStl : public TestFixture { " return s.erase(it);\n" " return s.end();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); // #11381 check("int f(std::map& map) {\n" @@ -5167,7 +5168,7 @@ class TestStl : public TestFixture { " if (i + 1 != s.end()) {}\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", + ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:2:29]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1. [derefInvalidIteratorRedundantCheck]\n", errout_str()); check("void f(bool b, std::vector v) {\n" // #12680 @@ -5224,7 +5225,7 @@ class TestStl : public TestFixture { " it->m_place = 0;\n" " return it;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:18]: (error, inconclusive) Invalid iterator 'it' used.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:18:5]: (error, inconclusive) Invalid iterator 'it' used. [eraseDereference]\n", errout_str()); } void loopAlgoElementAssign() { @@ -5233,35 +5234,35 @@ class TestStl : public TestFixture { " x = 1;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::fill algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Consider using std::fill algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " for(int& x:v)\n" " x = x + 1;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo(int a, int b) {\n" " for(int& x:v)\n" " x = a + b;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Consider using std::fill or std::generate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " for(int& x:v)\n" " x += 1;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " for(int& x:v)\n" " x = f();\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::generate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Consider using std::generate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " for(int& x:v) {\n" @@ -5306,7 +5307,7 @@ class TestStl : public TestFixture { " n += x;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5314,7 +5315,7 @@ class TestStl : public TestFixture { " n = n + x;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5322,7 +5323,7 @@ class TestStl : public TestFixture { " n += 1;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::distance algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5330,7 +5331,7 @@ class TestStl : public TestFixture { " n = n + 1;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::distance algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool f(int);\n" "void foo() {\n" @@ -5386,8 +5387,8 @@ class TestStl : public TestFixture { " }\n" " return t; \n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n" - "[test.cpp:7]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n" + "[test.cpp:7:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("int g(const std::vector& v) {\n" @@ -5397,7 +5398,7 @@ class TestStl : public TestFixture { " }\n" " return t;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("auto g(const std::vector& v) {\n" " std::vector::iterator> r;\n" @@ -5447,7 +5448,7 @@ class TestStl : public TestFixture { " s += v[i];\n" " return s;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("int f(int n) {\n" " int s = 0;\n" @@ -5475,7 +5476,7 @@ class TestStl : public TestFixture { " c.push_back(x);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::copy algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " std::vector c;\n" @@ -5483,7 +5484,7 @@ class TestStl : public TestFixture { " c.push_back(f(x));\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " std::vector c;\n" @@ -5491,7 +5492,7 @@ class TestStl : public TestFixture { " c.push_back(x + 1);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " std::vector c;\n" @@ -5499,7 +5500,7 @@ class TestStl : public TestFixture { " c.push_front(x);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::copy algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " std::vector c;\n" @@ -5507,7 +5508,7 @@ class TestStl : public TestFixture { " c.push_front(f(x));\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " std::vector c;\n" @@ -5515,7 +5516,7 @@ class TestStl : public TestFixture { " c.push_front(x + 1);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " std::vector c;\n" @@ -5541,7 +5542,7 @@ class TestStl : public TestFixture { " n++;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::distance algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5549,21 +5550,21 @@ class TestStl : public TestFixture { " ++n;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::distance algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::distance algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " for(int& x:v)\n" " x++;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " for(int& x:v)\n" " ++x;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); } void loopAlgoConditional() { @@ -5576,7 +5577,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::replace_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (style) Consider using std::replace_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void foo() {\n" @@ -5588,7 +5589,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:6]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:15]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void foo() {\n" @@ -5600,7 +5601,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:6]: (style) Consider using std::count_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:15]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void foo() {\n" @@ -5612,7 +5613,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:6]: (style) Consider using std::count_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:13]: (style) Consider using std::count_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void foo() {\n" @@ -5623,7 +5624,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::transform algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (style) Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void foo() {\n" @@ -5635,7 +5636,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:6]: (style) Consider using std::copy_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:14]: (style) Consider using std::copy_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "bool foo() {\n" @@ -5647,7 +5648,7 @@ class TestStl : public TestFixture { " return true;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:3:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" @@ -5660,7 +5661,7 @@ class TestStl : public TestFixture { " return true;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void f();\n" @@ -5673,7 +5674,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:22]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "void f(int x);\n" @@ -5686,7 +5687,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:22]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool pred(int x);\n" "bool foo() {\n" @@ -5808,7 +5809,7 @@ class TestStl : public TestFixture { " }\n" " return ret;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:20]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("struct T {\n" " std::vector v0, v1;\n" @@ -5824,7 +5825,7 @@ class TestStl : public TestFixture { " v1.erase(it1);\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:0]: (style) Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool f(const std::set& set, const std::string& f) {\n" // #11595 " for (const std::string& s : set) {\n" @@ -5834,7 +5835,7 @@ class TestStl : public TestFixture { " }\n" " return false;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void f() {\n" // #12064 @@ -5881,7 +5882,7 @@ class TestStl : public TestFixture { " n = x > n ? x : n;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::max_element algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5889,7 +5890,7 @@ class TestStl : public TestFixture { " n = x < n ? x : n;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::min_element algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5897,7 +5898,7 @@ class TestStl : public TestFixture { " n = x > n ? n : x;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::min_element algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo() {\n" " int n = 0;\n" @@ -5905,7 +5906,7 @@ class TestStl : public TestFixture { " n = x < n ? n : x;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::max_element algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void foo(int m) {\n" " int n = 0;\n" @@ -5913,7 +5914,7 @@ class TestStl : public TestFixture { " n = x > m ? x : n;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::accumulate algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("void f(const std::vector& v) {\n" // #9091 " int maxY = 0;\n" @@ -5923,7 +5924,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::max_element algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:18]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("int f(const std::vector& v) {\n" " int minY = 0;\n" @@ -5934,7 +5935,7 @@ class TestStl : public TestFixture { " return minY;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (style) Consider using std::min_element algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:18]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("int f(const std::vector& v) {\n" " int max = 0;\n" @@ -5943,7 +5944,7 @@ class TestStl : public TestFixture { " return max;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::max_element algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Consider using std::max_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("int f(const std::vector& v) {\n" @@ -5953,7 +5954,7 @@ class TestStl : public TestFixture { " return min;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::min_element algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:4:13]: (style) Consider using std::min_element algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); } @@ -5969,7 +5970,7 @@ class TestStl : public TestFixture { " return false;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool g(const std::vector& v) {\n" @@ -5982,7 +5983,7 @@ class TestStl : public TestFixture { " return false;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("bool g(const std::vector& v) {\n" @@ -6058,7 +6059,7 @@ class TestStl : public TestFixture { " return false;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop.\n", + ASSERT_EQUALS("[test.cpp:2:5]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("class C {\n" @@ -6086,7 +6087,7 @@ class TestStl : public TestFixture { " std::cout << *v0 << std::endl;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'v' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27] -> [test.cpp:2:22] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:19]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("std::string e();\n" "void a() {\n" @@ -6106,7 +6107,7 @@ class TestStl : public TestFixture { " std::cout << (*v0)[0] << std::endl;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error) Using pointer to local variable 'v' that may be invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:27] -> [test.cpp:2:15] -> [test.cpp:3:7] -> [test.cpp:1:26] -> [test.cpp:4:20]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("void f() {\n" " std::vector v = {1};\n" @@ -6116,7 +6117,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:5]: (error) Reference to v that may be invalid.\n", + "[test.cpp:3:13] -> [test.cpp:3:17] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\n", errout_str()); check("void f() {\n" @@ -6126,7 +6127,7 @@ class TestStl : public TestFixture { " std::cout << v0 << std::endl;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:5]: (error) Reference to v that may be invalid.\n", + ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:4:7] -> [test.cpp:5:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\n", errout_str()); check("void f(std::vector &v) {\n" @@ -6136,7 +6137,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:2] -> [test.cpp:1] -> [test.cpp:3] -> [test.cpp:4]: (error) Reference to v that may be invalid.\n", + "[test.cpp:2:13] -> [test.cpp:2:17] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\n", errout_str()); check("void f(std::vector &v) {\n" @@ -6146,7 +6147,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3] -> [test.cpp:4]: (error) Reference to v that may be invalid.\n", + "[test.cpp:2:13] -> [test.cpp:1:27] -> [test.cpp:3:7] -> [test.cpp:4:18]: (error) Reference to v that may be invalid. [invalidContainerReference]\n", errout_str()); check("void f(std::vector &v) {\n" @@ -6279,7 +6280,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:8] -> [test.cpp:12] -> [test.cpp:9]: (error) Using iterator to member container 'v' that may be invalid.\n", + "[test.cpp:7:44] -> [test.cpp:8:5] -> [test.cpp:12:7] -> [test.cpp:9:5]: (error) Using iterator to member container 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("void foo(std::vector& v) {\n" @@ -6292,7 +6293,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:7] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'v' that may be invalid.\n", + "[test.cpp:1:29] -> [test.cpp:2:44] -> [test.cpp:3:5] -> [test.cpp:7:7] -> [test.cpp:1:28] -> [test.cpp:4:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); // #10264 @@ -6331,7 +6332,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Using pointer to local variable 'v' that may be invalid.\n", + "[test.cpp:3:24] -> [test.cpp:3:18] -> [test.cpp:3:14] -> [test.cpp:4:7] -> [test.cpp:2:10] -> [test.cpp:5:19]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("struct A {\n" @@ -6383,7 +6384,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:1] -> [test.cpp:5]: (error) Using iterator to local container 'v' that may be invalid.\n", + "[test.cpp:2:22] -> [test.cpp:3:33] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("void f(std::vector v) {\n" @@ -6394,7 +6395,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:1] -> [test.cpp:5]: (error) Using iterator to local container 'v' that may be invalid.\n", + "[test.cpp:2:22] -> [test.cpp:4:7] -> [test.cpp:1:25] -> [test.cpp:5:5]: (error) Using iterator to local container 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("struct A {\n" @@ -6409,7 +6410,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:8] -> [test.cpp:5] -> [test.cpp:9]: (error) Using object that points to local variable 'v' that may be invalid.\n", + "[test.cpp:7:15] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\n", errout_str()); check("struct A {\n" @@ -6424,7 +6425,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:5] -> [test.cpp:9]: (error) Using object that points to local variable 'v' that may be invalid.\n", + "[test.cpp:6:21] -> [test.cpp:7:9] -> [test.cpp:8:7] -> [test.cpp:5:25] -> [test.cpp:9:5]: (error) Using object that points to local variable 'v' that may be invalid. [invalidContainer]\n", errout_str()); // #11028 @@ -6445,7 +6446,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:4]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead.\n", + "[test.cpp:4:13]: (performance) Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]\n", errout_str()); // #11630 @@ -6474,7 +6475,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:4]: (error) Using pointer to local variable 'v' that may be invalid.\n", + "[test.cpp:1:26] -> [test.cpp:2:30] -> [test.cpp:1:26] -> [test.cpp:2:20] -> [test.cpp:2:20] -> [test.cpp:3:7] -> [test.cpp:1:25] -> [test.cpp:4:13]: (error) Using pointer to local variable 'v' that may be invalid. [invalidContainer]\n", errout_str()); // #9834 @@ -6490,7 +6491,7 @@ class TestStl : public TestFixture { "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:7] -> [test.cpp:7] -> [test.cpp:8] -> [test.cpp:9]: (error) Reference to vec1 that may be invalid.\n", + "[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\n", errout_str()); } @@ -6503,7 +6504,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Calling 'push_back' while iterating the container is invalid.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:5] -> [test.cpp:4:15]: (error) Calling 'push_back' while iterating the container is invalid. [invalidContainerLoop]\n", errout_str()); // #9713 check("void f() {\n" @@ -6516,7 +6517,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Consider using std::any_of algorithm instead of a raw loop.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:17]: (style) Consider using std::any_of algorithm instead of a raw loop. [useStlAlgorithm]\n", errout_str()); check("struct A {\n" " std::vector v;\n" @@ -6530,7 +6531,7 @@ class TestStl : public TestFixture { "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:7] -> [test.cpp:8]: (error) Calling 'add' while iterating the container is invalid.\n", + "[test.cpp:4:7] -> [test.cpp:7:5] -> [test.cpp:8:7]: (error) Calling 'add' while iterating the container is invalid. [invalidContainerLoop]\n", errout_str()); } @@ -6541,7 +6542,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f2(std::map& m, unsigned x) {\n" " if (m.find(x) == m.end()) {\n" @@ -6551,7 +6552,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f3(std::map& m, unsigned x) {\n" " if (m.count(x) == 0) {\n" @@ -6559,7 +6560,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f4(std::set& s, unsigned x) {\n" " if (s.find(x) == s.end()) {\n" @@ -6567,7 +6568,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f5(std::map& m, unsigned x) {\n" " if (m.count(x) == 0) {\n" @@ -6577,7 +6578,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f6(std::map& m, unsigned x) {\n" " if (m.count(x) == 0) {\n" @@ -6585,7 +6586,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f1(std::unordered_set& s, unsigned x) {\n" " if (s.find(x) == s.end()) {\n" @@ -6593,7 +6594,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f2(std::unordered_map& m, unsigned x) {\n" " if (m.find(x) == m.end()) {\n" @@ -6603,7 +6604,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f3(std::unordered_map& m, unsigned x) {\n" " if (m.count(x) == 0) {\n" @@ -6611,7 +6612,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f4(std::unordered_set& s, unsigned x) {\n" " if (s.find(x) == s.end()) {\n" @@ -6619,7 +6620,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f5(std::unordered_map& m, unsigned x) {\n" " if (m.count(x) == 0) {\n" @@ -6629,7 +6630,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void f6(std::unordered_map& m, unsigned x) {\n" " if (m.count(x) == 0) {\n" @@ -6637,7 +6638,7 @@ class TestStl : public TestFixture { " }\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); check("void g1(std::map& m, unsigned x) {\n" " if (m.find(x) == m.end()) {\n" @@ -6767,7 +6768,7 @@ class TestStl : public TestFixture { check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP14)); ASSERT_EQUALS("", errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.cppstandard = Standards::CPP17)); - ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str()); } { // #10558 @@ -6791,7 +6792,7 @@ class TestStl : public TestFixture { " x[5] = data;\n" " }\n" "}", dinit(CheckOptions, $.cppstandard = Standards::CPP11)); - ASSERT_EQUALS("[test.cpp:7]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'. [stlFindInsert]\n", errout_str()); check("void foo() {\n" " std::map x;\n" @@ -6802,7 +6803,7 @@ class TestStl : public TestFixture { " x[5] = data;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:17]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'. [stlFindInsert]\n", errout_str()); } } @@ -6812,21 +6813,21 @@ class TestStl : public TestFixture { " for(auto x:v) {}\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Iterating over container 'v' that is always empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\n", errout_str()); check("void f(std::vector v) {\n" " v.clear();\n" " for(auto x:v) {}\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Iterating over container 'v' that is always empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\n", errout_str()); check("void f(std::vector v) {\n" " if (!v.empty()) { return; }\n" " for(auto x:v) {}\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Iterating over container 'v' that is always empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (style) Iterating over container 'v' that is always empty. [knownEmptyContainer]\n", errout_str()); check("void f(std::vector v) {\n" " if (v.empty()) { return; }\n" @@ -6840,7 +6841,7 @@ class TestStl : public TestFixture { " std::sort(v.begin(), v.end());\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (style) Using sort with iterator 'v.begin()' that is always empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:22]: (style) Using sort with iterator 'v.begin()' that is always empty. [knownEmptyContainer]\n", errout_str()); check("void f() {\n" // #1201 " std::vector v1{ 0, 1 };\n" @@ -6848,7 +6849,7 @@ class TestStl : public TestFixture { " std::copy(v1.begin(), v1.end(), v2.begin());\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (style) Using copy with iterator 'v2.begin()' that is always empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:45]: (style) Using copy with iterator 'v2.begin()' that is always empty. [knownEmptyContainer]\n", errout_str()); check("void f() {\n" " std::vector v;\n" @@ -6892,7 +6893,7 @@ class TestStl : public TestFixture { " for (const auto &a : arr) {}\n" "}", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:7]: (style) Iterating over container 'arr' that is always empty.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:26]: (style) Iterating over container 'arr' that is always empty. [knownEmptyContainer]\n", errout_str()); check("struct S {\n" " std::vector v;\n" @@ -6972,7 +6973,7 @@ class TestStl : public TestFixture { " static std::lock_guard g(m);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:40]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\n", errout_str()); check("void f() {\n" " static std::mutex m;\n" @@ -6987,7 +6988,7 @@ class TestStl : public TestFixture { " static std::lock(g);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:41]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\n", errout_str()); check("void f() {\n" " static std::mutex m;\n" @@ -7002,14 +7003,14 @@ class TestStl : public TestFixture { " std::lock_guard g(m);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\n", errout_str()); check("void f() {\n" " std::mutex m;\n" " std::unique_lock g(m);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\n", errout_str()); check("void f() {\n" " std::mutex m;\n" @@ -7017,7 +7018,7 @@ class TestStl : public TestFixture { " std::lock(g);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:3]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:34]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\n", errout_str()); check("void g();\n" "void f() {\n" @@ -7037,7 +7038,7 @@ class TestStl : public TestFixture { " m.unlock();\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\n", errout_str()); check("class A {\n" " std::mutex m;\n" @@ -7067,7 +7068,7 @@ class TestStl : public TestFixture { " }\n" "};\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:44]: (warning) Lock guard is defined globally. Lock guards are intended to be local. A global lock guard could lead to a deadlock since it won't unlock until the end of the program. [globalLockGuard]\n", errout_str()); check("std::mutex& h();\n" "void f() {\n" @@ -7094,7 +7095,7 @@ class TestStl : public TestFixture { " std::lock_guard g(m);\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:4]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:33]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\n", errout_str()); check("void g();\n" "std::mutex& h();\n" @@ -7105,7 +7106,7 @@ class TestStl : public TestFixture { " m.unlock();\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("[test.cpp:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (warning) The lock is ineffective because the mutex is locked at the same scope as the mutex itself. [localMutex]\n", errout_str()); check("void foo();\n" "void bar();\n" From 314a70b5e36d3533340103f854eeb55debf95796 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 12:20:05 +0200 Subject: [PATCH 3/4] TestLeakAutoVar: added error IDs and columns to expected output --- test/testleakautovar.cpp | 414 ++++++++++++++++++++------------------- 1 file changed, 209 insertions(+), 205 deletions(-) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 656a71fc19c..d74892e9c27 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -33,7 +33,7 @@ class TestLeakAutoVar : public TestFixture { const Settings settings = settingsBuilder().library("std.cfg").build(); void run() override { - // TODO: mNewTemplate = true; + mNewTemplate = true; // Assign TEST_CASE(assign1); TEST_CASE(assign2); @@ -250,7 +250,7 @@ class TestLeakAutoVar : public TestFixture { " p = NULL;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign2() { @@ -338,7 +338,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " x = a(b(p));\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function b() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.c:4:1]: (information) --check-library: Function b() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } void assign12() { // #4236: FP. bar(&x) @@ -358,7 +358,7 @@ class TestLeakAutoVar : public TestFixture { " p = malloc(10);\n" " free(ref);\n" "}", dinit(CheckOptions, $.cpp = true)); - TODO_ASSERT_EQUALS("", "[test.cpp:6]: (error) Memory leak: p\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:6:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign14() { @@ -366,13 +366,13 @@ class TestLeakAutoVar : public TestFixture { " char *p;\n" " if (x && (p = malloc(10))) { }" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:35]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f(int x) {\n" " char *p;\n" " if (x && (p = new char[10])) { }" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:37]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign15() { @@ -400,12 +400,12 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = (char*)malloc(10);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " char *p = (char*)(int*)malloc(10);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign18() { @@ -413,13 +413,13 @@ class TestLeakAutoVar : public TestFixture { " char *p;\n" " if (x && (p = (char*)malloc(10))) { }" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:42]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f(int x) {\n" " char *p;\n" " if (x && (p = (char*)(int*)malloc(10))) { }" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:48]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign19() { @@ -434,7 +434,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = static_cast(malloc(10));\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign21() { @@ -449,7 +449,7 @@ class TestLeakAutoVar : public TestFixture { " S* s = new S();\n" " (void)s;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: s\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:1]: (error) Memory leak: s [memleak]\n", errout_str()); } void assign22() { // #9139 @@ -457,12 +457,12 @@ class TestLeakAutoVar : public TestFixture { check("void f(char tempFileName[256]) {\n" " const int fd = socket(AF_INET, SOCK_PACKET, 0 );\n" "}", dinit(CheckOptions, $.cpp = true, $.s = &s)); - ASSERT_EQUALS("[test.cpp:3]: (error) Resource leak: fd\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:1]: (error) Resource leak: fd [resourceLeak]\n", errout_str()); check("void f() {\n" " const void * const p = malloc(10);\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign23() { @@ -484,20 +484,20 @@ class TestLeakAutoVar : public TestFixture { " *(&(*&n13)) = open(\"xx.log\", O_RDONLY);\n" " ((*&(*&n14))) = open(\"xx.log\", O_RDONLY);\n" "}\n", dinit(CheckOptions, $.cpp = true, $.s = &s)); - ASSERT_EQUALS("[test.cpp:17]: (error) Resource leak: n1\n" - "[test.cpp:17]: (error) Resource leak: n2\n" - "[test.cpp:17]: (error) Resource leak: n3\n" - "[test.cpp:17]: (error) Resource leak: n4\n" - "[test.cpp:17]: (error) Resource leak: n5\n" - "[test.cpp:17]: (error) Resource leak: n6\n" - "[test.cpp:17]: (error) Resource leak: n7\n" - "[test.cpp:17]: (error) Resource leak: n8\n" - "[test.cpp:17]: (error) Resource leak: n9\n" - "[test.cpp:17]: (error) Resource leak: n10\n" - "[test.cpp:17]: (error) Resource leak: n11\n" - "[test.cpp:17]: (error) Resource leak: n12\n" - "[test.cpp:17]: (error) Resource leak: n13\n" - "[test.cpp:17]: (error) Resource leak: n14\n", + ASSERT_EQUALS("[test.cpp:17:1]: (error) Resource leak: n1 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n2 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n3 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n4 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n5 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n6 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n7 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n8 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n9 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n10 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n11 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n12 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n13 [resourceLeak]\n" + "[test.cpp:17:1]: (error) Resource leak: n14 [resourceLeak]\n", errout_str()); } @@ -522,7 +522,7 @@ class TestLeakAutoVar : public TestFixture { " *p = 42;\n" " g();\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function g() should have configuration\n", + ASSERT_EQUALS("[test.cpp:4:8]: (information) --check-library: Function g() should have configuration [checkLibraryNoReturn]\n", errout_str()); check("void g();\n" @@ -531,7 +531,7 @@ class TestLeakAutoVar : public TestFixture { " *p = 42;\n" " g();\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("void g() {}\n" "void f() {\n" @@ -539,7 +539,7 @@ class TestLeakAutoVar : public TestFixture { " *p = 42;\n" " g();\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("[[noreturn]] void g();\n" "void f() {\n" @@ -562,7 +562,7 @@ class TestLeakAutoVar : public TestFixture { " char* p = malloc(10);\n" " g();\n" "}\n"); - ASSERT_EQUALS("[test.c:5]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:5:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign25() { @@ -570,8 +570,8 @@ class TestLeakAutoVar : public TestFixture { " int* p{ new int };\n" " int* q(new int);\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n" - "[test.cpp:4]: (error) Memory leak: q\n", + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: p [memleak]\n" + "[test.cpp:4:1]: (error) Memory leak: q [memleak]\n", errout_str()); check("struct S : B {\n" // #12239 @@ -658,14 +658,14 @@ class TestLeakAutoVar : public TestFixture { " char *str = strdup(value);\n" " memcpy(old, str, len);\n" "}\n", dinit(CheckOptions, $.cpp = true, $.s = &s)); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: str [memleak]\n", errout_str()); } void isAutoDealloc() { check("void f() {\n" " char *p = new char[100];" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:29]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " Fred *fred = new Fred;" @@ -675,7 +675,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " std::string *str = new std::string;" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2]: (error) Memory leak: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:40]: (error) Memory leak: str [memleak]\n", errout_str()); check("class TestType {\n" // #9028 "public:\n" @@ -684,13 +684,13 @@ class TestLeakAutoVar : public TestFixture { "void f() {\n" " TestType *tt = new TestType();\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: tt\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:1]: (error) Memory leak: tt [memleak]\n", errout_str()); check("void f(Bar& b) {\n" // #7622 " char* data = new char[10];\n" " b = Bar(*new Foo(data));\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function Foo() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function Foo() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("class B {};\n" " class D : public B {};\n" @@ -698,7 +698,7 @@ class TestLeakAutoVar : public TestFixture { " auto d = new D();\n" " if (d) {}\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: d\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:1]: (error) Memory leak: d [memleak]\n", errout_str()); check("struct S {\n" // #12354 " int i{};\n" @@ -709,7 +709,7 @@ class TestLeakAutoVar : public TestFixture { " p = new S();\n" " p->f();\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void realloc1() { @@ -726,7 +726,7 @@ class TestLeakAutoVar : public TestFixture { " void *p = malloc(10);\n" " void *q = realloc(p, 20);\n" "}"); - ASSERT_EQUALS("[test.c:4]: (error) Memory leak: q\n", errout_str()); + ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: q [memleak]\n", errout_str()); } void realloc3() { @@ -734,7 +734,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " char *q = (char*) realloc(p, 20);\n" "}"); - ASSERT_EQUALS("[test.c:4]: (error) Memory leak: q\n", errout_str()); + ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: q [memleak]\n", errout_str()); } void realloc4() { @@ -743,7 +743,7 @@ class TestLeakAutoVar : public TestFixture { " if (q == NULL)\n" " return;\n" "}"); - ASSERT_EQUALS("[test.c:5]: (error) Memory leak: q\n", errout_str()); + ASSERT_EQUALS("[test.c:5:1]: (error) Memory leak: q [memleak]\n", errout_str()); } void realloc5() { @@ -785,7 +785,7 @@ class TestLeakAutoVar : public TestFixture { " void *p = fopen(name,a);\n" " void *q = freopen(name, b, p);\n" "}"); - ASSERT_EQUALS("[test.c:4]: (error) Resource leak: q\n", errout_str()); + ASSERT_EQUALS("[test.c:4:1]: (error) Resource leak: q [resourceLeak]\n", errout_str()); } void deallocuse1() { @@ -793,13 +793,13 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " *p = 0;\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:3:6]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("void f(char *p) {\n" " free(p);\n" " char c = *p;\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:3:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); } void deallocuse3() { @@ -807,7 +807,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " p = p->next;\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:3:9]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); } void deallocuse4() { @@ -815,7 +815,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " return p;\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:2:5] -> [test.c:3:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); check("void f(char *p) {\n" " if (!p) free(p);\n" @@ -875,7 +875,7 @@ class TestLeakAutoVar : public TestFixture { " delete foo->ptr;\n" " x = *foo->ptr;\n" "}", dinit(CheckOptions, $.cpp = true)); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:6]: (error) Dereferencing 'ptr' after it is deallocated / released [deallocuse]\n", "", errout_str()); check("void parse() {\n" " struct Buf {\n" @@ -912,7 +912,7 @@ class TestLeakAutoVar : public TestFixture { " delete(ptr);\n" " *ptr = 0;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Dereferencing 'ptr' after it is deallocated / released [deallocuse]\n", errout_str()); } void deallocuse9() { @@ -948,13 +948,13 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " p[0] = 10;\n" "}\n"); - ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:3:5]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("int f(int* p) {\n" " free(p);\n" " return p[1];\n" "}\n"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:2:5] -> [test.c:3:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); } void deallocuse11() { // #8302 @@ -963,14 +963,14 @@ class TestLeakAutoVar : public TestFixture { " delete [] array;\n" " return array[1];" // << "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:3] -> [test.cpp:4:3]: (error) Returning/dereferencing 'array' after it is deallocated / released [deallocret]\n", errout_str()); check("int f() {\n" " int *array = (int*)malloc(40);\n" " free(array);\n" " return array[1];" // << "}"); - ASSERT_EQUALS("[test.c:3] -> [test.c:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:3:3] -> [test.c:4:3]: (error) Returning/dereferencing 'array' after it is deallocated / released [deallocret]\n", errout_str()); } void deallocuse12() { @@ -993,8 +993,8 @@ class TestLeakAutoVar : public TestFixture { " free(b);\n" " b[1] = 0;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'a' after it is deallocated / released\n" - "[test.cpp:7]: (error) Dereferencing 'b' after it is deallocated / released\n", + ASSERT_EQUALS("[test.cpp:4:5]: (error) Dereferencing 'a' after it is deallocated / released [deallocuse]\n" + "[test.cpp:7:5]: (error) Dereferencing 'b' after it is deallocated / released [deallocuse]\n", errout_str()); } @@ -1005,7 +1005,7 @@ class TestLeakAutoVar : public TestFixture { " delete s;\n" " s->f();\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 's' after it is deallocated / released\n", + ASSERT_EQUALS("[test.cpp:5:5]: (error) Dereferencing 's' after it is deallocated / released [deallocuse]\n", errout_str()); check("void f() {\n" @@ -1013,7 +1013,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " if (*p == 5) {}\n" "}\n"); - ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n", + ASSERT_EQUALS("[test.c:4:10]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("int g(int);\n" @@ -1025,8 +1025,8 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " return g(*p);\n" "}\n"); - ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n" - "[test.c:7] -> [test.c:8]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", + ASSERT_EQUALS("[test.c:4:8]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n" + "[test.c:7:5] -> [test.c:8:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); check("int g(int);\n" @@ -1038,8 +1038,8 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " return g(1 + *p);\n" "}\n"); - ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n" - "[test.c:7] -> [test.c:8]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", + ASSERT_EQUALS("[test.c:4:12]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n" + "[test.c:7:5] -> [test.c:8:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); check("int g(int, int);\n" @@ -1051,14 +1051,14 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " return g(0, 1 + *p);\n" "}\n"); - ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n" - "[test.c:7] -> [test.c:8]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", + ASSERT_EQUALS("[test.c:4:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n" + "[test.c:7:5] -> [test.c:8:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); check("void f() {\n" " FOREACH(callables, ());\n" "}\n"); - ASSERT_EQUALS("[test.c:2]: (information) --check-library: Function FOREACH() should have configuration\n", errout_str()); // don't crash + ASSERT_EQUALS("[test.c:2:27]: (information) --check-library: Function FOREACH() should have configuration [checkLibraryNoReturn]\n", errout_str()); // don't crash check("int f() {\n" // #12321 " std::invoke([](int i) {\n" @@ -1098,7 +1098,7 @@ class TestLeakAutoVar : public TestFixture { " int i = ftell(h);\n" " return i;\n" "}\n"); - ASSERT_EQUALS("[test.c:5]: (error) Dereferencing 'h' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.c:5:19]: (error) Dereferencing 'h' after it is deallocated / released [deallocuse]\n", errout_str()); } void deallocuse16() { @@ -1108,7 +1108,7 @@ class TestLeakAutoVar : public TestFixture { " delete (a, c);\n" " *c = 10;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'c' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:6]: (error) Dereferencing 'c' after it is deallocated / released [deallocuse]\n", errout_str()); } void doublefree1() { // #3895 @@ -1119,14 +1119,14 @@ class TestLeakAutoVar : public TestFixture { " p = 0;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:3] -> [test.c:6]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:3:9] -> [test.c:6:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p) {\n" " free(p);\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:3] -> [test.c:3:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p, char *r) {\n" @@ -1163,7 +1163,7 @@ class TestLeakAutoVar : public TestFixture { " bar();\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p) {\n" @@ -1171,8 +1171,8 @@ class TestLeakAutoVar : public TestFixture { " printf(\"Freed memory at location %x\", p);\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n" - "[test.c:2] -> [test.c:4]: (error) Memory pointed to by 'p' is freed twice.\n", + ASSERT_EQUALS("[test.c:3:41]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n" + "[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( @@ -1180,7 +1180,7 @@ class TestLeakAutoVar : public TestFixture { " fclose(p);\n" " fclose(p);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Resource handle 'p' freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:3] -> [test.c:3:3]: (error) Resource handle 'p' freed twice. [doubleFree]\n", errout_str()); check( "void foo(FILE *p, FILE *r) {\n" @@ -1210,7 +1210,7 @@ class TestLeakAutoVar : public TestFixture { " gethandle();\n" " fclose(p);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:4]: (error) Resource handle 'p' freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:3] -> [test.c:4:3]: (error) Resource handle 'p' freed twice. [doubleFree]\n", errout_str()); check( "void foo(Data* p) {\n" @@ -1239,7 +1239,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:4] -> [test.c:7]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:4:9] -> [test.c:7:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void f() {\n" @@ -1255,7 +1255,7 @@ class TestLeakAutoVar : public TestFixture { " delete p;\n" " delete p;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:10]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p, char *r) {\n" @@ -1292,14 +1292,14 @@ class TestLeakAutoVar : public TestFixture { " bar();\n" " delete p;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:4:10]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p) {\n" " delete[] p;\n" " delete[] p;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:12]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p, char *r) {\n" @@ -1322,7 +1322,7 @@ class TestLeakAutoVar : public TestFixture { " bar();\n" " delete[] p;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:12]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "LineMarker::~LineMarker() {\n" @@ -1366,7 +1366,7 @@ class TestLeakAutoVar : public TestFixture { " delete a;\n" " return 0;\n" "}", dinit(CheckOptions, $.cpp = true)); - TODO_ASSERT_EQUALS("", "[test.cpp:8] -> [test.cpp:11]: (error) Memory pointed to by 'a' is freed twice.\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:8:8] -> [test.cpp:11:15]: (error) Memory pointed to by 'a' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(int y)\n" @@ -1456,7 +1456,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:6] -> [test.c:8]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:6:9] -> [test.c:8:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void MyFunction()\n" @@ -1579,7 +1579,7 @@ class TestLeakAutoVar : public TestFixture { " x = (q == p);\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); } void doublefree6() { // #7685 @@ -1612,35 +1612,35 @@ class TestLeakAutoVar : public TestFixture { " std::unique_ptr x(i);\n" " delete i;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("void f() {\n" " int * i = new int;\n" " delete i;\n" " std::unique_ptr x(i);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:4:28]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("void f() {\n" " int * i = new int;\n" " std::unique_ptr x{i};\n" " delete i;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("void f() {\n" " int * i = new int;\n" " std::shared_ptr x(i);\n" " delete i;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("void f() {\n" " int * i = new int;\n" " std::shared_ptr x{i};\n" " delete i;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); // Check for use-after-free FP check("void f() {\n" @@ -1655,7 +1655,7 @@ class TestLeakAutoVar : public TestFixture { " std::unique_ptr x(i);\n" " delete i;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:4:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("using namespace std;\n" // #9708 "void f() {\n" @@ -1663,7 +1663,7 @@ class TestLeakAutoVar : public TestFixture { " unique_ptr x(i);\n" " delete i;\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:5:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); } void doublefree9() { @@ -1716,7 +1716,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " free(q);\n" "}"); - ASSERT_EQUALS("[test.c:3] -> [test.c:8]: (error) Memory pointed to by 'p' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.c:3:16] -> [test.c:8:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); } void doublefree12() { // #10502 @@ -1752,7 +1752,7 @@ class TestLeakAutoVar : public TestFixture { " unique_ptr x(i);\n" " delete i;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7]: (error) Memory pointed to by 'i' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5] -> [test.cpp:7:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("using namespace std;\n" " \n" @@ -1798,7 +1798,7 @@ class TestLeakAutoVar : public TestFixture { " delete (a, c);\n" " delete (b, c);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6]: (error) Memory pointed to by 'c' is freed twice.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:6:16]: (error) Memory pointed to by 'c' is freed twice. [doubleFree]\n", errout_str()); } void exit1() { @@ -1814,7 +1814,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " fatal_error();\n" "}"); - ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function fatal_error() should have configuration\n", + ASSERT_EQUALS("[test.c:3:18]: (information) --check-library: Function fatal_error() should have configuration [checkLibraryNoReturn]\n", errout_str()); } @@ -1882,7 +1882,7 @@ class TestLeakAutoVar : public TestFixture { " char* b = new char[len + 1]{};\n" " std::string str = std::string(b);\n" "}", dinit(CheckOptions, $.cpp = true, $.s = &s)); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: b [memleak]\n", errout_str()); } void goto1() { @@ -1940,7 +1940,7 @@ class TestLeakAutoVar : public TestFixture { " if (x) { p = malloc(10); }\n" " else { return 0; }\n" "}"); - ASSERT_EQUALS("[test.c:5]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:5:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void ifelse3() { @@ -2009,7 +2009,7 @@ class TestLeakAutoVar : public TestFixture { " else\n" " a = 0;\n" "}"); - ASSERT_EQUALS("[test.c:6]: (error) Memory leak: a\n", errout_str()); + ASSERT_EQUALS("[test.c:6:9]: (error) Memory leak: a [memleak]\n", errout_str()); } void ifelse7() { // #5576 @@ -2171,7 +2171,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " free(q);\n" "}"); - ASSERT_EQUALS("[test.c:5]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:5:9]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " void * p = malloc(10);\n" @@ -2182,7 +2182,7 @@ class TestLeakAutoVar : public TestFixture { " } else\n" " return;\n" "}"); - ASSERT_EQUALS("[test.c:8]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:8:9]: (error) Memory leak: p [memleak]\n", errout_str()); } void ifelse19() { @@ -2204,8 +2204,8 @@ class TestLeakAutoVar : public TestFixture { " void * p2 = malloc(2);\n" " return;\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p1\n" - "[test.c:5]: (error) Memory leak: p2\n", errout_str()); + ASSERT_EQUALS("[test.c:3:0]: (error) Memory leak: p1 [memleak]\n" + "[test.c:5:0]: (error) Memory leak: p2 [memleak]\n", errout_str()); check("void f() {\n" " if (x > 0)\n" @@ -2213,8 +2213,8 @@ class TestLeakAutoVar : public TestFixture { " else\n" " void * p2 = malloc(2);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p1\n" - "[test.c:5]: (error) Memory leak: p2\n", errout_str()); + ASSERT_EQUALS("[test.c:3:0]: (error) Memory leak: p1 [memleak]\n" + "[test.c:5:0]: (error) Memory leak: p2 [memleak]\n", errout_str()); } void ifelse21() { @@ -2226,7 +2226,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " return;\n" "}"); - ASSERT_EQUALS("[test.c:6]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:6:5]: (error) Memory leak: p [memleak]\n", errout_str()); } void ifelse22() { // #10187 @@ -2251,7 +2251,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " if (FILE* fp = fopen(\"x\", \"r\")) {}\n" "}\n"); - ASSERT_EQUALS("[test.c:2]: (error) Resource leak: fp\n", errout_str()); + ASSERT_EQUALS("[test.c:2:38]: (error) Resource leak: fp [resourceLeak]\n", errout_str()); } void ifelse24() { // #1733 @@ -2263,9 +2263,9 @@ class TestLeakAutoVar : public TestFixture { " if (NULL == x || NULL == (fp = fopen(temp, \"rt\")))\n" " return;\n" "}\n", s); - ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: temp\n" - "[test.cpp:6]: (error) Memory leak: temp\n" - "[test.cpp:6]: (error) Resource leak: fp\n", + ASSERT_EQUALS("[test.cpp:5:9]: (error) Memory leak: temp [memleak]\n" + "[test.cpp:6:1]: (error) Memory leak: temp [memleak]\n" + "[test.cpp:6:1]: (error) Resource leak: fp [resourceLeak]\n", errout_str()); check("FILE* f() {\n" @@ -2273,7 +2273,7 @@ class TestLeakAutoVar : public TestFixture { " FILE* fp = fopen(temp, \"rt\");\n" " return fp;\n" "}\n", s); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: temp\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (error) Memory leak: temp [memleak]\n", errout_str()); check("FILE* f() {\n" " char* temp = strdup(\"temp.txt\");\n" @@ -2281,7 +2281,7 @@ class TestLeakAutoVar : public TestFixture { " fopen_s(&fp, temp, \"rt\");\n" " return fp;\n" "}\n", s); - ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: temp\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (error) Memory leak: temp [memleak]\n", errout_str()); check("void f() {\n" " char* temp = strdup(\"temp.txt\");\n" @@ -2289,8 +2289,8 @@ class TestLeakAutoVar : public TestFixture { " if (fp)\n" " freopen(temp, \"rt\", fp);\n" "}\n", s); - ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: temp\n" - "[test.cpp:6]: (error) Resource leak: fp\n", + ASSERT_EQUALS("[test.cpp:6:1]: (error) Memory leak: temp [memleak]\n" + "[test.cpp:6:1]: (error) Resource leak: fp [resourceLeak]\n", errout_str()); check("FILE* f() {\n" @@ -2416,13 +2416,13 @@ class TestLeakAutoVar : public TestFixture { " FILE*f=fopen(fname,a);\n" " free(f);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Mismatching allocation and deallocation: f\n", errout_str()); + ASSERT_EQUALS("[test.c:2:12] -> [test.c:3:5]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " free((void*)f);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Mismatching allocation and deallocation: f\n", errout_str()); + ASSERT_EQUALS("[test.c:2:12] -> [test.c:3:5]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " char *cPtr = new char[100];\n" @@ -2432,13 +2432,13 @@ class TestLeakAutoVar : public TestFixture { " cPtr = new char[100];\n" " delete cPtr;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7]: (error) Mismatching allocation and deallocation: cPtr\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:7:12]: (error) Mismatching allocation and deallocation: cPtr [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " char *cPtr = new char[100];\n" " free(cPtr);\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: cPtr\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:3:5]: (error) Mismatching allocation and deallocation: cPtr [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " char *cPtr = new (buf) char[100];\n" @@ -2449,21 +2449,21 @@ class TestLeakAutoVar : public TestFixture { " int * i = new int[1];\n" " std::unique_ptr x(i);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:3:28]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " int * i = new int;\n" " std::unique_ptr x(i);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " void* a = malloc(1);\n" " void* b = freopen(f, p, a);\n" " free(b);\n" "}"); - ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Mismatching allocation and deallocation: a\n" - "[test.c:3] -> [test.c:4]: (error) Mismatching allocation and deallocation: b\n", errout_str()); + ASSERT_EQUALS("[test.c:2:14] -> [test.c:3:14]: (error) Mismatching allocation and deallocation: a [mismatchAllocDealloc]\n" + "[test.c:3:14] -> [test.c:4:4]: (error) Mismatching allocation and deallocation: b [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " void* a;\n" @@ -2477,8 +2477,8 @@ class TestLeakAutoVar : public TestFixture { " int * j = realloc(i, 2 * sizeof(int));\n" " delete[] j;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: i\n" - "[test.cpp:3] -> [test.cpp:4]: (error) Mismatching allocation and deallocation: j\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:14]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\n" + "[test.cpp:3:14] -> [test.cpp:4:13]: (error) Mismatching allocation and deallocation: j [mismatchAllocDealloc]\n", errout_str()); check("static void deleter(int* p) { free(p); }\n" // #11392 "void f() {\n" @@ -2507,7 +2507,7 @@ class TestLeakAutoVar : public TestFixture { " FILE*f=fopen(fname,a);\n" " std::unique_ptr fp{f};\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: f\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" @@ -2560,13 +2560,13 @@ class TestLeakAutoVar : public TestFixture { " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, [](FILE* x) { free(f); }};\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: f\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, [](FILE* x) {}};\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: f\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("class C;\n" "void f() {\n" @@ -2588,7 +2588,7 @@ class TestLeakAutoVar : public TestFixture { "void openDir(DIR* dir) {\n" " std::shared_ptr dp(dir, DirDeleter());\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: Function closedir() should have configuration\n", errout_str()); // don't crash + ASSERT_EQUALS("[test.cpp:2:44]: (information) --check-library: Function closedir() should have configuration [checkLibraryNoReturn]\n", errout_str()); // don't crash } void smartPointerRelease() { check("void f() {\n" @@ -2604,7 +2604,7 @@ class TestLeakAutoVar : public TestFixture { " std::unique_ptr x(i);\n" " x.release();\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: i\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:1]: (error) Memory leak: i [memleak]\n", errout_str()); } void return1() { @@ -2612,7 +2612,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(100);\n" " return 123;\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); } void return2() { @@ -2694,7 +2694,7 @@ class TestLeakAutoVar : public TestFixture { " void *x = malloc(1);\n" " return (uint8_t)x;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: x [memleak]\n", errout_str()); check("void** f() {\n" " void *x = malloc(1);\n" @@ -2712,7 +2712,7 @@ class TestLeakAutoVar : public TestFixture { " void *x = malloc(1);\n" " return (void*)(short)x;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: x [memleak]\n", errout_str()); check("void* f() {\n" " void *x = malloc(1);\n" @@ -2724,7 +2724,7 @@ class TestLeakAutoVar : public TestFixture { " void *x = malloc(1);\n" " return (mytype)y;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: x [memleak]\n", errout_str()); } void return8() { @@ -2767,7 +2767,7 @@ class TestLeakAutoVar : public TestFixture { " p[0] = 'x';\n" " return p[0];\n" "}"); - ASSERT_EQUALS("[test.c:4]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:4:5]: (error) Memory leak: p [memleak]\n", errout_str()); check("struct S { int f(); };\n" // #11746 "int g() {\n" @@ -2775,14 +2775,14 @@ class TestLeakAutoVar : public TestFixture { " delete s;\n" " return s->f();\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Returning/dereferencing 's' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:5:5]: (error) Returning/dereferencing 's' after it is deallocated / released [deallocret]\n", errout_str()); check("int f() {\n" " int* p = new int(3);\n" " delete p;\n" " return *p;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:4:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); } void return11() { // #13098 @@ -2794,7 +2794,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " return 'a';\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: ptr\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:5]: (error) Memory leak: ptr [memleak]\n", errout_str()); check("char malloc_memleak(void) {\n" " bool flag = false;\n" @@ -2804,7 +2804,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " return 'a';\n" "}\n"); - ASSERT_EQUALS("[test.c:7]: (error) Memory leak: ptr\n", errout_str()); + ASSERT_EQUALS("[test.c:7:5]: (error) Memory leak: ptr [memleak]\n", errout_str()); } void test1() { @@ -2817,7 +2817,7 @@ class TestLeakAutoVar : public TestFixture { " p = (int*)malloc(4);\n" " p = (int*)malloc(4);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " int* p = (int*)malloc(4);\n" @@ -2832,7 +2832,7 @@ class TestLeakAutoVar : public TestFixture { " free(r);\n" " p = (int*)malloc(4);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - TODO_ASSERT_EQUALS("", "[test.cpp:6]: (error) Memory leak: p\n", errout_str()); + TODO_ASSERT_EQUALS("", "[test.cpp:6:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void test2() { // 3899 @@ -2862,10 +2862,10 @@ class TestLeakAutoVar : public TestFixture { void test5() { // unknown type check("void f() { Fred *p = malloc(10); }", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:1]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:34]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() { Fred *p = malloc(10); }"); - ASSERT_EQUALS("[test.c:1]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:1:34]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() { Fred *p = new Fred; }", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); @@ -2879,7 +2879,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " throw 123;\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " char *p;\n" @@ -2919,8 +2919,8 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " x(p);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function x() should have configuration\n" - "[test.c:4]: (information) --check-library: Function x() should have / configuration\n", + ASSERT_EQUALS("[test.c:3:9]: (information) --check-library: Function x() should have configuration [checkLibraryNoReturn]\n" + "[test.c:4:1]: (information) --check-library: Function x() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("void cb();\n" // #11190, #11523 @@ -2937,8 +2937,8 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " x(&p);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function x() should have configuration\n" - "[test.c:4]: (information) --check-library: Function x() should have / configuration\n", + ASSERT_EQUALS("[test.c:3:10]: (information) --check-library: Function x() should have configuration [checkLibraryNoReturn]\n" + "[test.c:4:1]: (information) --check-library: Function x() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } @@ -2949,9 +2949,9 @@ class TestLeakAutoVar : public TestFixture { " if (set_data(p)) { }\n" "}"; check(code); - ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.c:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check(code, dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function set_data() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } { @@ -2960,12 +2960,12 @@ class TestLeakAutoVar : public TestFixture { " if (set_data(p)) { return; }\n" "}"; check(code); - ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function set_data() should have / configuration\n" - "[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n" + ASSERT_EQUALS("[test.c:3:24]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n" + "[test.c:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n" , errout_str()); check(code, dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3]: (information) --check-library: Function set_data() should have / configuration\n" - "[test.cpp:4]: (information) --check-library: Function set_data() should have / configuration\n" + ASSERT_EQUALS("[test.cpp:3:24]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n" + "[test.cpp:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n" , errout_str()); } } @@ -2976,7 +2976,7 @@ class TestLeakAutoVar : public TestFixture { " int ret = set_data(p);\n" " return ret;\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.c:4:5]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } void configuration5() { @@ -3031,7 +3031,7 @@ class TestLeakAutoVar : public TestFixture { " p = reinterpret_cast(buf);\n" " }\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:5]: (error) Resource leak: file\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5]: (error) Resource leak: file [resourceLeak]\n", errout_str()); } void configuration6() { @@ -3054,7 +3054,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char **p = malloc(10);\n" "}"); - ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.c:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void nestedAllocation() { @@ -3062,19 +3062,19 @@ class TestLeakAutoVar : public TestFixture { " unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\n" " m_dsmccQueue.enqueue(new DSMCCPacket(dataCopy));\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function DSMCCPacket() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function DSMCCPacket() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("void QueueDSMCCPacket(unsigned char *data, int length) {\n" " unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\n" " m_dsmccQueue.enqueue(new DSMCCPacket(somethingunrelated));\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: dataCopy\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: dataCopy [memleak]\n", errout_str()); check("void f() {\n" " char *buf = new char[1000];\n" " clist.push_back(new (std::nothrow) C(buf));\n" "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function C() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function C() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } void testKeywords() { @@ -3131,7 +3131,7 @@ class TestLeakAutoVar : public TestFixture { " char * buf = malloc(4);\n" " free_func((void *)(1), buf);\n" "}", settingsFunctionCall); - ASSERT_EQUALS("[test.cpp:5]: (information) --check-library: Function free_func() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:1]: (information) --check-library: Function free_func() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("void g(void*);\n" "void h(int, void*);\n" @@ -3143,8 +3143,8 @@ class TestLeakAutoVar : public TestFixture { " int* p = new int;\n" " h(1, static_cast(p));\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:6]: (information) --check-library: Function g() should have / configuration\n" - "[test.cpp:10]: (information) --check-library: Function h() should have / configuration\n", + ASSERT_EQUALS("[test.cpp:6:1]: (information) --check-library: Function g() should have / configuration [checkLibraryUseIgnore]\n" + "[test.cpp:10:1]: (information) --check-library: Function h() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } @@ -3162,7 +3162,7 @@ class TestLeakAutoVar : public TestFixture { " double* a = new double[1024];\n" " SomeClass::someMethod(a);\n" "}\n", settingsLeakIgnore); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: a [memleak]\n", errout_str()); check("void bar(int* p) {\n" " if (p)\n" @@ -3178,7 +3178,7 @@ class TestLeakAutoVar : public TestFixture { " char* p = new char[n];\n" " v.push_back(p);\n" "}\n", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function unknown::push_back() should have / configuration\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function unknown::push_back() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } }; @@ -3203,6 +3203,7 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture { } void run() override { + mNewTemplate = true; TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097 } @@ -3249,6 +3250,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { } void run() override { + mNewTemplate = true; TEST_CASE(returnedValue); // #9298 TEST_CASE(deallocuse2); TEST_CASE(fclose_false_positive); // #9575 @@ -3272,13 +3274,13 @@ class TestLeakAutoVarStrcpy : public TestFixture { " free(p);\n" " strcpy(a, p);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("void f(char *p, const char *q) {\n" // #11665 " free(p);\n" " strcpy(p, q);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Dereferencing 'p' after it is deallocated / released\n", + ASSERT_EQUALS("[test.cpp:3:12]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("void f(char *p) {\n" // #3041 - assigning pointer when it's used @@ -3298,7 +3300,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { " char* buf = new char[12];\n" " strcpy(buf, \"123\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: buf\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: buf [memleak]\n", errout_str()); } void doubleFree() { @@ -3320,7 +3322,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { " p = new S();\n" " p->f();\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("class B { std::string s; };\n" // #12062 "class D : public B {};\n" @@ -3328,7 +3330,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { " auto d = new D();\n" " if (d) {}\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: d\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:1]: (error) Memory leak: d [memleak]\n", errout_str()); } }; @@ -3353,54 +3355,55 @@ class TestLeakAutoVarWindows : public TestFixture { } void run() override { + mNewTemplate = true; TEST_CASE(heapDoubleFree); } void heapDoubleFree() { - check("void f() {" - " HANDLE MyHeap = HeapCreate(0, 0, 0);" - " int *a = HeapAlloc(MyHeap, 0, sizeof(int));" - " int *b = HeapAlloc(MyHeap, 0, sizeof(int));" - " HeapFree(MyHeap, 0, a);" - " HeapFree(MyHeap, 0, b);" - " HeapDestroy(MyHeap);" - "}"); + check("void f() {\n" + " HANDLE MyHeap = HeapCreate(0, 0, 0);\n" + " int *a = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " int *b = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " HeapFree(MyHeap, 0, a);\n" + " HeapFree(MyHeap, 0, b);\n" + " HeapDestroy(MyHeap);\n" + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f() {" - " int *a = HeapAlloc(GetProcessHeap(), 0, sizeof(int));" - " int *b = HeapAlloc(GetProcessHeap(), 0, sizeof(int));" - " HeapFree(GetProcessHeap(), 0, a);" - " HeapFree(GetProcessHeap(), 0, b);" - "}"); + check("void f() {\n" + " int *a = HeapAlloc(GetProcessHeap(), 0, sizeof(int))\n" + " int *b = HeapAlloc(GetProcessHeap(), 0, sizeof(int));\n" + " HeapFree(GetProcessHeap(), 0, a);\n" + " HeapFree(GetProcessHeap(), 0, b);\n" + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f() {" - " HANDLE MyHeap = HeapCreate(0, 0, 0);" - " int *a = HeapAlloc(MyHeap, 0, sizeof(int));" - " int *b = HeapAlloc(MyHeap, 0, sizeof(int));" - " HeapFree(MyHeap, 0, a);" - " HeapDestroy(MyHeap);" - "}"); - ASSERT_EQUALS("[test.c:1]: (error) Memory leak: b\n", errout_str()); + check("void f() {\n" + " HANDLE MyHeap = HeapCreate(0, 0, 0);\n" + " int *a = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " int *b = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " HeapFree(MyHeap, 0, a);\n" + " HeapDestroy(MyHeap);\n" + "}\n"); + ASSERT_EQUALS("[test.c:7:1]: (error) Memory leak: b [memleak]\n", errout_str()); - check("void f() {" - " HANDLE MyHeap = HeapCreate(0, 0, 0);" - " int *a = HeapAlloc(MyHeap, 0, sizeof(int));" - " int *b = HeapAlloc(MyHeap, 0, sizeof(int));" - " HeapFree(MyHeap, 0, a);" - " HeapFree(MyHeap, 0, b);" - "}"); - ASSERT_EQUALS("[test.c:1]: (error) Resource leak: MyHeap\n", errout_str()); + check("void f() {\n" + " HANDLE MyHeap = HeapCreate(0, 0, 0);\n" + " int *a = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " int *b = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " HeapFree(MyHeap, 0, a);\n" + " HeapFree(MyHeap, 0, b);\n" + "}\n"); + ASSERT_EQUALS("[test.c:7:1]: (error) Resource leak: MyHeap [resourceLeak]\n", errout_str()); - check("void f() {" - " HANDLE MyHeap = HeapCreate(0, 0, 0);" - " int *a = HeapAlloc(MyHeap, 0, sizeof(int));" - " int *b = HeapAlloc(MyHeap, 0, sizeof(int));" - " HeapFree(MyHeap, 0, a);" - "}"); - ASSERT_EQUALS("[test.c:1]: (error) Resource leak: MyHeap\n" - "[test.c:1]: (error) Memory leak: b\n", + check("void f() {\n" + " HANDLE MyHeap = HeapCreate(0, 0, 0);\n" + " int *a = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " int *b = HeapAlloc(MyHeap, 0, sizeof(int));\n" + " HeapFree(MyHeap, 0, a);\n" + "}\n"); + ASSERT_EQUALS("[test.c:6:1]: (error) Resource leak: MyHeap [resourceLeak]\n" + "[test.c:6:1]: (error) Memory leak: b [memleak]\n", errout_str()); } }; @@ -3425,6 +3428,7 @@ class TestLeakAutoVarPosix : public TestFixture { } void run() override { + mNewTemplate = true; TEST_CASE(memleak_getline); TEST_CASE(deallocuse_fdopen); TEST_CASE(doublefree_fdopen); // #12781 From de4761a6bedf83f9939080d32c4473ed0ea1db4c Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 16 May 2025 15:20:21 +0200 Subject: [PATCH 4/4] TestBufferOverrun: added error IDs and columns to expected output --- test/testbufferoverrun.cpp | 536 ++++++++++++++++++------------------- 1 file changed, 268 insertions(+), 268 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5bda0c72ef3..964ed84bdf0 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -85,7 +85,7 @@ class TestBufferOverrun : public TestFixture { } void run() override { - // TODO: mNewTemplate = true; + mNewTemplate = true; TEST_CASE(noerr1); TEST_CASE(noerr2); TEST_CASE(noerr3); @@ -389,14 +389,14 @@ class TestBufferOverrun : public TestFixture { " str[15] = 0;\n" " str[16] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("char f()\n" "{\n" " char str[16] = {0};\n" " return str[16];\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:15]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // test stack array check("int f()\n" @@ -406,7 +406,7 @@ class TestBufferOverrun : public TestFixture { " y = x[ 4 ];\n" " return y;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'x[3]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:9]: (error) Array 'x[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int f()\n" "{\n" @@ -419,11 +419,11 @@ class TestBufferOverrun : public TestFixture { check("int x[5] = {0};\n" "int a = x[10];"); - ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int x[5] = {0};\n" "int a = (x)[10];"); - ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:12]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -434,12 +434,12 @@ class TestBufferOverrun : public TestFixture { " str[i] = 0;\n" "}\n" "void b() { a(16); }"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_4() { check("char c = \"abc\"[4];"); - ASSERT_EQUALS("[test.cpp:1]: (error) Array '\"abc\"[4]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:15]: (error) Array '\"abc\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("p = &\"abc\"[4];"); ASSERT_EQUALS("", errout_str()); @@ -448,7 +448,7 @@ class TestBufferOverrun : public TestFixture { ASSERT_EQUALS("", errout_str()); check("char c = L\"abc\"[4];"); - ASSERT_EQUALS("[test.cpp:1]: (error) Array 'L\"abc\"[4]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:1:16]: (error) Array 'L\"abc\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_3() { @@ -459,7 +459,7 @@ class TestBufferOverrun : public TestFixture { " for (i = 0; i < 100; i++)\n" " sum += val[i];\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -468,7 +468,7 @@ class TestBufferOverrun : public TestFixture { " for (i = 1; i < 100; i++)\n" " sum += val[i];\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(int a)\n" "{\n" @@ -477,7 +477,7 @@ class TestBufferOverrun : public TestFixture { " for (i = a; i < 100; i++)\n" " sum += val[i];\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("typedef struct g g2[3];\n" "void foo(char *a)\n" @@ -501,7 +501,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index 49, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Array 'a[10]' accessed at index 49, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_6() { @@ -515,7 +515,7 @@ class TestBufferOverrun : public TestFixture { " struct ABC abc;\n" " abc.str[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:12]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct ABC\n" "{\n" @@ -527,7 +527,7 @@ class TestBufferOverrun : public TestFixture { " struct ABC abc;\n" " return abc.str[10];\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:19]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // This is not out of bounds because it is a variable length array check("struct ABC\n" @@ -637,7 +637,7 @@ class TestBufferOverrun : public TestFixture { " struct ABC x;\n" " x.str[1] = 0;" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct foo\n" "{\n" @@ -650,7 +650,7 @@ class TestBufferOverrun : public TestFixture { " for ( unsigned int i = 0; i < 64; ++i )\n" " f.str[i] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:14]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct AB { char a[NUM]; char b[NUM]; }\n" "void f(struct AB *ab) {\n" @@ -662,7 +662,7 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " ab.a[2] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -676,7 +676,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " abc->str[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_11() { @@ -695,7 +695,7 @@ class TestBufferOverrun : public TestFixture { " abc->str[10] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:13:17]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_12() { @@ -710,7 +710,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " str[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:8]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("class Fred\n" "{\n" @@ -723,7 +723,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " return str[10];\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:15]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_13() { @@ -746,7 +746,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 10; i++)\n" " a[i+10] = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_15() { @@ -756,7 +756,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 10; i++)\n" " a[10+i] = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_16() { @@ -766,7 +766,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 10; i++)\n" " a[i+1] = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_17() { @@ -776,7 +776,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 10; i++)\n" " a[i*2] = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 18, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 18, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -792,14 +792,14 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 12; i+=6)\n" " a[i+6] = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[12]' accessed at index 12, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[12]' accessed at index 12, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #4398 " int a[2];\n" " for (int i = 0; i < 4; i+=2)\n" " a[i] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #4398 " int a[2];\n" @@ -852,7 +852,7 @@ class TestBufferOverrun : public TestFixture { " i=4;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -881,7 +881,7 @@ class TestBufferOverrun : public TestFixture { " char a[2];\n" " char *end = &(a[3]);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 3, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (error) Array 'a[2]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_20() { @@ -914,7 +914,7 @@ class TestBufferOverrun : public TestFixture { " size_t indices[2];\n" " int b = indices[2];\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_23() { @@ -923,7 +923,7 @@ class TestBufferOverrun : public TestFixture { " char c[10];\n" " c[1<<23]='a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_24() { @@ -934,66 +934,66 @@ class TestBufferOverrun : public TestFixture { " a[-1] = 0;\n" // negative index " a[" + charMaxPlusOne + "] = 0;\n" // 128/256 > CHAR_MAX "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index -1, which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index " + charMaxPlusOne + ", which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index -1, which is out of bounds. [negativeIndex]\n" + "[test.cpp:4:6]: (error) Array 'a[" + charMaxPlusOne + "]' accessed at index " + charMaxPlusOne + ", which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(signed char n) {\n" " int a[n];\n" // n <= SCHAR_MAX " a[-1] = 0;\n" // negative index " a[128] = 0;\n" // 128 > SCHAR_MAX "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[128]' accessed at index -1, which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'a[128]' accessed at index 128, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[128]' accessed at index -1, which is out of bounds. [negativeIndex]\n" + "[test.cpp:4:6]: (error) Array 'a[128]' accessed at index 128, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(unsigned char n) {\n" " int a[n];\n" // n <= UCHAR_MAX " a[-1] = 0;\n" // negative index " a[256] = 0;\n" // 256 > UCHAR_MAX "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[256]' accessed at index -1, which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'a[256]' accessed at index 256, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[256]' accessed at index -1, which is out of bounds. [negativeIndex]\n" + "[test.cpp:4:6]: (error) Array 'a[256]' accessed at index 256, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(short n) {\n" " int a[n];\n" // n <= SHRT_MAX " a[-1] = 0;\n" // negative index " a[32768] = 0;\n" // 32768 > SHRT_MAX "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\n" + "[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(unsigned short n) {\n" " int a[n];\n" // n <= USHRT_MAX " a[-1] = 0;\n" // negative index " a[65536] = 0;\n" // 65536 > USHRT_MAX "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds. [negativeIndex]\n" + "[test.cpp:4:6]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(signed short n) {\n" " int a[n];\n" // n <= SHRT_MAX " a[-1] = 0;\n" // negative index " a[32768] = 0;\n" // 32768 > SHRT_MAX "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\n" + "[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(int n) {\n" " int a[n];\n" // n <= INT_MAX " a[-1] = 0;\n" // negative index "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f(unsigned int n) {\n" " int a[n];\n" // n <= UINT_MAX " a[-1] = 0;\n" // negative index "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f(signed int n) {\n" " int a[n];\n" // n <= INT_MAX " a[-1] = 0;\n" // negative index "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } void array_index_25() { // #1536 @@ -1011,7 +1011,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 3; 0 <= i; i--)\n" " a[i] = i;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[3]' accessed at index 3, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -1029,7 +1029,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 10; i++)\n" " a[i-1] = a[i];\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } void array_index_28() { @@ -1062,7 +1062,7 @@ class TestBufferOverrun : public TestFixture { " UINT8 x[2];\n" " x[5] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[2]' accessed at index 5, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'x[2]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_31() { @@ -1118,7 +1118,7 @@ class TestBufferOverrun : public TestFixture { " }\n" " int m_x[1];\n" "};"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:11]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_33() { @@ -1134,8 +1134,8 @@ class TestBufferOverrun : public TestFixture { " y[0][2][0] = 0;\n" " y[0][0][2] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds.\n" - "[test.cpp:4]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:4:6]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct TEST\n" "{\n" @@ -1154,12 +1154,12 @@ class TestBufferOverrun : public TestFixture { " ptest->b[10][2] = 4;\n" " ptest->b[0][19] = 4;\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds.\n" - "[test.cpp:10]: (error) Array 'test.b[10][5]' accessed at index test.b[10][2], which is out of bounds.\n" - "[test.cpp:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds.\n" - "[test.cpp:14]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds.\n" - "[test.cpp:15]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[10][2], which is out of bounds.\n" - "[test.cpp:16]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:11]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:10:11]: (error) Array 'test.b[10][5]' accessed at index test.b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:11:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:14:13]: (error) Array 'ptest->a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:15:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:16:13]: (error) Array 'ptest->b[10][5]' accessed at index ptest->b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct TEST\n" "{\n" @@ -1175,10 +1175,10 @@ class TestBufferOverrun : public TestFixture { " ptest->a[9][5] = 4;\n" " ptest->a[0][50] = 4;\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds.\n" - "[test.cpp:9]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds.\n" - "[test.cpp:12]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds.\n" - "[test.cpp:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:11]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:9:11]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:12:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:13:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_35() { // ticket #2889 @@ -1186,14 +1186,14 @@ class TestBufferOverrun : public TestFixture { " struct Struct { unsigned m_Var[1]; } s;\n" " s.m_Var[1] = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Struct { unsigned m_Var[1]; };\n" "void f() {\n" " struct Struct s;\n" " s.m_Var[1] = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Struct { unsigned m_Var[1]; };\n" "void f() {\n" @@ -1212,8 +1212,8 @@ class TestBufferOverrun : public TestFixture { "Fred::Fred(const Fred & rhs) {\n" " m_b[2] = rhs.m_b[2];\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds.\n" - "[test.cpp:7]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:8]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:7:21]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_37() { @@ -1252,7 +1252,7 @@ class TestBufferOverrun : public TestFixture { " char a[10];\n" " a[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_40() { @@ -1285,7 +1285,7 @@ class TestBufferOverrun : public TestFixture { " struct Fred { char data[3]; } fred;\n" " fred.data[4] = 0;\n" // <- error "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:14]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_42() { // ticket #3569 @@ -1296,7 +1296,7 @@ class TestBufferOverrun : public TestFixture { " p[10] = 7;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -1304,7 +1304,7 @@ class TestBufferOverrun : public TestFixture { " p[10] = 7;\n" " free(p);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -1363,7 +1363,7 @@ class TestBufferOverrun : public TestFixture { " y = var[ 0 ].arr[ 3 ];\n" // <-- array access out of bounds " return y;\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:20]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int f( )\n" "{\n" @@ -1393,8 +1393,8 @@ class TestBufferOverrun : public TestFixture { "y=var.arr[ 3 ];\n" // <-- array access out of bounds "return y;\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n" - "[test.cpp:11]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:8]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:11:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f( ) {\n" @@ -1407,7 +1407,7 @@ class TestBufferOverrun : public TestFixture { "var[0].var[ 2 ] = 2;\n" "var[0].var[ 4 ] = 4;\n" // <-- array access out of bounds "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:11]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f( ) {\n" "struct S{\n" @@ -1443,7 +1443,7 @@ class TestBufferOverrun : public TestFixture { " int * p = &ab[10].a[0];\n" " return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:18]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_44() { // #3979 (false positive) @@ -1511,7 +1511,7 @@ class TestBufferOverrun : public TestFixture { " buffer[i] = i;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // Correct access limits -> i from 9 to 0 check("void f() {\n" @@ -1543,7 +1543,7 @@ class TestBufferOverrun : public TestFixture { " array[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'array[4]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:14]: (error) Array 'array[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void test(void)\n" "{\n" @@ -1587,7 +1587,7 @@ class TestBufferOverrun : public TestFixture { " int k=0, dd, d[1U] = {1};\n" " for (dd=d[k]; k<10; dd=d[++k]){;}\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'd[1]' accessed at index 1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:29]: (error) Array 'd[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_52() { @@ -1598,7 +1598,7 @@ class TestBufferOverrun : public TestFixture { " buf[i] = 0;\n" " return buf[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_53() { @@ -1610,7 +1610,7 @@ class TestBufferOverrun : public TestFixture { " for (int j = 0; j < 3; j++)\n" " M[i][j]=0.0;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:15]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_54() { @@ -1680,7 +1680,7 @@ class TestBufferOverrun : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:6] -> [test.cpp:5]: (warning) Either the condition 'i==4' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds.\n", + "[test.cpp:6:15] -> [test.cpp:5:18]: (warning) Either the condition 'i==4' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); } @@ -1695,7 +1695,7 @@ class TestBufferOverrun : public TestFixture { " return y;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:6]: (warning) Either the condition 'x<2' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds.\n", + "[test.cpp:3:9] -> [test.cpp:6:14]: (warning) Either the condition 'x<2' is redundant or the array 'a[3]' is accessed at index 3, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); check("void f() {\n" // #2199 @@ -1712,8 +1712,8 @@ class TestBufferOverrun : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:5]: (error) Array 'a[5]' accessed at index 8, which is out of bounds.\n" - "[test.cpp:11]: (error) Array 'a[5]' accessed at index 11, which is out of bounds.\n", + "[test.cpp:5:10]: (error) Array 'a[5]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:11:10]: (error) Array 'a[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1764,7 +1764,7 @@ class TestBufferOverrun : public TestFixture { " array[index]++;\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:5]: (warning) Either the condition 'index>5' is redundant or the array 'array[5]' is accessed at index 5, which is out of bounds.\n", + "[test.cpp:4:5] -> [test.cpp:5:10]: (warning) Either the condition 'index>5' is redundant or the array 'array[5]' is accessed at index 5, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); } @@ -1803,7 +1803,7 @@ class TestBufferOverrun : public TestFixture { " buf[i] = 0;\n" " return buf[0];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:7:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1829,7 +1829,7 @@ class TestBufferOverrun : public TestFixture { " Array array = {};\n" " array.accessArrayRef(10);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int i = 10;\n" "struct Array {\n" @@ -1840,7 +1840,7 @@ class TestBufferOverrun : public TestFixture { " Array array = {};\n" " array.accessArrayRef(i);\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3:42]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", "", errout_str()); } void array_index_65() // #11066 @@ -1865,7 +1865,7 @@ class TestBufferOverrun : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:5]: (warning) Either the condition 'j>=256' is redundant or the array 'offsets[256]' is accessed at index 256, which is out of bounds.\n", + "[test.cpp:4:15] -> [test.cpp:5:16]: (warning) Either the condition 'j>=256' is redundant or the array 'offsets[256]' is accessed at index 256, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); } @@ -1898,7 +1898,7 @@ class TestBufferOverrun : public TestFixture { " f(20);\n" " return 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Array 'ia[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // #6370 @@ -1910,7 +1910,7 @@ class TestBufferOverrun : public TestFixture { " for(int i = 0; i < 4; ++i)\n" " a[e[i]] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[4]' accessed at index 30, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (error) Array 'a[4]' accessed at index 30, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // #11355 @@ -1919,7 +1919,7 @@ class TestBufferOverrun : public TestFixture { " static const char a[] = ((\"test\"));\n" " printf(\"%c\", a[5]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[5]' accessed at index 5, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // #11461 @@ -1985,7 +1985,7 @@ class TestBufferOverrun : public TestFixture { " while (i >= 3)\n" " buf[i--] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // #12592 @@ -2003,8 +2003,8 @@ class TestBufferOverrun : public TestFixture { " cb0(nullptr, 1);\n" " cb1(1, nullptr);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 's[1]' accessed at index 1, which is out of bounds.\n" - "[test.cpp:7]: (error) Array 's[1]' accessed at index 1, which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:3:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:7:12]: (error) Array 's[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2028,67 +2028,67 @@ class TestBufferOverrun : public TestFixture { " char a[2][2];\n" " a[2][1] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2];\n" " a[1][2] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[2][1][1] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[1][2][1] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2][2];\n" " a[1][2][1][1] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[1][1][2] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[10][10][10];\n" " a[2*3][4*3][2] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char a[10][10][10];\n" " a[6][40][10] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char a[1][1][1];\n" " a[2][2][2] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char a[6][6][6];\n" " a[6][6][2] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int a[2][2];\n" @@ -2204,8 +2204,8 @@ class TestBufferOverrun : public TestFixture { " if (i >= 0 && i < 10) {}\n" " a[i] = 1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds.\n" - "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:4:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\n" + "[test.cpp:3:9] -> [test.cpp:4:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2218,7 +2218,7 @@ class TestBufferOverrun : public TestFixture { " data[i/2] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' accessed at index 17, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 17, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // #2199 - false negative: array out of bounds in loop when there is calculation check("void f()\n" @@ -2228,7 +2228,7 @@ class TestBufferOverrun : public TestFixture { " arr[i + 7] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_negative1() { @@ -2238,14 +2238,14 @@ class TestBufferOverrun : public TestFixture { " char data[8];\n" " data[-1] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'data[8]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f()\n" "{\n" " char data[8][4];\n" " data[5][-1] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds. [negativeIndex]\n", errout_str()); // #1614 - negative index is ok for pointers check("void foo(char *p)\n" @@ -2276,7 +2276,7 @@ class TestBufferOverrun : public TestFixture { " TEST test;\n" " test.a[-1] = 3;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } void array_index_negative3() { @@ -2346,7 +2346,7 @@ class TestBufferOverrun : public TestFixture { " for (; i < 5; i++)\n" " a[i] = 1;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[5]' accessed at index -9, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[5]' accessed at index -9, which is out of bounds. [negativeIndex]\n", errout_str()); } // #11651 @@ -2374,7 +2374,7 @@ class TestBufferOverrun : public TestFixture { " int a[] = { 1, 2, 3 };\n" " printf(\"%d\\n\", a[g(4)]);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Array 'a[3]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:21]: (error) Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } // #11844 @@ -2399,7 +2399,7 @@ class TestBufferOverrun : public TestFixture { " data[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[8]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -2417,8 +2417,8 @@ class TestBufferOverrun : public TestFixture { " val[i+1] = val[i];\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds.\n" - "[test.cpp:5]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds. [negativeIndex]\n" + "[test.cpp:5:23]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2450,8 +2450,8 @@ class TestBufferOverrun : public TestFixture { " a.data[4] = 0;\n" " a.b.data[3] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:10]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds.\n" - "[test.cpp:11]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:10:11]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n" + "[test.cpp:11:13]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_for_andand_oror() { // #3907 - using && or || @@ -2464,7 +2464,7 @@ class TestBufferOverrun : public TestFixture { " data[x] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char data[2];\n" @@ -2473,7 +2473,7 @@ class TestBufferOverrun : public TestFixture { " data[x] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char data[2];\n" @@ -2482,7 +2482,7 @@ class TestBufferOverrun : public TestFixture { " data[x] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char data[2];\n" @@ -2491,7 +2491,7 @@ class TestBufferOverrun : public TestFixture { " data[x] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int f() {\n" // #9126 " int i, c;\n" @@ -2529,7 +2529,7 @@ class TestBufferOverrun : public TestFixture { " a[i - 1] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[2]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (error) Array 'a[2]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } void array_index_for() { @@ -2542,7 +2542,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // Ticket #2385 - No false positive check("void f() {\n" @@ -2564,7 +2564,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // #7686 check("char f() {\n" @@ -2574,7 +2574,7 @@ class TestBufferOverrun : public TestFixture { " buf[i] = 0;\n" " return buf[0];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " const int a[10] = {};\n" @@ -2587,7 +2587,7 @@ class TestBufferOverrun : public TestFixture { " }\n" " }\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 9998, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Array 'a[10]' accessed at index 9998, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_for_neq() { @@ -2598,7 +2598,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[5]' accessed at index 9, which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'a[5]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2618,7 +2618,7 @@ class TestBufferOverrun : public TestFixture { " some_condition ? 0 : a[i-1];\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:4:31]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f() {\n" @@ -2628,7 +2628,7 @@ class TestBufferOverrun : public TestFixture { " a[i-1] = 0;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } void array_index_for_varid0() { // #4228: No varid for counter variable @@ -2688,14 +2688,14 @@ class TestBufferOverrun : public TestFixture { " const char *str = \"abc\";\n" " bar(str[10]);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'str[4]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " const char *str = \"abc\";\n" " bar(str[4]);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" @@ -2709,7 +2709,7 @@ class TestBufferOverrun : public TestFixture { " const char *str = \"a\tc\";\n" " bar(str[4]);\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #6973 " const char *name = \"\";\n" @@ -2755,7 +2755,7 @@ class TestBufferOverrun : public TestFixture { " struct tt *tt=x;\n" " tt->name[22] = 123;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:13]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_valueflow() { @@ -2764,7 +2764,7 @@ class TestBufferOverrun : public TestFixture { " str[i] = 0;\n" " if (i==10) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:3:8]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); check("void f(int i) {\n" " char str[3];\n" @@ -2773,7 +2773,7 @@ class TestBufferOverrun : public TestFixture { " case 10: break;\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:3:8]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); check("void f() {\n" " char str[3];\n" @@ -2806,7 +2806,7 @@ class TestBufferOverrun : public TestFixture { "int g() {\n" " return f(16);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds.\n", + ASSERT_EQUALS("[test.cpp:3:15] -> [test.cpp:3:41]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); check("void f(int fd) {\n" // #12318 @@ -2838,7 +2838,7 @@ class TestBufferOverrun : public TestFixture { " int *p = a;\n" " p[10] = 0;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", "", errout_str()); check("void f() {\n" " int a[10];\n" @@ -2867,7 +2867,7 @@ class TestBufferOverrun : public TestFixture { check("void f(char a[10]) {\n" " a[20] = 0;\n" // <- cppcheck warn here even though it's not a definite access out of bounds "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(char a[10]) {\n" // #6353 - reassign 'a' " a += 4;\n" @@ -2879,7 +2879,7 @@ class TestBufferOverrun : public TestFixture { " a[0] = 0;\n" " a[-1] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } void array_index_enum_array() { // #8439 @@ -2888,7 +2888,7 @@ class TestBufferOverrun : public TestFixture { " E arrE[] = { e1, e2 };\n" " arrE[sizeof(arrE)] = e1;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_container() { // #9386 @@ -2946,7 +2946,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int* z = new int(1);\n" @@ -2954,7 +2954,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int* z = new int{};\n" @@ -2962,7 +2962,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[1]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[1]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int* z = new int[5];\n" @@ -2970,7 +2970,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 0;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void g() {\n" " int* z = new int[5]();\n" @@ -2978,7 +2978,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = 1;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5];\n" @@ -2986,7 +2986,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5]();\n" @@ -2994,7 +2994,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5]{};\n" @@ -3002,7 +3002,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void h() {\n" " int** z = new int* [5]{ 0 };\n" @@ -3010,7 +3010,7 @@ class TestBufferOverrun : public TestFixture { " z[n] = nullptr;\n" " delete[] z;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'z[5]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'z[5]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_2_struct() { @@ -3023,7 +3023,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " strcpy( abc->str, \"abcdef\" );\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc->str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\n", errout_str()); check("struct ABC\n" "{\n" @@ -3035,7 +3035,7 @@ class TestBufferOverrun : public TestFixture { " struct ABC abc;\n" " strcpy( abc.str, \"abcdef\" );\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Buffer is accessed out of bounds: abc.str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\n", errout_str()); check("struct ABC\n" "{\n" @@ -3046,7 +3046,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " strcpy( abc.str, \"abcdef\" );\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc.str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\n", errout_str()); check("static void f()\n" "{\n" @@ -3056,7 +3056,7 @@ class TestBufferOverrun : public TestFixture { " } abc;\n" " strcpy( abc.str, \"abcdef\" );\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: abc.str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\n", errout_str()); check("static void f()\n" "{\n" @@ -3068,7 +3068,7 @@ class TestBufferOverrun : public TestFixture { " strcpy( abc->str, \"abcdef\" );\n" " free(abc);\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Buffer is accessed out of bounds: abc->str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\n", errout_str()); } @@ -3081,11 +3081,11 @@ class TestBufferOverrun : public TestFixture { " for (i = 0; i <= 10; ++i)\n" " a[i] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct S { int b; } static e[1];\n" // #11052 "int f() { return e[1].b; }\n"); - ASSERT_EQUALS("[test.cpp:2]: (error) Array 'e[1]' accessed at index 1, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:19]: (error) Array 'e[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -3096,7 +3096,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 8; ++i)\n" " p[i] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'p[2]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'p[2]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // No false positive check("void foo(int x, int y)\n" @@ -3155,14 +3155,14 @@ class TestBufferOverrun : public TestFixture { " char d[3] = {};\n" " strcat(d, \"12345678\");\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: d\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char d[3] = \"ab\"; \n" " strcat(d, \"c\");\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: d\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\n", "", errout_str()); } void buffer_overrun_7() { @@ -3254,7 +3254,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " strcpy(val, \"ab\") ;\n" "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: val\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:12]: (error) Buffer is accessed out of bounds: val [bufferAccessOutOfBounds]\n", errout_str()); } void buffer_overrun_16() { @@ -3302,7 +3302,7 @@ class TestBufferOverrun : public TestFixture { " b[i] = b[i+1];\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:8]: (error) Array 'b[7]' accessed at index 7, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:8:17]: (error) Array 'b[7]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_19() { // #2597 - class member with unknown type @@ -3326,7 +3326,7 @@ class TestBufferOverrun : public TestFixture { " for (size_t i = 0; i <= 4; i++)\n" " dst[i] = src[i];\n" "} } }"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:12]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_24() { // index variable is changed in for-loop @@ -3389,7 +3389,7 @@ class TestBufferOverrun : public TestFixture { "int f(S * s) {\n" " return s->m[sizeof(s->m)];\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_31() { @@ -3407,7 +3407,7 @@ class TestBufferOverrun : public TestFixture { " (void)strxfrm(dest,src,1);\n" " (void)strxfrm(dest,src,2);\n"// << "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: dest\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\n", errout_str()); // destination size is too small check("void f(void) {\n" " const char src[3] = \"abc\";\n" @@ -3416,7 +3416,7 @@ class TestBufferOverrun : public TestFixture { " (void)strxfrm(dest,src,2);\n" " (void)strxfrm(dest,src,3);\n" // << "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: dest\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\n", errout_str()); // source size is too small check("void f(void) {\n" " const char src[2] = \"ab\";\n" @@ -3425,7 +3425,7 @@ class TestBufferOverrun : public TestFixture { " (void)strxfrm(dest,src,2);\n" " (void)strxfrm(dest,src,3);\n" // << "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: src\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\n", errout_str()); // source size is too small check("void f(void) {\n" " const char src[1] = \"a\";\n" @@ -3433,7 +3433,7 @@ class TestBufferOverrun : public TestFixture { " (void)strxfrm(dest,src,1);\n" " (void)strxfrm(dest,src,2);\n" // << "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: src\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\n", errout_str()); } void buffer_overrun_33() { // #2019 @@ -3444,7 +3444,7 @@ class TestBufferOverrun : public TestFixture { " z[i] = 0;\n" " return z[0];\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'z[16]' accessed at index 19, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'z[16]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_34() { // #11035 @@ -3468,7 +3468,7 @@ class TestBufferOverrun : public TestFixture { " strcpy(p, q);\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char* q = \"0123456789\";\n" @@ -3476,7 +3476,7 @@ class TestBufferOverrun : public TestFixture { " strcpy(p, q);\n" " free(p);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: p\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\n", errout_str()); check("typedef struct { char buf[1]; } S;\n" "S* f() {\n" @@ -3708,7 +3708,7 @@ class TestBufferOverrun : public TestFixture { " u8 str[2];\n" " mystrcpy(str, \"abcd\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); // The same for structs, where the message comes from a different check check("void f() {\n" @@ -3721,7 +3721,7 @@ class TestBufferOverrun : public TestFixture { " struct { u8 str[2]; } ms;\n" " mystrcpy(ms.str, \"abcd\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: ms.str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:16]: (error) Buffer is accessed out of bounds: ms.str [bufferAccessOutOfBounds]\n", errout_str()); } void valueflow_string() { // using ValueFlow string values in checking @@ -3730,7 +3730,7 @@ class TestBufferOverrun : public TestFixture { " if (cond) x = \"abcde\";\n" " return x[20];\n" // <- array index out of bounds when x is "abcde" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[6]' accessed at index 20, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void pointer_out_of_bounds_1() { @@ -3740,27 +3740,27 @@ class TestBufferOverrun : public TestFixture { " char a[10];\n" " char *p = a + 100;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("char *f() {\n" " char a[10];\n" " return a + 100;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == 123) {}\n" " dostuff(x+i);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == -1) {}\n" " dostuff(x+i);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\n", errout_str()); check("void f() {\n" // #6350 - fp when there is cast of buffer " wchar_t buf[64];\n" @@ -3816,7 +3816,7 @@ class TestBufferOverrun : public TestFixture { "void f(struct S *s) {\n" " int *p = s->a + 100;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("template class Vector\n" "{\n" @@ -3844,7 +3844,7 @@ class TestBufferOverrun : public TestFixture { check("const char* f() {\n" " g(\"Hello\" + 7);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic '\"Hello\"+7' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:15]: (portability) Undefined behaviour, pointer arithmetic '\"Hello\"+7' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("const char16_t* f() {\n" " g(u\"Hello\" + 6);\n" @@ -3854,14 +3854,14 @@ class TestBufferOverrun : public TestFixture { check("const char16_t* f() {\n" " g(u\"Hello\" + 7);\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (portability) Undefined behaviour, pointer arithmetic 'u\"Hello\"+7' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:16]: (portability) Undefined behaviour, pointer arithmetic 'u\"Hello\"+7' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f() {\n" // #4647 " int val = 5;\n" " std::string hi = \"hi\" + val;\n" " std::cout << hi << std::endl;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic '\"hi\"+val' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:27]: (portability) Undefined behaviour, pointer arithmetic '\"hi\"+val' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f(const char* s, int len) {\n" // #11026 " const char* end = s + len;\n" @@ -3901,14 +3901,14 @@ class TestBufferOverrun : public TestFixture { " char x[10];\n" " return x-1;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == 123) {}\n" " dostuff(x-i);\n" "}"); - ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds. [pointerOutOfBoundsCond]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" @@ -3961,7 +3961,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " str[3] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[3]' accessed at index 3, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:8]: (error) Array 'str[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void alloc_new() { @@ -3970,7 +3970,7 @@ class TestBufferOverrun : public TestFixture { " char *s; s = new char[10];\n" " s[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1670 - false negative when using return check("char f()\n" @@ -3978,7 +3978,7 @@ class TestBufferOverrun : public TestFixture { " int *s; s = new int[10];\n" " return s[10];\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Fred { char c[10]; };\n" "char f()\n" @@ -3986,7 +3986,7 @@ class TestBufferOverrun : public TestFixture { " Fred *f; f = new Fred;\n" " return f->c[10];\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:16]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\n" "struct Thing { char data[MAX_SIZE]; };\n" @@ -4011,7 +4011,7 @@ class TestBufferOverrun : public TestFixture { " buf[9] = 0;\n" " delete [] buf;\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" @@ -4019,7 +4019,7 @@ class TestBufferOverrun : public TestFixture { " char *s; s = new char[Size];\n" " s[Size] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" @@ -4027,7 +4027,7 @@ class TestBufferOverrun : public TestFixture { " E *e; e = new E[10];\n" " e[10] = ZERO;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'e[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // data is allocated with malloc @@ -4037,14 +4037,14 @@ class TestBufferOverrun : public TestFixture { " char *s; s = (char *)malloc(10);\n" " s[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #842 check("void f() {\n" " int *tab4 = (int *)malloc(20 * sizeof(int));\n" " tab4[20] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1478 check("void foo() {\n" @@ -4053,7 +4053,7 @@ class TestBufferOverrun : public TestFixture { " p = (char *)malloc(10);\n" " p[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1134 check("void f() {\n" @@ -4061,7 +4061,7 @@ class TestBufferOverrun : public TestFixture { " x = (int *)malloc(10 * sizeof(int));\n" " x[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int *tab4; tab4 = malloc(20 * sizeof(int));\n" @@ -4087,21 +4087,21 @@ class TestBufferOverrun : public TestFixture { " E *tab4 = (E *)malloc(Size * 4);\n" " tab4[Size] = Size;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " enum E { Size = 20 };\n" " E *tab4 = (E *)malloc(4 * Size);\n" " tab4[Size] = Size;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " enum E { ZERO };\n" " E *tab4 = (E *)malloc(20 * sizeof(E));\n" " tab4[20] = ZERO;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #8721 " unsigned char **cache = malloc(32);\n" @@ -4115,14 +4115,14 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 3; i++)\n" " a[i] = NULL;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int **a = new int*[2];\n" " for (int i = 0; i < 3; i++)\n" " a[i] = NULL;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } // statically allocated buffer @@ -4132,14 +4132,14 @@ class TestBufferOverrun : public TestFixture { " const char *s = \"123\";\n" " s[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[4]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" " char *s; s = \"\";\n" " s[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[1]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo() {\n" " const char *s = \"\";\n" @@ -4164,7 +4164,7 @@ class TestBufferOverrun : public TestFixture { " char *s = (char *)alloca(10);\n" " s[10] = 0;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", "", errout_str()); } /* void countSprintfLength() const { @@ -4266,7 +4266,7 @@ class TestBufferOverrun : public TestFixture { " char c[10];\n" " mymemset(c, 0, 11);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); check("struct S {\n" " char a[5];\n" @@ -4275,28 +4275,28 @@ class TestBufferOverrun : public TestFixture { " S s;\n" " mymemset(s.a, 0, 10);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer is accessed out of bounds: s.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:15]: (error) Buffer is accessed out of bounds: s.a [bufferAccessOutOfBounds]\n", errout_str()); check("void foo() {\n" " char s[10];\n" " mymemset(s, 0, '*');\n" "}", dinit(CheckOptions, $.s = &settings)); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) The size argument is given as a char constant.\n" - "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", "[test.cpp:3]: (error) Buffer is accessed out of bounds: s\n", errout_str()); + "[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\n", "[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\n", errout_str()); // ticket #836 check("void f(void) {\n" " char a[10];\n" " mymemset(a+5, 0, 10);\n" "}", dinit(CheckOptions, $.s = &settings)); - TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n", "", errout_str()); // Ticket #909 check("void f(void) {\n" " char str[] = \"abcd\";\n" " mymemset(str, 0, 6);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f(void) {\n" " char str[] = \"abcd\";\n" @@ -4308,7 +4308,7 @@ class TestBufferOverrun : public TestFixture { " wchar_t str[] = L\"abcd\";\n" " mymemset(str, 0, 21);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f(void) {\n" " wchar_t str[] = L\"abcd\";\n" @@ -4321,7 +4321,7 @@ class TestBufferOverrun : public TestFixture { " char c;\n" " mymemset(&c, 0, 4);\n" "}", dinit(CheckOptions, $.s = &settings)); - TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", "", errout_str()); // ticket #2121 - buffer access out of bounds when using uint32_t check("void f(void) {\n" @@ -4341,13 +4341,13 @@ class TestBufferOverrun : public TestFixture { " char b[5][6];\n" " mymemset(b, 0, 6 * 6);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\n", errout_str()); check("int main() {\n" " char b[5][6];\n" " mymemset(b, 0, 31);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: b\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\n", errout_str()); // #4968 - not standard function check("void f() {\n" @@ -4356,7 +4356,7 @@ class TestBufferOverrun : public TestFixture { " foo::mymemset(str, 0, 100);\n" " std::mymemset(str, 0, 100);\n" "}", dinit(CheckOptions, $.s = &settings)); - TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", "", errout_str()); // #5257 - check strings check("void f() {\n" @@ -4409,13 +4409,13 @@ class TestBufferOverrun : public TestFixture { " char c[5];\n" " mystrncpy(c,\"hello\",6);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char c[6];\n" " mystrncpy(c,\"hello!\",7);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); check("void f(unsigned int addr) {\n" " memset((void *)addr, 0, 1000);\n" @@ -4459,13 +4459,13 @@ class TestBufferOverrun : public TestFixture { " char str[3];\n" " mysprintf(str, \"test\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char str[5];\n" " mysprintf(str, \"%s\", \"abcde\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("int getnumber();\n" "void f()\n" @@ -4473,7 +4473,7 @@ class TestBufferOverrun : public TestFixture { " char str[5];\n" " mysprintf(str, \"%d: %s\", getnumber(), \"abcde\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char str[5];\n" @@ -4485,7 +4485,7 @@ class TestBufferOverrun : public TestFixture { " char *str = new char[5];\n" " mysprintf(str, \"abcde\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f(int condition) {\n" " char str[5];\n" @@ -4504,20 +4504,20 @@ class TestBufferOverrun : public TestFixture { " struct Foo x;\n" " mysprintf(x.a, \"aa\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\n", errout_str()); // ticket #900 check("void f() {\n" " char *a = new char(30);\n" " mysprintf(a, \"a\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n", errout_str()); check("void f(char value) {\n" " char *a = new char(value);\n" " mysprintf(a, \"a\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n", errout_str()); // This is out of bounds if 'sizeof(ABC)' is 1 (No padding) check("struct Foo { char a[1]; };\n" @@ -4539,7 +4539,7 @@ class TestBufferOverrun : public TestFixture { " struct Foo x;\n" " mysprintf(x.a, \"aa\");\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\n", errout_str()); check("struct Foo {\n" // #6668 - unknown size " char a[LEN];\n" @@ -4575,7 +4575,7 @@ class TestBufferOverrun : public TestFixture { " char c[5];\n" " myfread(c, 1, 6, stdin);\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: c\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); } // extracttests.enable @@ -4625,7 +4625,7 @@ class TestBufferOverrun : public TestFixture { " foo(baz);\n" " foo(baz);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } void terminateStrncpy2() { @@ -4635,7 +4635,7 @@ class TestBufferOverrun : public TestFixture { " bar[99] = 0;\n" " return strdup(baz);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } void terminateStrncpy3() { @@ -4650,7 +4650,7 @@ class TestBufferOverrun : public TestFixture { "void bar(char *p) {\n" " strncpy(p, str, 100);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy().\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } void terminateStrncpy4() { @@ -4664,7 +4664,7 @@ class TestBufferOverrun : public TestFixture { " char buf[4];\n" " strncpy(buf, \"abcde\", 4);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy().\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } void terminateStrncpy5() { // #9944 @@ -4681,7 +4681,7 @@ class TestBufferOverrun : public TestFixture { " if (buf.size() >= sizeof(v))\n" " strncpy(v, buf.c_str(), sizeof(v));\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy().\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:9]: (warning, inconclusive) The buffer 'v' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } // extracttests.enable @@ -5044,7 +5044,7 @@ class TestBufferOverrun : public TestFixture { " A::X x;\n" " x.buf[10] = 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:10]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void getErrorMessages() { @@ -5068,25 +5068,25 @@ class TestBufferOverrun : public TestFixture { " if (s[i] == 'x' && i < y) {\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const char s[]) {\n" " for (int i = 0; s[i] == 'x' && i < y; ++i) {\n" " }" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:22]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const int a[], unsigned i) {\n" " if((a[i] < 2) && (i <= 42)) {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const int a[], unsigned i) {\n" " if((a[i] < 2) && (42 >= i)) {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); // extracttests.start: int elen; check("void f(char* e, int y) {\n" @@ -5100,7 +5100,7 @@ class TestBufferOverrun : public TestFixture { " if(a[i] < func(i) && i <= 42) {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:9]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const int a[], unsigned i) {\n" " if (i <= 42 && a[i] < func(i)) {\n" @@ -5112,7 +5112,7 @@ class TestBufferOverrun : public TestFixture { " if (foo(a[i] + 3) < func(i) && i <= 42) {\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:14]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(int i) {\n" // sizeof " sizeof(a)/sizeof(a[i]) && i < 10;\n" @@ -5146,7 +5146,7 @@ class TestBufferOverrun : public TestFixture { " char c[6];\n" " strncpy(c,\"hello!\",6);\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy().\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); check("void f() {\n" " char c[6];\n" @@ -5168,7 +5168,7 @@ class TestBufferOverrun : public TestFixture { " a = new int[-1];\n" " delete [] a;\n" "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", errout_str()); check("void f()\n" "{\n" @@ -5176,7 +5176,7 @@ class TestBufferOverrun : public TestFixture { " a = (int *)malloc( -10 );\n" " free(a);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", "", errout_str()); check("void f()\n" "{\n" @@ -5184,14 +5184,14 @@ class TestBufferOverrun : public TestFixture { " a = (int *)malloc( -10);\n" " free(a);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", "", errout_str()); check("void f()\n" "{\n" " int *a;\n" " a = (int *)alloca( -10 );\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout_str()); + TODO_ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", "", errout_str()); check("int* f(int n) {\n" // #11145 " int d = -1;\n" @@ -5200,7 +5200,7 @@ class TestBufferOverrun : public TestFixture { " int* p = new int[d];\n" " return p;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Memory allocation size is negative.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:5:14]: (warning, inconclusive) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", errout_str()); } void negativeArraySize() { @@ -5208,7 +5208,7 @@ class TestBufferOverrun : public TestFixture { " int a[sz];\n" "}\n" "void x() { f(-100); }"); - ASSERT_EQUALS("[test.cpp:2]: (error) Declaration of array 'a' with negative size is undefined behaviour\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:8]: (error) Declaration of array 'a' with negative size is undefined behaviour [negativeArraySize]\n", errout_str()); // don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance check("int x, y;\n" @@ -5223,7 +5223,7 @@ class TestBufferOverrun : public TestFixture { " char arr[10];\n" " char *p = arr + 20;\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("char(*g())[1];\n" // #7950 "void f() {\n" @@ -5263,7 +5263,7 @@ class TestBufferOverrun : public TestFixture { " char *s = malloc(4);\n" " dostuff(s);\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7] -> [test.cpp:2]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3. [ctuArrayIndex]\n", errout_str()); ctu("void dostuff(char *p) {\n" " p[4] = 0;\n" @@ -5273,7 +5273,7 @@ class TestBufferOverrun : public TestFixture { " char *s = malloc(4);\n" " dostuff(s);\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4. [ctuArrayIndex]\n", errout_str()); ctu("void f(int* p) {\n" // #10415 " int b[1];\n" @@ -5285,7 +5285,7 @@ class TestBufferOverrun : public TestFixture { " a[0] = 5;\n" " f(a);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:7:12] -> [test.cpp:9:6] -> [test.cpp:3:12]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20. [ctuArrayIndex]\n", errout_str()); } void ctu_array() { @@ -5296,7 +5296,7 @@ class TestBufferOverrun : public TestFixture { " char str[4];\n" " dostuff(str);\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10. [ctuArrayIndex]\n", errout_str()); ctu("static void memclr( char *data )\n" "{\n" @@ -5308,7 +5308,7 @@ class TestBufferOverrun : public TestFixture { " char str[5];\n" " memclr( str );\n" "}"); - ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\n", errout_str()); ctu("static void memclr( int i, char *data )\n" "{\n" @@ -5320,7 +5320,7 @@ class TestBufferOverrun : public TestFixture { " char str[5];\n" " memclr( 0, str );\n" "}"); - ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\n", errout_str()); ctu("static void memclr( int i, char *data )\n" "{\n" @@ -5384,8 +5384,8 @@ class TestBufferOverrun : public TestFixture { " f1(str);\n" " f2(str);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2.\n" - "[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2.\n", + ASSERT_EQUALS("[test.cpp:5:7] -> [test.cpp:1:20]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\n" + "[test.cpp:6:7] -> [test.cpp:2:21]: (error) Array index out of bounds; 's' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]\n", errout_str()); // #5140 @@ -5394,7 +5394,7 @@ class TestBufferOverrun : public TestFixture { " const char* argv[] = { \"test\" };\n" " g(argv);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 4.\n", + ASSERT_EQUALS("[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 4. [ctuArrayIndex]\n", errout_str()); ctu("void g(const char* argv[]) { std::cout << \"argv: \" << argv[5] << std::endl; }\n" @@ -5402,7 +5402,7 @@ class TestBufferOverrun : public TestFixture { " const char* argv[1] = { \"test\" };\n" " g(argv);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5.\n", + ASSERT_EQUALS("[test.cpp:4:6] -> [test.cpp:1:55]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5. [ctuArrayIndex]\n", errout_str()); ctu("void g(int *b) { b[0] = 0; }\n" @@ -5419,7 +5419,7 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " g(a);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8.\n", + ASSERT_EQUALS("[test.cpp:6:6] -> [test.cpp:3:11]: (error) Array index out of bounds; 'd' buffer size is 4 and it is accessed at offset 8. [ctuArrayIndex]\n", errout_str()); } @@ -5431,7 +5431,7 @@ class TestBufferOverrun : public TestFixture { " int x = 4;\n" " dostuff(&x);\n" "}"); - ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40. [ctuArrayIndex]\n", errout_str()); } void ctu_arithmetic() { @@ -5440,7 +5440,7 @@ class TestBufferOverrun : public TestFixture { " int x[3];\n" " dostuff(x);\n" "}"); - ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Pointer arithmetic overflow; 'p' buffer size is 12\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:1:28]: (error) Pointer arithmetic overflow; 'p' buffer size is 12 [ctuPointerArith]\n", errout_str()); ctu("void f(const char *p) {\n" // #11361 " const char* c = p + 1;\n" @@ -5458,7 +5458,7 @@ class TestBufferOverrun : public TestFixture { " return (&i)[1];\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3]: (error) The address of variable 'i' is accessed at non-zero index.\n", + "[test.cpp:3:13] -> [test.cpp:3:16]: (error) The address of variable 'i' is accessed at non-zero index. [objectIndex]\n", errout_str()); check("int f(int j) {\n" @@ -5466,7 +5466,7 @@ class TestBufferOverrun : public TestFixture { " return (&i)[j];\n" "}"); ASSERT_EQUALS( - "[test.cpp:3] -> [test.cpp:3]: (warning) The address of variable 'i' might be accessed at non-zero index.\n", + "[test.cpp:3:13] -> [test.cpp:3:16]: (warning) The address of variable 'i' might be accessed at non-zero index. [objectIndex]\n", errout_str()); check("int f() {\n" @@ -5525,7 +5525,7 @@ class TestBufferOverrun : public TestFixture { " return m[0][1];\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:5]: (error) The address of variable 'x' is accessed at non-zero index.\n", + "[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\n", errout_str()); check("int x = 0;\n" @@ -5535,7 +5535,7 @@ class TestBufferOverrun : public TestFixture { " return m[0][1];\n" "}"); ASSERT_EQUALS( - "[test.cpp:4] -> [test.cpp:5]: (error) The address of variable 'x' is accessed at non-zero index.\n", + "[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\n", errout_str()); check("int f(int * y) {\n" @@ -5625,7 +5625,7 @@ class TestBufferOverrun : public TestFixture { check("uint32_t f(uint32_t u) {\n" " return ((uint8_t*)&u)[4];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:23] -> [test.cpp:2:26]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\n", errout_str()); check("uint32_t f(uint32_t u) {\n" " return reinterpret_cast(&u)[3];\n" @@ -5635,7 +5635,7 @@ class TestBufferOverrun : public TestFixture { check("uint32_t f(uint32_t u) {\n" " return reinterpret_cast(&u)[4];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:45] -> [test.cpp:2:48]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\n", errout_str()); check("uint32_t f(uint32_t u) {\n" " uint8_t* p = (uint8_t*)&u;\n" @@ -5647,7 +5647,7 @@ class TestBufferOverrun : public TestFixture { " uint8_t* p = (uint8_t*)&u;\n" " return p[4];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) The address of variable 'u' is accessed at non-zero index.\n", errout_str()); + ASSERT_EQUALS("[test.cpp:2:28] -> [test.cpp:3:13]: (error) The address of variable 'u' is accessed at non-zero index. [objectIndex]\n", errout_str()); check("uint32_t f(uint32_t* pu) {\n" " uint8_t* p = (uint8_t*)pu;\n" @@ -5687,7 +5687,7 @@ class TestBufferOverrun : public TestFixture { " return;\n" " }\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: pipefd\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: pipefd [bufferAccessOutOfBounds]\n", errout_str()); check("void f(){\n" "int pipefd[2];\n" @@ -5703,7 +5703,7 @@ class TestBufferOverrun : public TestFixture { " return;\n" " }\n" "}", dinit(CheckOptions, $.s = &settings)); - ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: (int*)pipefd\n", errout_str()); + ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: (int*)pipefd [bufferAccessOutOfBounds]\n", errout_str()); check("void f(){\n" "char pipefd[20];\n" // Strange, but large enough