diff --git a/test/testclass.cpp b/test/testclass.cpp index a748b11b0..712ab695d 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -577,7 +577,7 @@ private: "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }\n"); + "A & A::operator=(const A &a) { return *this; }"); ASSERT_EQUALS("", errout.str()); checkOpertorEqRetRefThis( @@ -586,7 +586,7 @@ private: "public:\n" " A & operator=(const A &a);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }\n"); + "A & A::operator=(const A &a) { return *this; }"); ASSERT_EQUALS("", errout.str()); checkOpertorEqRetRefThis( @@ -595,7 +595,7 @@ private: "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return a; }\n"); + "A & A::operator=(const A &a) { return a; }"); ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -604,7 +604,7 @@ private: "public:\n" " A & operator=(const A &a);\n" "};\n" - "A & A::operator=(const A &a) { return a; }\n"); + "A & A::operator=(const A &a) { return a; }"); ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -641,7 +641,7 @@ private: " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return *this; }\n"); + "A::B & A::B::operator=(const A::B &b) { return *this; }"); ASSERT_EQUALS("", errout.str()); checkOpertorEqRetRefThis( @@ -654,7 +654,7 @@ private: " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return b; }\n"); + "A::B & A::B::operator=(const A::B &b) { return b; }"); ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } @@ -847,7 +847,7 @@ private: "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { if (&a != this) { } return *this; }\n"); + "A & A::operator=(const A &a) { if (&a != this) { } return *this; }"); ASSERT_EQUALS("", errout.str()); // this test doesn't have an assignment test but doesn't need it @@ -857,7 +857,7 @@ private: "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }\n"); + "A & A::operator=(const A &a) { return *this; }"); ASSERT_EQUALS("", errout.str()); // this test needs an assignment test and has it @@ -992,7 +992,7 @@ private: " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\n"); + "A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }"); ASSERT_EQUALS("", errout.str()); // this test doesn't have an assignment test but doesn't need it @@ -1006,7 +1006,7 @@ private: " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return *this; }\n"); + "A::B & A::B::operator=(const A::B &b) { return *this; }"); ASSERT_EQUALS("", errout.str()); // this test needs an assignment test and has it @@ -1029,7 +1029,7 @@ private: " s = strdup(b.s);\n" " }\n" " return *this;\n" - " }\n"); + " }"); ASSERT_EQUALS("", errout.str()); // this test needs an assignment test but doesn't have it @@ -1049,7 +1049,7 @@ private: " free(s);\n" " s = strdup(b.s);\n" " return *this;\n" - " }\n"); + " }"); ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); } @@ -1085,7 +1085,7 @@ private: "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }\n"); + "A & A::operator=(const A &a) { return *this; }"); ASSERT_EQUALS("", errout.str()); // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it @@ -1149,7 +1149,7 @@ private: " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return *this; }\n"); + "A::B & A::B::operator=(const A::B &b) { return *this; }"); ASSERT_EQUALS("", errout.str()); // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it @@ -1882,7 +1882,7 @@ private: "};\n" "\n" "void Fred::foobar()\n" - "{ }\n"); + "{ }"); ASSERT_EQUALS("", errout.str()); } @@ -2870,7 +2870,7 @@ private: " };\n" "};\n" "int Fred::B::A::getA() { return a; }\n" - "int Fred::B::getB() { return b; }\n"); + "int Fred::B::getB() { return b; }"); ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const.\n" "[test.cpp:11] -> [test.cpp:7]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const.\n" , errout.str()); } @@ -4023,7 +4023,7 @@ private: " int var;\n" " };\n" "}\n" - "int N::Base::getResourceName() { return var; }\n"); + "int N::Base::getResourceName() { return var; }"); ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout.str()); checkConst("namespace N\n" @@ -4051,7 +4051,7 @@ private: " };\n" "}\n" "using namespace N;\n" - "int Base::getResourceName() { return var; }\n"); + "int Base::getResourceName() { return var; }"); TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", "", errout.str()); } @@ -5191,7 +5191,7 @@ private: " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }\n"); + "int B::func() { return b; }"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout.str()); // base class has no virtual function @@ -5217,7 +5217,7 @@ private: " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }\n"); + "int B::func() { return b; }"); ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:9]: (style, inconclusive) Technically the member function 'B::func' can be const.\n", errout.str()); // base class has virtual function @@ -5243,7 +5243,7 @@ private: " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }\n"); + "int B::func() { return b; }"); ASSERT_EQUALS("", errout.str()); checkConst("class A {\n" @@ -5256,7 +5256,7 @@ private: " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }\n"); + "int B::func() { return b; }"); ASSERT_EQUALS("", errout.str()); // base class has no virtual function @@ -5302,7 +5302,7 @@ private: " C() : c(0) { }\n" " int func();\n" "};\n" - "int C::func() { return c; }\n"); + "int C::func() { return c; }"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'A::func' can be const.\n" "[test.cpp:14] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'B::func' can be const.\n" "[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'C::func' can be const.\n", errout.str()); @@ -5348,7 +5348,7 @@ private: " C() : c(0) { }\n" " int func();\n" "};\n" - "int C::func() { return c; }\n"); + "int C::func() { return c; }"); ASSERT_EQUALS("", errout.str()); // ticket #1311 @@ -5394,7 +5394,7 @@ private: " Z(int x, int y, int z) : Y(x, y), z(z) { }\n" " int getZ();\n" "};\n" - "int Z::getZ() { return z; }\n"); + "int Z::getZ() { return z; }"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Technically the member function 'X::getX' can be const.\n" "[test.cpp:14] -> [test.cpp:12]: (style, inconclusive) Technically the member function 'Y::getY' can be const.\n" "[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'Z::getZ' can be const.\n", errout.str()); diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 43eaf6c6a..189d44301 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -226,7 +226,7 @@ private: " int i;\n" "};\n" "Fred::Fred() :i(0)\n" - "{ }\n"); + "{ }"); ASSERT_EQUALS("", errout.str()); check("struct Fred\n" @@ -235,7 +235,7 @@ private: " int i;\n" "};\n" "Fred::Fred()\n" - "{ i = 0; }\n"); + "{ i = 0; }"); ASSERT_EQUALS("", errout.str()); check("struct Fred\n" @@ -244,7 +244,7 @@ private: " int i;\n" "};\n" "Fred::Fred()\n" - "{ }\n"); + "{ }"); ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str()); } @@ -321,7 +321,7 @@ private: void simple8() { check("struct Fred { int x; };\n" "class Barney { Fred fred; };\n" - "class Wilma { struct Betty { int x; } betty; };\n"); + "class Wilma { struct Betty { int x; } betty; };"); ASSERT_EQUALS("[test.cpp:2]: (style) The class 'Barney' does not have a constructor.\n" "[test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n", errout.str()); } @@ -363,7 +363,7 @@ private: " Fred() { Init(); }\n" " void Init(int i = 0);\n" "};\n" - "void Fred::Init(int i) { x = i; }\n"); + "void Fred::Init(int i) { x = i; }"); ASSERT_EQUALS("", errout.str()); check("class Fred {\n" @@ -373,7 +373,7 @@ private: " Fred() { Init(0); }\n" " void Init(int i, int j = 0);\n" "};\n" - "void Fred::Init(int i, int j) { x = i; y = j; }\n"); + "void Fred::Init(int i, int j) { x = i; y = j; }"); ASSERT_EQUALS("", errout.str()); } @@ -881,7 +881,7 @@ private: " Fred(const Fred &);\n" "};\n" "Fred::Fred() { };\n" - "Fred::Fred(const Fred &) { };\n"); + "Fred::Fred(const Fred &) { };"); ASSERT_EQUALS("", errout.str()); check("class Fred\n" @@ -930,7 +930,7 @@ private: "A::A(){}\n" "A::B::B(int x){}\n" "A::B::C::C(int y){}\n" - "A::B::C::D::D(int z){}\n"); + "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" @@ -960,7 +960,7 @@ private: "A::A(){}\n" "A::B::B(int x){}\n" "A::B::C::C(int y){}\n" - "A::B::C::D::D(const A::B::C::D & d){}\n"); + "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" @@ -991,7 +991,7 @@ private: "A::A(){}\n" "A::B::B(int x){}\n" "A::B::C::C(int y){}\n" - "A::B::C::D::D(const A::B::C::D::E & e){}\n"); + "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" @@ -1998,7 +1998,7 @@ private: " Fred() : f{0, true} { }\n" " float get() const\n" "};\n" - "float Fred::get() const { return g; }\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()); } diff --git a/test/testdivision.cpp b/test/testdivision.cpp index 8891f8e50..501e322ed 100644 --- a/test/testdivision.cpp +++ b/test/testdivision.cpp @@ -131,8 +131,7 @@ private: check("void foo()\n" "{\n" " unsigned int val = 32;\n" - " int i = val / -2; }\n" - ); + " int i = val / -2; }"); ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str()); } @@ -140,7 +139,7 @@ private: check("void foo()\n" "{\n" " unsigned int val = 32;\n" - " int i = -96 / val; }\n"); + " int i = -96 / val; }"); ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str()); } diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 2ea987b7e..2675bd8b3 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -160,7 +160,7 @@ private: " {\n" " throw err;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } @@ -174,7 +174,7 @@ private: " {\n" " throw err;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } @@ -201,7 +201,7 @@ private: " exception err2;\n" " throw err2;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index d0c815d74..848495406 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -75,7 +75,7 @@ private: "{\n" " const char def[] =\n" " \"abc\";\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -84,7 +84,7 @@ private: check("void foo()\n" "{\n" " \"abc\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant.\n", errout.str()); } @@ -93,7 +93,7 @@ private: check("void foo()\n" "{\n" " const char *str[] = { \"abc\" };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -107,7 +107,7 @@ private: "\"more \"\n" "\"world\"\n" "};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -116,7 +116,7 @@ private: check("void foo()\n" "{\n" " 50;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant.\n", errout.str()); } @@ -133,13 +133,13 @@ private: "{\n" "{ 346.1,114.1 }, { 347.1,111.1 }\n" "};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void intarray() { - check("int arr[] = { 100/2, 1*100 };\n"); + check("int arr[] = { 100/2, 1*100 };"); ASSERT_EQUALS("", errout.str()); } @@ -147,7 +147,7 @@ private: check("struct st arr[] = {\n" " { 100/2, 1*100 }\n" " { 90, 70 }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -155,14 +155,14 @@ private: check("struct st arr[] = {\n" " { 100/2, 1*100 }\n" " { 90, 70 }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } void conditionalcall() { check("void f() {\n" " 0==x ? X() : Y();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -170,7 +170,7 @@ private: // #2462 - C++11 struct initialization check("void f() {\n" " ABC abc{1,2,3};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #2482 - false positive for empty struct diff --git a/test/testinternal.cpp b/test/testinternal.cpp index ae75efab5..47c5252e4 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -309,7 +309,7 @@ private: " Z(){\n" " z[0] = 0;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testio.cpp b/test/testio.cpp index aeac6ba41..8377989da 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -474,7 +474,7 @@ private: "{\n" " char str [8];\n" " scanf (\"%70s\",str);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Width 70 given in format string (no. 1) is larger than destination buffer 'str[8]', use %7s to prevent overflowing it.\n", errout.str()); } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 229f4b884..436f90f7c 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -127,7 +127,7 @@ private: " char *p = malloc(10);\n" " p = NULL;\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str()); } @@ -136,7 +136,7 @@ private: " char *p = malloc(10);\n" " char *q = p;\n" " free(q);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -145,7 +145,7 @@ private: " char *p = malloc(10);\n" " char *q = p + 1;\n" " free(q - 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -154,7 +154,7 @@ private: " char *a = malloc(10);\n" " a += 10;\n" " free(a - 10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -163,7 +163,7 @@ private: "{\n" " char *p = new char[100];\n" " list += p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -172,7 +172,7 @@ private: " char *p = malloc(10);\n" " p = strcpy(p,q);\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -180,7 +180,7 @@ private: check("void foo(struct str *d) {\n" " struct str *p = malloc(10);\n" " d->p = p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -188,7 +188,7 @@ private: check("void foo(struct str *d) {\n" " struct str *p = malloc(10);\n" " d->p = &p->x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -197,7 +197,7 @@ private: " char *p = x();\n" " free(p);\n" " p = NULL;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -207,7 +207,7 @@ private: " if (x) { p = malloc(10); }\n" " if (!x) { p = NULL; }\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -436,7 +436,7 @@ private: " free(a);\n" " else\n" " a = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.c:6]: (error) Memory leak: a\n", errout.str()); } @@ -459,7 +459,7 @@ private: " for (i=0;i<5;i++) { }\n" " if (x) { free(p) }\n" " else { a = p; }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c9b02ff1e..ddecb0094 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -894,7 +894,7 @@ private: "{\n" " struct *str = new strlist;\n" " return &str->s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -905,7 +905,7 @@ private: "void foo()\n" "{\n" " Fred *f = new Fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -916,7 +916,7 @@ private: " MyClass *c = new MyClass();\n" " c->free(c);\n" " delete c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -937,7 +937,7 @@ private: " if (c)\n" " h(s);\n" " free(s);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -947,53 +947,53 @@ private: check("void f()\n" "{\n" " int *p = new(std::nothrow) int;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); check("void f()\n" "{\n" " using std::nothrow;\n" " int *p = new(nothrow) int;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); check("void f()\n" "{\n" " int *p = new(std::nothrow) int[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); check("void f()\n" "{\n" " using namespace std;\n" " int *p = new(nothrow) int[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); check("void f()\n" "{\n" " int *p = new(std::nothrow) int;\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: p\n", errout.str()); check("void f()\n" "{\n" " int *p = new(std::nothrow) int[10];\n" " delete p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: p\n", errout.str()); check("void f()\n" "{\n" " Fred *f = new(nothrow) Fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" "{\n" " Fred *f = new(std::nothrow) Fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ticket #2971 @@ -1001,14 +1001,14 @@ private: "{\n" " Fred *f = new(std::nothrow) Fred[10];\n" " delete f;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: f\n", errout.str()); check("void f()\n" "{\n" " struct Fred *f = new(std::nothrow) struct Fred[10];\n" " delete f;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: f\n", errout.str()); } @@ -1020,7 +1020,7 @@ private: " free(s);\n" " s = malloc(100);\n" " return 123;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1029,7 +1029,7 @@ private: "{\n" " extern char *s;\n" " s = malloc(100);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1037,7 +1037,7 @@ private: check("void f() {\n" " char *&x = get();\n" " x = malloc(100);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1049,7 +1049,7 @@ private: " str = new char[10];\n" " str = new char[20];\n" " delete [] str;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); } @@ -1071,7 +1071,7 @@ private: " return s;\n" " }\n" " return NULL;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: s\n", errout.str()); } @@ -1085,7 +1085,7 @@ private: " s = new char[10];\n" " }\n" " return s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1099,7 +1099,7 @@ private: " return s;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1130,7 +1130,7 @@ private: " ;\n" " if (b)\n" " free(s);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1146,7 +1146,7 @@ private: " if( b )\n" " delete [] a;\n" " else {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1164,7 +1164,7 @@ private: " return;\n" " }\n" " free(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: c\n", errout.str()); } @@ -1179,7 +1179,7 @@ private: " }\n" " buf = tmp;\n" " return buf;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1192,7 +1192,7 @@ private: " else if (buf = realloc(buf, 100))\n" " ;\n" " free(buf);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Common realloc mistake: \'buf\' nulled but not freed upon failure\n", errout.str()); } @@ -1220,7 +1220,7 @@ private: " str = strdup(a[i]);\n" " }\n" " return str;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1233,7 +1233,7 @@ private: " {\n" " str = strdup(a[i]);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: str\n", errout.str()); } @@ -1255,7 +1255,7 @@ private: " }\n" "\n" " return a;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: a\n", "[test.cpp:8]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n", @@ -1311,7 +1311,7 @@ private: " while((stream = fopen(name,\"r\")) == NULL)\n" " { }\n" " if(stream!=NULL) fclose(stream);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1330,7 +1330,7 @@ private: " default:\n" " break;\n" " };\n" - "}\n"); + "}"); check(code.c_str(), false); ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: str\n", errout.str()); } @@ -1348,7 +1348,7 @@ private: " }\n" " }\n" " delete [] str;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: str\n", errout.str()); } @@ -1360,7 +1360,7 @@ private: " case 0:\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str()); } @@ -1369,7 +1369,7 @@ private: "{\n" " char *c = new char[50];\n" " return (c ? c : NULL);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1378,7 +1378,7 @@ private: "{\n" " char *c = new char[50];\n" " return strcpy(c, \"foo\");\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1387,7 +1387,7 @@ private: "{\n" " char *c = new char[50];\n" " return memcpy(c, \"foo\",4);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1396,7 +1396,7 @@ private: "{\n" " char *c = new char[50];\n" " return ((char *)(c+1));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1484,7 +1484,7 @@ private: " buf = malloc(3);\n" " buf[i] = 0;\n" " free(buf);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1502,7 +1502,7 @@ private: "{\n" " char *p = new char[100];\n" " foo(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str()); } @@ -1517,7 +1517,7 @@ private: "{\n" " char *p = new char[100];\n" " foo(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1548,7 +1548,7 @@ private: "{\n" " char *p = new char[100];\n" " foo(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: p\n", errout.str()); } @@ -1565,7 +1565,7 @@ private: "{\n" " char *p = new char[100];\n" " foo(p);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: p\n", "", errout.str()); } @@ -1583,7 +1583,7 @@ private: " if (b())\n" " return;\n" " delete [] a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1592,7 +1592,7 @@ private: "{\n" " char *c = malloc(50);\n" " (fnc)(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1601,7 +1601,7 @@ private: "{\n" " char *c = malloc(50);\n" " (s1->fnc)(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1620,7 +1620,7 @@ private: " return -ENOMEM;\n" "\n" " add_list(base);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1629,7 +1629,7 @@ private: "{\n" " char *p = malloc(100);\n" " foo(&p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1645,7 +1645,7 @@ private: " char *p = malloc(100);\n" " foo(p);\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1658,7 +1658,7 @@ private: " char *p = malloc(100);\n" " if (a()) return;\n" // <- memory leak " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str()); } @@ -1677,7 +1677,7 @@ private: " a(box);\n" " }\n" " return box;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1702,7 +1702,7 @@ private: " char *res = malloc(65);\n" " bar(parent, res, a);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1730,7 +1730,7 @@ private: "{\n" " int *p = malloc(16);\n" " free_pointers(1, p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1744,7 +1744,7 @@ private: " int *p = malloc(16);\n" " if (!a(p)) return;\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1764,7 +1764,7 @@ private: " exit(0);\n" " }\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // False positive in classmember @@ -1780,7 +1780,7 @@ private: " exit(0);\n" " }\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1798,7 +1798,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpFile\n", errout.str()); check("void foo ()\n" @@ -1812,7 +1812,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str()); check("void foo ()\n" @@ -1827,7 +1827,7 @@ private: " }\n" " delete [] cpFile;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -1843,7 +1843,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpFile\n", errout.str()); check("void foo ()\n" @@ -1857,7 +1857,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str()); check("void foo ()\n" @@ -1872,7 +1872,7 @@ private: " }\n" " delete [] cpFile;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // checking for access function @@ -1889,7 +1889,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpFile\n", errout.str()); check("void foo ()\n" @@ -1903,7 +1903,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str()); check("void foo ()\n" @@ -1918,7 +1918,7 @@ private: " }\n" " delete [] cpFile;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -1936,7 +1936,7 @@ private: " }\n" " delete [] cpDir;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: cpDir\n", errout.str()); check("void foo()\n" @@ -1949,7 +1949,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpDir\n", errout.str()); check("void foo()\n" @@ -1963,7 +1963,7 @@ private: " }\n" " delete [] cpDir;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // checking for chmod function @@ -1980,7 +1980,7 @@ private: " }\n" " delete [] cpDir;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: cpDir\n", errout.str()); check("void foo()\n" @@ -1993,7 +1993,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpDir\n", errout.str()); check("void foo()\n" @@ -2007,7 +2007,7 @@ private: " }\n" " delete [] cpDir;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -2025,7 +2025,7 @@ private: " }\n" " delete [] cpDir;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: cpDir\n", errout.str()); check("void foo()\n" @@ -2038,7 +2038,7 @@ private: " return;\n" " }\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpDir\n", errout.str()); check("void foo()\n" @@ -2052,7 +2052,7 @@ private: " }\n" " delete [] cpDir;\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // checking perror @@ -2065,7 +2065,7 @@ private: " sprintf(cBuf,\"%s\",\"testtest..\");\n" " perror (cBuf);\n" " delete [] cBuf;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -2073,7 +2073,7 @@ private: " char *cBuf = new char[11];\n" " sprintf(cBuf,\"%s\",\"testtest..\");\n" " perror (cBuf);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: cBuf\n", errout.str()); } @@ -2090,7 +2090,7 @@ private: " }\n" " delete [] cpFile;\n" " fclose (stdout);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: cpFile\n", errout.str()); check("void foo()\n" @@ -2104,7 +2104,7 @@ private: " return;\n" " }\n" " fclose (stdout);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: cpFile\n", errout.str()); check("void foo()\n" @@ -2119,7 +2119,7 @@ private: " }\n" " delete [] cpFile;\n" " fclose (stdout);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2139,7 +2139,7 @@ private: " }\n" " delete [] cpFile;\n" " return file;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: cpFile\n", errout.str()); check("int * foo()\n" @@ -2153,7 +2153,7 @@ private: " return file;\n" " }\n" " return file;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str()); check("int * foo()\n" @@ -2168,7 +2168,7 @@ private: " }\n" " delete [] cpFile;\n" " return file;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // check for _open, _wopen @@ -2185,7 +2185,7 @@ private: " }\n" " delete [] cpFile;\n" " return file;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: cpFile\n", errout.str()); check("int * foo()\n" @@ -2199,7 +2199,7 @@ private: " return file;\n" " }\n" " return file;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str()); check("int * foo()\n" @@ -2214,7 +2214,7 @@ private: " }\n" " delete [] cpFile;\n" " return file;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2223,14 +2223,14 @@ private: check("void f(void)\n" "{\n" " std::string *x = new std::string;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n","", errout.str()); check("void f(void)\n" "{\n" " std::string *x = new std::string;\n" " delete x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2240,14 +2240,14 @@ private: "{\n" " Fred *f = new Fred();\n" " delete f;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class Fred { };\n" "void f(void)\n" "{\n" " Fred *f = new Fred();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: f\n", errout.str()); check("class Fred { void foo(){ } };\n" @@ -2255,14 +2255,14 @@ private: "{\n" " Fred *f = new Fred();\n" " delete f;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class Fred { void foo(){ } };\n" "void f(void)\n" "{\n" " Fred *f = new Fred();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: f\n", errout.str()); } @@ -2279,13 +2279,13 @@ private: check("void f(FRED *pData)\n" "{\n" " pData =(FRED*)malloc( 100 );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: pData\n", errout.str()); check("void f(int *pData)\n" "{\n" " pData =(int*)malloc( 100 );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: pData\n", errout.str()); } @@ -2297,7 +2297,7 @@ private: "static void b()\n" "{\n" " char *p = a();\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); check("FILE *a()\n" @@ -2307,7 +2307,7 @@ private: "static void b()\n" "{\n" " FILE *p = a();\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Resource leak: p\n"), errout.str()); check("char *a()\n" @@ -2317,7 +2317,7 @@ private: "static void b()\n" "{\n" " char *p = a();\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); } @@ -2331,7 +2331,7 @@ private: " int len = 100;\n" " char *p = a(len);\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string(""), errout.str()); check("char *a(char *a)\n" @@ -2346,7 +2346,7 @@ private: " free(q);\n" " else\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string(""), errout.str()); check("char *a()\n" @@ -2357,7 +2357,7 @@ private: "{\n" " char *p = a();\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string(""), errout.str()); } @@ -2370,7 +2370,7 @@ private: "static void b()\n" "{\n" " char *p = a();\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); } @@ -2385,7 +2385,7 @@ private: "void bar()\n" "{\n" " char *p = foo();\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"), errout.str()); check("char* foo()\n" @@ -2399,7 +2399,7 @@ private: "{\n" " char *p = foo();\n" " delete p;\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Mismatching allocation and deallocation: p\n"), errout.str()); } @@ -2413,7 +2413,7 @@ private: "{\n" " char *p;\n" " foo(&p);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:10]: (error) Memory leak: p\n"), errout.str()); check("void foo(char **str)\n" @@ -2426,7 +2426,7 @@ private: " char *p;\n" " foo(&p);\n" " delete p;\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:10]: (error) Mismatching allocation and deallocation: p\n"), errout.str()); check("void foo(char **q, char **str)\n" @@ -2439,7 +2439,7 @@ private: " char *p;\n" " char *q;\n" " foo(&q, &p);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"), errout.str()); check("void foo(char **str)\n" @@ -2452,7 +2452,7 @@ private: "{\n" " char *p;\n" " foo(&p);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"), "", errout.str()); @@ -2468,7 +2468,7 @@ private: " foo(&tmp);\n" " foo(&tmp);\n" " free(tmp);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string(""), errout.str()); //#ticket 1789: getcode other function: @@ -2486,7 +2486,7 @@ private: " foo(&tmp);\n" " foo(&tmp);\n" " free(tmp);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string(""), errout.str()); } @@ -2506,7 +2506,7 @@ private: " fclose(f);\n" "\n" " free(expr);\n" - "}\n"); + "}"); ASSERT_EQUALS(std::string(""), errout.str()); } @@ -2523,7 +2523,7 @@ private: "static void foo()\n" "{\n" " char* s = data();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2571,7 +2571,7 @@ private: void allocfunc11() { // ticket #3809 - false positive check("void f (double * & data_val) {\n" " data_val = malloc(0x100);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2613,7 +2613,7 @@ private: " if ( ! abc )\n" " throw 123;\n" " delete [] str;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); } @@ -2633,7 +2633,7 @@ private: " {\n" " delete [] str;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2651,7 +2651,7 @@ private: "{\n" " struct AB *ab = new AB;\n" " func(&ab->a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2675,7 +2675,7 @@ private: " free(s2);\n" "\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: s2\n", errout.str()); } @@ -2686,7 +2686,7 @@ private: "{\n" " char *a = (char *)malloc(10);\n" " a = realloc(a, 100);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n" "[test.cpp:5]: (error) Memory leak: a\n", errout.str()); } @@ -2697,7 +2697,7 @@ private: " char *a = (char *)malloc(10);\n" " a = (char *)realloc(a, 100);\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n", errout.str()); } @@ -2709,7 +2709,7 @@ private: " if ((a = realloc(a, 100)) == NULL)\n" " return;\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2721,7 +2721,7 @@ private: " if ((a = realloc(a, 100)) == NULL)\n" " return;\n" " free(a);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", @@ -2811,7 +2811,7 @@ private: " if ((a = realloc(a, x + 100)) == NULL)\n" " return;\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2821,7 +2821,7 @@ private: " char **str;\n" " *str = realloc(*str,100);\n" " free (*str);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Common realloc mistake: \'str\' nulled but not freed upon failure\n", errout.str()); } @@ -2854,7 +2854,7 @@ private: " char *a = (char *)malloc(10);\n" " a = 0;\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str()); @@ -2863,7 +2863,7 @@ private: " char *a = (char *)malloc(10);\n" " char *p = a;\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -2872,7 +2872,7 @@ private: " char *a = (char *)malloc(10);\n" " char *p = a + 1;\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -2881,7 +2881,7 @@ private: " char *a = (char *)malloc(10);\n" " a += 10;\n" " free(a - 10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -2890,7 +2890,7 @@ private: " char *a = (char *)malloc(10);\n" " a = (void *)a + 10;\n" " free(a - 10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -2898,7 +2898,7 @@ private: "{\n" " char *a = new char[100];\n" " list += a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2910,7 +2910,7 @@ private: " bar = g_strdup(fuba);\n" " bar = g_strstrip(bar);\n" " g_free(bar);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2923,7 +2923,7 @@ private: " delete p;\n" " }\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2931,7 +2931,7 @@ private: check("void foo()\n" "{\n" " char *a = reinterpret_cast(malloc(10));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str()); } @@ -2945,7 +2945,7 @@ private: " char *s = new char[100];\n" " delete [] s;\n" " p = s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" @@ -2953,7 +2953,7 @@ private: " char *s = new char[100];\n" " delete [] s;\n" " foo(s);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // The pointer to the pointer is valid.. @@ -2962,7 +2962,7 @@ private: " char *str;\n" " free(str);\n" " foo(&str);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -2971,7 +2971,7 @@ private: " free(str);\n" " f1(&str);\n" " f2(str);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Dereferencing the freed pointer is not ok.. @@ -2980,7 +2980,7 @@ private: " char *str = malloc(10);\n" " free(str);\n" " char c = *str;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", "", errout.str()); @@ -2989,7 +2989,7 @@ private: " char *str = malloc(10);\n" " free(str);\n" " char c = str[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); check("void foo()\n" @@ -2997,21 +2997,21 @@ private: " char *str = malloc(10);\n" " free(str);\n" " str[10] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); check("void foo() {\n" " char *str = malloc(10);\n" " free(str);\n" " strcpy(str, p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); check("void foo(int x) {\n" " char *str = malloc(10);\n" " free(str);\n" " assert(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3020,7 +3020,7 @@ private: check("void f(char *s) {\n" " free(s);\n" " strcpy(a, s=b());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3030,7 +3030,7 @@ private: " char *str = malloc(10);\n" " realloc(str, 0);\n" " str[10] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); check("void foo()\n" @@ -3038,7 +3038,7 @@ private: " char *str = realloc(0, 10);\n" " realloc(str, 0);\n" " str[10] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); } @@ -3048,7 +3048,7 @@ private: " char *str = malloc(100);\n" " free(str);\n" " free(str);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Deallocating a deallocated pointer: str\n", errout.str()); } @@ -3058,7 +3058,7 @@ private: " FILE *fd = fopen(\"test.txt\", \"wb\");\n" " fprintf(fd, \"test\");\n" " fclose(fd);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3069,7 +3069,7 @@ private: " free(p);\n" " bar(&p);\n" " free(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3127,7 +3127,7 @@ private: " ThrowException();\n" " }\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3140,7 +3140,7 @@ private: " delete [] p;\n" " ThrowException();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: p\n", errout.str()); check("void foo()\n" @@ -3148,7 +3148,7 @@ private: " int *p = new int[100];\n" " p = g();\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); } @@ -3159,7 +3159,7 @@ private: " a();\n" " if (b) return;\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } @@ -3176,7 +3176,7 @@ private: " FREENULL(p);\n" " FREENULL();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3189,7 +3189,7 @@ private: " {\n" " int *p = new int[100];\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str()); } @@ -3260,7 +3260,7 @@ private: "{\n" " FILE *f = popen (\"test\", \"w\");\n" " int a = pclose(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3269,7 +3269,7 @@ private: "{\n" " char *out = new char[100];\n" " exit(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" @@ -3277,7 +3277,7 @@ private: " char *out = new char[100];\n" " if( out ) {}\n" " exit(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3289,7 +3289,7 @@ private: " {\n" " exit(0);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str()); } @@ -3302,7 +3302,7 @@ private: " xyz();\n" " exit(0);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3320,7 +3320,7 @@ private: " }\n" " fclose(sfile);\n" " exit(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3335,7 +3335,7 @@ private: "void b() {\n" " char *p = malloc(100);\n" " int i = a(123);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: p\n", errout.str()); } @@ -3347,7 +3347,7 @@ private: "{\n" " char *p = malloc(100);\n" " fatal_error();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void fatal_error()\n" // #2440 @@ -3357,7 +3357,7 @@ private: "{\n" " char *p = malloc(100);\n" " fatal_error();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str()); } @@ -3368,7 +3368,7 @@ private: "{\n" " char *out = new char[11];\n" " memset(&(out[0]), 0, 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: out\n", errout.str()); } @@ -3377,7 +3377,7 @@ private: check("void f()\n" "{\n" " char *out = strndup(\"text\", 3);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: out\n", errout.str()); } @@ -3385,7 +3385,7 @@ private: check("void f()\n" "{\n" " FILE *f = tmpfile();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: f\n", errout.str()); check("void f()\n" @@ -3393,14 +3393,14 @@ private: " FILE *f = tmpfile();\n" " if (!f)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Resource leak: f\n", errout.str()); check("void f()\n" "{\n" " FILE *f = tmpfile();\n" " fclose(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" @@ -3409,13 +3409,13 @@ private: " if (!f)\n" " return;\n" " fclose(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("FILE *f()\n" "{\n" " return tmpfile();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3424,14 +3424,14 @@ private: "{\n" " FILE *f = fopen(fname, str);\n" " fcloseall();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" "{\n" " FILE *f = tmpfile();\n" " fcloseall();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3477,7 +3477,7 @@ private: " int fd = open(path, O_RDONLY);\n" " FILE *f = fdopen(fd, x);\n" " fclose(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3485,7 +3485,7 @@ private: check("void f(const char *path)\n" "{\n" " int fd = creat(path, S_IRWXU);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: fd\n", errout.str()); } @@ -3494,14 +3494,14 @@ private: "{\n" " int fd = open(path, O_RDONLY);\n" " close(fd);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(const char *path)\n" "{\n" " int fd = creat(path, S_IRWXU);\n" " close(fd);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(const char *path)\n" @@ -3510,7 +3510,7 @@ private: " if (close(fd) < 0) {\n" " perror(\"close\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); //#ticket 1401 @@ -3528,7 +3528,7 @@ private: " return 3;\n" " }\n" " close(handle);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); //#ticket 1401 @@ -3545,7 +3545,7 @@ private: " return 3;\n" " }\n" " close(handle);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11]: (error) Resource leak: handle\n", errout.str()); } @@ -3573,7 +3573,7 @@ private: " ftruncate(fd, len);\n" " fstat(fd, buf);\n" " fchmod(fd, mode);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:24]: (error) Resource leak: fd\n", errout.str()); } @@ -3581,7 +3581,7 @@ private: check("void f()\n" "{\n" " DIR *f = opendir(\".\");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: f\n", errout.str()); } @@ -3589,7 +3589,7 @@ private: check("void f(int fd)\n" "{\n" " DIR *f = fdopendir(fd);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: f\n", errout.str()); } @@ -3598,21 +3598,21 @@ private: "{\n" " DIR *f = opendir(\".\");\n" " closedir(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int fd)\n" "{\n" " DIR *f = fdopendir(fd);\n" " closedir(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" " DIR * f = opendir(dirname);\n" " if (closedir(f));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3626,7 +3626,7 @@ private: " telldir(f);\n;" " seekdir(f, 2)\n;" " scandir(f, namelist, filter, comp);\n;" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Resource leak: f\n", errout.str()); } @@ -3652,7 +3652,7 @@ private: "fsetpos(in, 0);\n" "fgetpos(in, 10);\n" "fprintf(in, \"text\\n\");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:22]: (error) Resource leak: f\n", errout.str()); } @@ -3664,7 +3664,7 @@ private: " FILE *fin1a = fopen (\"FILE.txt\", \"r\");\n" " while ( (c = getc (fin1a)) != EOF)\n" " { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Resource leak: fin1a\n", errout.str()); } @@ -3674,7 +3674,7 @@ private: " int c;\n" " FILE *fin1b = fopen(\"FILE.txt\", \"r\");\n" " c = getc(fin1b);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Resource leak: fin1b\n", errout.str()); } } @@ -3685,7 +3685,7 @@ private: " char *c = new char[12];\n" " *c = 0;\n" " *data = c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3703,7 +3703,7 @@ private: " a[0] = 1;\n" " delete [] a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3721,7 +3721,7 @@ private: " __ptr;\n" " } );\n" " free(sym);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3730,7 +3730,7 @@ private: "{\n" " int *p = new int[100];\n" " typeid(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } @@ -3741,7 +3741,7 @@ private: "{\n" " char *p = malloc(10);\n" " abc.a(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3749,7 +3749,7 @@ private: check("void a(char *p)\n" "{\n" " p = malloc(100);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); } @@ -3772,7 +3772,7 @@ private: " longjmp(env, 1);\n" "\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3792,14 +3792,14 @@ private: "{\n" " char* str = strdup(\"abc def\");\n" " char *name = strtok(str, \" \");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); check("void f(char *cBuf)\n" "{\n" " char* str = strdup(*cBuf);\n" " char *name = strtok(str, \" \");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); } @@ -3813,7 +3813,7 @@ private: "\n" "void bar() {\n" " char *s = foo();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("char *foo() {\n" @@ -3823,7 +3823,7 @@ private: "\n" "void bar() {\n" " char *s = foo();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int shl()\n" @@ -3835,7 +3835,7 @@ private: "int shr()\n" "{\n" " return shl();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3845,7 +3845,7 @@ private: "int *a = new int[10];\n" "try {}\n" "catch(...) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str()); } @@ -3970,7 +3970,7 @@ private: "Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); check("class Fred\n" @@ -3988,7 +3988,7 @@ private: " {\n" " delete [] str2;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); } @@ -4010,7 +4010,7 @@ private: "Fred::~Fred()\n" "{\n" " free(str1);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:17]: (error) Mismatching allocation and deallocation: Fred::str1\n", errout.str()); check("class Fred\n" @@ -4026,7 +4026,7 @@ private: " {\n" " free(str1);\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:12]: (error) Mismatching allocation and deallocation: Fred::str1\n", errout.str()); } @@ -4062,7 +4062,7 @@ private: " delete tok;\n" " tok = next;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -4091,7 +4091,7 @@ private: " tok = next;\n" " }\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4115,7 +4115,7 @@ private: "{\n" " ABC *p = new ABC;\n" " addAbc( p );\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct ABC;\n" @@ -4132,7 +4132,7 @@ private: " ABC *p = new ABC;\n" " addAbc( p );\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4148,7 +4148,7 @@ private: " char *str = new char[100];\n" " delete [] str;\n" " hello();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class Fred\n" @@ -4160,7 +4160,7 @@ private: " delete [] str;\n" " hello();\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4180,7 +4180,7 @@ private: "Fred::~Fred()\n" "{\n" " delete this->i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class Fred\n" @@ -4195,7 +4195,7 @@ private: " {\n" " delete this->i;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4212,7 +4212,7 @@ private: " int* c = new int(1);\n" " delete c;\n" " doNothing(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class A\n" @@ -4225,7 +4225,7 @@ private: " doNothing(c);\n" " }\n" " void doNothing() { }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4242,7 +4242,7 @@ private: "{ p = new int; }\n" "\n" "A::~A()\n" - "{ delete (p); }\n"); + "{ delete (p); }"); ASSERT_EQUALS("", errout.str()); check("class A\n" @@ -4253,7 +4253,7 @@ private: " { p = new int; }\n" " ~A()\n" " { delete (p); }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4265,7 +4265,7 @@ private: " A();\n" "};\n" "A::A()\n" - "{ p = new int; }\n"); + "{ p = new int; }"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); check("class A\n" @@ -4273,7 +4273,7 @@ private: "public:\n" " int * p;\n" " A() { p = new int; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } @@ -4284,7 +4284,7 @@ private: " int * p;\n" " A() : p(new int[10])\n" " { }" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); check("class A\n" @@ -4316,7 +4316,7 @@ private: "{ }\n" "\n" "void A::cleanup()\n" - "{ delete [] p; }\n"); + "{ delete [] p; }"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); check("class A\n" @@ -4330,7 +4330,7 @@ private: " { }\n" " void cleanup()\n" " { delete [] p; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } @@ -4352,7 +4352,7 @@ private: "{ }\n" "\n" "void A::foo()\n" - "{ p = new int[10]; delete [] p; }\n"); + "{ p = new int[10]; delete [] p; }"); ASSERT_EQUALS("[test.cpp:17]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n", errout.str()); check("class A\n" @@ -4366,7 +4366,7 @@ private: " { }\n" " void foo()\n" " { p = new int[10]; delete [] p; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:11]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n", errout.str()); } @@ -4379,7 +4379,7 @@ private: "};\n" "\n" "void A::init()\n" - "{ p = new int[10]; }\n"); + "{ p = new int[10]; }"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n" "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); @@ -4389,7 +4389,7 @@ private: "public:\n" " void init()\n" " { p = new int[10]; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n" "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); @@ -4402,7 +4402,7 @@ private: "};\n" "\n" "void A::init()\n" - "{ p = new int; }\n"); + "{ p = new int; }"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n" "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); @@ -4412,7 +4412,7 @@ private: "public:\n" " void init()\n" " { p = new int; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n" "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); @@ -4425,7 +4425,7 @@ private: "};\n" "\n" "void A::init()\n" - "{ p = malloc(sizeof(int)*10); }\n"); + "{ p = malloc(sizeof(int)*10); }"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n" "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); @@ -4435,7 +4435,7 @@ private: "public:\n" " void init()\n" " { p = malloc(sizeof(int)*10); }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n" "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } @@ -4459,7 +4459,7 @@ private: " A()\n" " { p = new int[10]; }\n" " ~A() { delete [] p; }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); @@ -4481,7 +4481,7 @@ private: " A()\n" " { p = new int; }\n" " ~A() { delete p; }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); @@ -4503,7 +4503,7 @@ private: " A()\n" " { p = malloc(sizeof(int)*10); }\n" " ~A() { free(p); }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4516,7 +4516,7 @@ private: "public:\n" " A() { a = b = new int[10]; }\n" " ~A() { delete [] a; }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4533,7 +4533,7 @@ private: "{\n" " A::pd = new char[12];\n" " delete [] A::pd;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated.\n", errout.str()); check("class A {\n" @@ -4545,7 +4545,7 @@ private: " pd = new char[12];\n" " delete [] pd;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated.\n", errout.str()); check("class A {\n" @@ -4559,7 +4559,7 @@ private: "{\n" " pd = new char[12];\n" " delete [] pd;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated.\n", errout.str()); } @@ -4575,7 +4575,7 @@ private: " }\n" "private:\n" " char *a;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("class A : public x\n" @@ -4589,7 +4589,7 @@ private: "{\n" " a = new char[10];\n" " foo(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4607,7 +4607,7 @@ private: "{\n" " rp1 = new TRadioButton(this);\n" " rp2 = new TRadioButton(this);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class TRadioButton { };\n" @@ -4623,7 +4623,7 @@ private: "{\n" " rp1 = new TRadioButton;\n" " rp2 = new TRadioButton;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Class 'Foo' is unsafe, 'Foo::rp1' can leak by wrong usage.\n" "[test.cpp:6]: (style) Class 'Foo' is unsafe, 'Foo::rp2' can leak by wrong usage.\n", errout.str()); @@ -4646,7 +4646,7 @@ private: "{\n" " delete rp1;\n" " delete rp2;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4668,7 +4668,7 @@ private: " delete [] str2;\n" " }\n" " };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); check("namespace ns1 {\n" @@ -4692,7 +4692,7 @@ private: " {\n" " delete [] str2;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); check("namespace ns1 {\n" @@ -4715,7 +4715,7 @@ private: "ns1::Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); check("namespace ns1 {\n" @@ -4740,7 +4740,7 @@ private: "ns1::ns2::Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); check("namespace ns1 {\n" @@ -4767,7 +4767,7 @@ private: "ns1::ns2::ns3::Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); } @@ -4784,7 +4784,7 @@ private: " C *c;\n" "public:\n" " A() : b(new B()), c(new C(b)) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (style) Class 'A' is unsafe, 'A::b' can leak by wrong usage.\n" "[test.cpp:10]: (style) Class 'A' is unsafe, 'A::c' can leak by wrong usage.\n", errout.str()); @@ -4804,7 +4804,7 @@ private: " b = new B();\n" " c = new C(b);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (style) Class 'A' is unsafe, 'A::b' can leak by wrong usage.\n" "[test.cpp:10]: (style) Class 'A' is unsafe, 'A::c' can leak by wrong usage.\n", errout.str()); } @@ -4816,7 +4816,7 @@ private: "private:\n" " Fred() { a = new int; }\n" " ~Fred() { (delete(a), (a)=NULL); }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4835,7 +4835,7 @@ private: " ~CData() { if (m_impl) m_impl->Release(); }\n" "private:\n" " CDataImpl *m_impl;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4846,7 +4846,7 @@ private: "public:\n" " Fred(const Fred &fred) { a = new int; }\n" " ~Fred() { delete a; }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4857,7 +4857,7 @@ private: "public:\n" " Fred() { a = new int; }\n" " ~Fred();\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4872,7 +4872,7 @@ private: " if (!p)\n" " p = new int[100];\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4904,7 +4904,7 @@ private: "void Tokenizer::deleteTokens(int *tok)\n" "{\n" " delete tok;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Global function @@ -4931,7 +4931,7 @@ private: "{\n" " deleteTokens(_tokens);\n" " _tokens = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4956,7 +4956,7 @@ private: "\n" "A::~A() {\n" " delete [] pkt_buffer;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:14]: (error) Mismatching allocation and deallocation: A::pkt_buffer\n", errout.str()); } @@ -4970,7 +4970,7 @@ private: " ~Fred() { free(s); }\n" " void xy()\n" " { s = malloc(100); }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); check("class Fred\n" @@ -4982,7 +4982,7 @@ private: " { s = malloc(100); }\n" "private:\n" " char *s;\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:7]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); } @@ -4996,7 +4996,7 @@ private: " ~Fred() { free(s); }\n" " const Fred & operator = (const Fred &f)\n" " { s = malloc(100); }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", errout.str()); } }; @@ -5075,14 +5075,14 @@ private: " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " free(abc);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: abc.a\n", errout.str()); check("static void foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: abc.a\n", errout.str()); check("static ABC * foo()\n" @@ -5095,7 +5095,7 @@ private: " return 0;\n" " }\n" " return abc;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: abc.a\n", errout.str()); check("static void foo(int a)\n" @@ -5107,7 +5107,7 @@ private: " free(abc->a);\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: abc.a\n", errout.str()); } @@ -5123,7 +5123,7 @@ private: "out:\n" " free(abc->a);\n" " free(abc);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5133,13 +5133,13 @@ private: " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " return abc;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static void foo(struct ABC *abc)\n" "{\n" " abc->a = malloc(10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5149,7 +5149,7 @@ private: " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " return &abc->self;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5158,7 +5158,7 @@ private: "{\n" " struct ABC *abc = abc1;\n" " abc->a = malloc(10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static void foo()\n" @@ -5166,7 +5166,7 @@ private: " struct ABC *abc;\n" " abc1 = abc = malloc(sizeof(ABC));\n" " abc->a = malloc(10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -5176,7 +5176,7 @@ private: " ptr = malloc(sizeof(struct msn_entry));\n" " ptr->msn = malloc(100);\n" " back = ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5185,7 +5185,7 @@ private: check("static void foo() {\n" " struct ABC *abc = malloc(123);\n" " abc->a = abc->b = malloc(10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5209,7 +5209,7 @@ private: " return 0;\n" " }\n" " return abc;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5220,7 +5220,7 @@ private: " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " func(abc);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static void foo()\n" @@ -5228,7 +5228,7 @@ private: " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abclist.push_back(abc);\n" " abc->a = malloc(10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5278,7 +5278,7 @@ private: " }\n" " free(abc->a);\n" " free(abc);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5306,7 +5306,7 @@ private: " abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5365,18 +5365,18 @@ private: // standard function.. check("void x() {\n" " strcpy(a, strdup(p));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Allocation with strdup, strcpy doesn't release it.\n", errout.str()); check("char *x() {\n" " char *ret = strcpy(malloc(10), \"abc\");\n" " return ret;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void x() {\n" " free(malloc(10));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // user function.. @@ -5385,7 +5385,7 @@ private: "\n" "void x() {\n" " set_error(strdup(p));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Allocation with strdup, set_error doesn't release it.\n", errout.str()); check("void f()\n" @@ -5393,7 +5393,7 @@ private: " int fd;\n" " fd = mkstemp(strdup(\"/tmp/file.XXXXXXXX\"));\n" " close(fd);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout.str()); } @@ -5401,7 +5401,7 @@ private: check("void x()\n" "{\n" " malloc(10);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function malloc is not used.\n", "", errout.str()); check("void *f()\n" @@ -5411,7 +5411,7 @@ private: "void x()\n" "{\n" " f();\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Return value of allocation function f is not used.\n", "", errout.str()); } }; diff --git a/test/testnonreentrantfunctions.cpp b/test/testnonreentrantfunctions.cpp index 72c43a75f..7fe8a91dd 100644 --- a/test/testnonreentrantfunctions.cpp +++ b/test/testnonreentrantfunctions.cpp @@ -61,7 +61,7 @@ private: "{\n" " char *cpwd;" " crypt(pwd, cpwd);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str()); check("void f()\n" @@ -69,14 +69,14 @@ private: " char *pwd = getpass(\"Password:\");" " char *cpwd;" " crypt(pwd, cpwd);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str()); check("int f()\n" "{\n" " int crypt = 0;" " return crypt;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -85,14 +85,14 @@ private: "{\n" " time_t t = 0;" " std::localtime(&t);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str()); // Passed as function argument check("int f()\n" "{\n" " printf(\"Magic guess: %d\n\", getpwent());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str()); // Pass return value @@ -100,35 +100,35 @@ private: "{\n" " time_t t = 0;" " struct tm *foo = localtime(&t);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str()); // Access via global namespace check("int f()\n" "{\n" " ::getpwent();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str()); // Be quiet on function definitions check("int getpwent()\n" "{\n" " return 123;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Be quiet on other namespaces check("int f()\n" "{\n" " foobar::getpwent();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Be quiet on class member functions check("int f()\n" "{\n" " foobar.getpwent();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 1453af777..293009022 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -105,7 +105,7 @@ private: "{\n" " while (tok);\n" " tok = tok->next();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", errout.str()); // #2681 @@ -133,7 +133,7 @@ private: " while (tok && tok->str() != \";\")\n" " tok = tok->next();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(Token &tok)\n" @@ -143,7 +143,7 @@ private: " while (!tok)\n" " char c = tok.read();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -154,7 +154,7 @@ private: " tok = tok->next();\n" " if( !tok ) break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -164,7 +164,7 @@ private: " while (tok && tok->str() != \";\")\n" " tok = tok->next();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(A*a)\n" @@ -179,7 +179,7 @@ private: " a->b();\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // dereference in outer scope.. @@ -222,7 +222,7 @@ private: " }\n" " else if (a->x == 2) { }\n" " if (a) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ticket #2134 - sizeof doesn't dereference @@ -266,14 +266,14 @@ private: " int a = abc->a;\n" " if (!abc)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(struct ABC *abc) {\n" " bar(abc->a);\n" " if (!abc)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(ABC *abc) {\n" @@ -297,14 +297,14 @@ private: " abc->next->a = 0;\n" " if (abc->next)\n" " ;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", "", errout.str()); check("void foo(ABC *abc) {\n" " abc->a = 0;\n" " if (abc && abc->b == 0)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str()); // ok dereferencing in a condition @@ -313,7 +313,7 @@ private: " if (abc && abc->a);\n" " if (!abc)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(struct ABC *abc) {\n" @@ -367,7 +367,7 @@ private: "out:\n" " if (!abc)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // loops.. @@ -381,7 +381,7 @@ private: " --a;\n" " }\n" " while (a > 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" @@ -393,7 +393,7 @@ private: " if (!tok)\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // dynamic_cast.. @@ -402,7 +402,7 @@ private: " int a = abc->a;\n" " if (!dynamic_cast(abc))\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #2641 - global pointer, function call @@ -486,21 +486,21 @@ private: " *p = 0;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(int *p)\n" "{\n" " *p = 0;\n" " if (p) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(int *p)\n" "{\n" " *p = 0;\n" " if (p || q) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(int *p)\n" @@ -508,7 +508,7 @@ private: " bar(*p);\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p)\n" @@ -516,14 +516,14 @@ private: " strcpy(p, \"abc\");\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p)\n" "{\n" " if (*p == 0) { }\n" " if (!p) { }\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", "", errout.str()); // no error @@ -533,7 +533,7 @@ private: " f(&p);\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -552,7 +552,7 @@ private: " *p = 0;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int x)\n" @@ -568,7 +568,7 @@ private: " int var1 = p ? *p : 0;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int *p)\n" @@ -576,7 +576,7 @@ private: " int var1 = x ? *p : 5;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); // Ticket #3125 @@ -585,7 +585,7 @@ private: " int var1 = p ? (p->a) : 0;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(ABC *p)\n" @@ -593,7 +593,7 @@ private: " int var1 = p ? (1 + p->a) : 0;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -625,7 +625,7 @@ private: " break;\n" " else\n" " p = p->next();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(Document *doc) {\n" @@ -661,7 +661,7 @@ private: " p = p->next;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(x *p)\n" @@ -669,7 +669,7 @@ private: " p = bar(p->next);\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(x *p)\n" @@ -677,7 +677,7 @@ private: " p = aa->bar(p->next);\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(x *p)\n" @@ -685,7 +685,7 @@ private: " p = *p2 = p->next;\n" " if (!p)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(struct ABC *abc)\n" @@ -693,7 +693,7 @@ private: " abc = abc ? abc->next : 0;\n" " if (!abc)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(struct ABC *abc) {\n" // #4523 @@ -711,14 +711,14 @@ private: check("int f(Item *item) {\n" " x = item ? ab(item->x) : 0;\n" " if (item) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(Item *item) {\n" " item->x = 0;\n" " a = b ? c : d;\n" " if (item) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (error) Possible null pointer dereference: item - otherwise it is redundant to check it against null.\n", errout.str()); check("BOOL GotoFlyAnchor()\n" // #2243 @@ -730,7 +730,7 @@ private: "\n" " if( !pFrm )\n" " return FALSE;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #2463 @@ -750,7 +750,7 @@ private: " break;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #2525 - sizeof @@ -796,7 +796,7 @@ private: " char c = a.c();\n" " if (!a)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -811,7 +811,7 @@ private: " else if (a == 2)\n" " p = new FooCar;\n" " p->abcd();\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n", "", errout.str()); @@ -820,21 +820,21 @@ private: " int *p = 0;\n" " int *q = p;\n" " q[0] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: q\n", errout.str()); check("static void foo()\n" "{\n" " int *p = 0;\n" " int &r = *p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str()); check("static void foo(int x)\n" "{\n" " int *p = 0;\n" " int y = 5 + *p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str()); { @@ -857,7 +857,7 @@ private: "{\n" " int *p(0);\n" " std::cout << *p;" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str()); check("void f()\n" @@ -867,14 +867,14 @@ private: " delete c;\n" " }\n" " c[0] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str()); check("static void foo()\n" "{\n" " int *p = 0;\n" " if (3 > *p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str()); check("void f()\n" @@ -883,7 +883,7 @@ private: " char *c = 0;\n" " *c = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n", errout.str()); // no false positive.. @@ -892,7 +892,7 @@ private: " Foo *p = 0;\n" " p = new Foo;\n" " p->abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static void foo()\n" @@ -901,7 +901,7 @@ private: " if (!p)\n" " return;\n" " p->abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static void foo()\n" @@ -909,7 +909,7 @@ private: " int *p = 0;\n" " exit();\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static void foo(int a)\n" @@ -917,26 +917,26 @@ private: " Foo *p = 0;\n" " if (a && p)\n" " p->do_something();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " Foo *p = 0;\n" " bool b = (p && (p->type() == 1));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" " int sz = sizeof((*(struct dummy *)0).x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void get_offset(long &offset)\n" "{\n" " mystruct * temp; temp = 0;\n" " offset = (long)(&(temp->z));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #1893 - try/catch inside else @@ -955,7 +955,7 @@ private: " }\n" " *Q=1;\n" " return Q;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int *test(int *Z)\n" @@ -971,7 +971,7 @@ private: " }\n" " *Q=1;\n" " return Q;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:12]: (error) Possible null pointer dereference: Q\n", errout.str()); // Ticket #2052 (false positive for 'else continue;') @@ -991,7 +991,7 @@ private: " void (*f)();\n" " f = 0;\n" " f();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: f\n", errout.str()); check("static void foo()\n" @@ -1000,7 +1000,7 @@ private: " int *p2 = 0;\n" " int r = *p;\n" " int r2 = *p2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n" "[test.cpp:6]: (error) Null pointer dereference\n", errout.str()); @@ -1010,7 +1010,7 @@ private: " for (int i = 0; i < 10; ++i) {\n" " int x = *p + 1;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); check("void f(int a) {\n" @@ -1078,7 +1078,7 @@ private: " for (int i = 0; i < n; i++) {\n" " argv32[i] = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // No false negative: @@ -1093,7 +1093,7 @@ private: " for (int i = 0; i < n; i++) {\n" " argv32[i] = 0;\n" " }\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); @@ -1127,13 +1127,13 @@ private: "{\n" " const char * x = 0;\n" " strdup(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str()); check("void foo()\n" "{\n" " char const * x = 0;\n" " strdup(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str()); } @@ -1142,7 +1142,7 @@ private: "{\n" " std::string * x = 0;\n" " *x = \"test\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str()); } @@ -1151,7 +1151,7 @@ private: "{\n" " struct my_type* p = 0;\n" " p->x = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); check("void foo()\n" @@ -1159,7 +1159,7 @@ private: " struct my_type* p;\n" " p = 0;\n" " p->x = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); } @@ -1168,14 +1168,14 @@ private: "{\n" " my_type* p = 0;\n" " return p->x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); check("int foo()\n" "{\n" " struct my_type* p = 0;\n" " return p->x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); check("int foo()\n" @@ -1183,7 +1183,7 @@ private: " my_type* p;\n" " p = 0;\n" " return p->x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); check("int foo()\n" @@ -1191,7 +1191,7 @@ private: " struct my_type* p;\n" " p = 0;\n" " return p->x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); } @@ -1221,7 +1221,7 @@ private: " s.d=NULL;\n" " double *pd = s.d;\n" " *pd = 10;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) Null pointer dereference\n", errout.str()); } @@ -1229,13 +1229,13 @@ private: check("void foo()\n" "{\n" " strcpy(bar, 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str()); check("void foo()\n" "{\n" " memcmp(bar(xyz()), 0, 123);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str()); check("void foo(const char *s)\n" @@ -1244,7 +1244,7 @@ private: " frexp(1.0, p);\n" " char *q = 0;\n" " frexp(1.0, q);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: q\n", errout.str()); } @@ -1358,48 +1358,48 @@ private: " if (!p) {\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" " if (NULL == p) {\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" " if (p == NULL) {\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" " if (p == NULL) {\n" " }\n" " printf(\"%c\", *p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" " if (p && *p == 0) {\n" " }\n" " printf(\"%c\", *p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" " if (p && *p == 0) {\n" " } else { *p = 0; }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" " if (p) {\n" " }\n" " strcpy(p, \"abc\");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(char *p) {\n" @@ -1407,7 +1407,7 @@ private: " }\n" " bar();\n" " strcpy(p, \"abc\");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); check("void foo(abc *p) {\n" @@ -1415,7 +1415,7 @@ private: " }\n" " else if (!p->x) {\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(char *p) {\n" @@ -1423,7 +1423,7 @@ private: " abort();\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(char *p) {\n" @@ -1439,7 +1439,7 @@ private: " (*bail)();\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(char *p) {\n" @@ -1447,7 +1447,7 @@ private: " throw x;\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(char *p) {\n" @@ -1455,7 +1455,7 @@ private: " ab.abort();\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(char *p) {\n" @@ -1487,7 +1487,7 @@ private: " if (!a) {\n" " a.x();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // This is why this check can't be used on the simplified token list @@ -1495,7 +1495,7 @@ private: " if (!dynamic_cast(foo)) {\n" " *foo = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ticket: #2300 - calling unknown function that may initialize the pointer @@ -1505,7 +1505,7 @@ private: " initfred();\n" " fred->x = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ticket #1219 @@ -1514,7 +1514,7 @@ private: " return;\n" " }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); // #2467 - unknown macro may terminate the application @@ -1618,7 +1618,7 @@ private: check("int foo(struct Fred *fred) {\n" " if (fred) { int a = 0; }\n" " return fred->a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: fred - otherwise it is redundant to check it against null.\n", errout.str()); // #2789 - assign and check pointer @@ -1626,7 +1626,7 @@ private: " char *p;\n" " if (!(p=x())) { }\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); // check, assign and use @@ -1707,7 +1707,7 @@ private: check("void f(char *s) {\n" // #3358 " if (s==0);\n" " strcpy(a, s?b:c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // sizeof @@ -1743,7 +1743,7 @@ private: check("void foo() {\n" " char *p = 0;\n" " strcpy(p, \"abcd\");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str()); // Ticket #1171 @@ -1816,7 +1816,7 @@ private: check("void f() {\n" " char *s = 0;\n" " printf(\"%s\", s == 0 ? a : s);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" diff --git a/test/testobsoletefunctions.cpp b/test/testobsoletefunctions.cpp index e4e50380e..7d93efaff 100644 --- a/test/testobsoletefunctions.cpp +++ b/test/testobsoletefunctions.cpp @@ -92,14 +92,14 @@ private: check("void f()\n" "{\n" " bsd_signal(SIGABRT, SIG_IGN);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'bsd_signal' called. It is recommended to use the function 'sigaction' instead.\n", errout.str()); check("int f()\n" "{\n" " int bsd_signal(0);\n" " return bsd_signal;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -111,7 +111,7 @@ private: " if(!hp = gethostbyname('127.0.0.1')) {\n" " exit(1);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'gethostbyname' called. It is recommended to use the function 'getaddrinfo' instead.\n", errout.str()); } @@ -123,7 +123,7 @@ private: " if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\n" " exit(1);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gethostbyaddr' called. It is recommended to use the function 'getnameinfo' instead.\n", errout.str()); } @@ -131,7 +131,7 @@ private: check("void f()\n" "{\n" " usleep( 1000 );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str()); } @@ -143,7 +143,7 @@ private: "int main()\n" "{\n" " n1::index();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::size_t f()\n" @@ -151,19 +151,19 @@ private: " std::size_t index(0);\n" " index++;\n" " return index;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f()\n" "{\n" " return this->index();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" "{\n" " int index( 0 );\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("const char f()\n" @@ -171,7 +171,7 @@ private: " const char var[6] = 'index';\n" " const char i = index(var, 0);\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n", errout.str()); } @@ -179,7 +179,7 @@ private: void test_qt_index() { check("void TDataModel::forceRowRefresh(int row) {\n" " emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n", errout.str()); } @@ -187,14 +187,14 @@ private: check("void f()\n" "{\n" " int rindex( 0 );\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" "{\n" " const char var[7] = 'rindex';\n" " print(rindex(var, 0));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'rindex' called. It is recommended to use the function 'strrchr' instead.\n", errout.str()); } @@ -204,7 +204,7 @@ private: "public:\n" " Fred() : index(0) { }\n" " int index;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -212,7 +212,7 @@ private: check("void f()\n" "{\n" " char *x = gets();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str()); check("void f()\n" @@ -246,7 +246,7 @@ private: "{\n" " int b ; b = ftime ( 1 ) ;\n" " return 0 ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -255,7 +255,7 @@ private: check("void f(char * str)\n" "{\n" " char *x = std::gets(str);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str()); } @@ -265,7 +265,7 @@ private: "{\n" " char *x = std::gets(str);\n" " usleep( 1000 );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n" "[test.cpp:4]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str()); } @@ -276,14 +276,14 @@ private: "{\n" " char s [ 10 ] ;\n" " gets ( s ) ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str()); check("int getcontext(ucontext_t *ucp);\n" "int f (ucontext_t *ucp)\n" "{\n" " getcontext ( ucp ) ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'getcontext' called. Due to portability issues, applications are recommended to be rewritten to use POSIX threads.\n", errout.str()); } @@ -293,7 +293,7 @@ private: "{\n" " char s [ 10 ] ;\n" " gets ( s ) ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testother.cpp b/test/testother.cpp index ed91edb51..cc21da010 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -360,13 +360,13 @@ private: " sum += i;\n" " }\n" " cout< [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" @@ -1564,7 +1564,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" @@ -1581,7 +1581,7 @@ private: " }\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1599,7 +1599,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1614,7 +1614,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1630,7 +1630,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1645,7 +1645,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1662,7 +1662,7 @@ private: " }\n" " bar(y);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1679,7 +1679,7 @@ private: " }\n" " bar(y);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1694,7 +1694,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" @@ -1709,7 +1709,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void bar() {}\n" // bar isn't noreturn @@ -1725,7 +1725,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" @@ -1737,7 +1737,7 @@ private: " case 3:\n" " strcpy(str, \"b'\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" @@ -1749,7 +1749,7 @@ private: " case 3:\n" " strncpy(str, \"b'\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" @@ -1764,7 +1764,7 @@ private: " strcpy(str, \"b'\");\n" " z++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (warning) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", errout.str()); check("void foo(char *str, int a)\n" @@ -1778,7 +1778,7 @@ private: " strcpy(str, \"b'\");\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(char *str, int a)\n" @@ -1791,7 +1791,7 @@ private: " case 3:\n" " strcpy(str, \"b'\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" // Ticket #4356 @@ -1813,7 +1813,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1828,7 +1828,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1841,7 +1841,7 @@ private: " ++y;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -1854,7 +1854,7 @@ private: " ++y;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -1867,7 +1867,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1882,7 +1882,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1895,7 +1895,7 @@ private: " --y;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -1908,7 +1908,7 @@ private: " --y;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -1921,7 +1921,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1936,7 +1936,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1949,7 +1949,7 @@ private: " y++;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -1962,7 +1962,7 @@ private: " y++;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -1975,7 +1975,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -1990,7 +1990,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:11]: (warning) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing?\n", errout.str()); check("void foo()\n" "{\n" @@ -2003,7 +2003,7 @@ private: " y--;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2016,7 +2016,7 @@ private: " y--;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2032,7 +2032,7 @@ private: " }\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2049,7 +2049,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2063,7 +2063,7 @@ private: " y++;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2077,7 +2077,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2093,7 +2093,7 @@ private: " }\n" " bar(y);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2109,7 +2109,7 @@ private: " }\n" " bar(y);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2123,7 +2123,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" @@ -2137,7 +2137,7 @@ private: " y = 3;\n" " }\n" " bar(y);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2153,7 +2153,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); check("void foo(int a)\n" @@ -2167,7 +2167,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); check("void foo(int a)\n" @@ -2182,7 +2182,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2197,7 +2197,7 @@ private: " y |= z;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2212,7 +2212,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2227,7 +2227,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2241,7 +2241,7 @@ private: " y &= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (warning) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing?\n", errout.str()); check("void foo(int a)\n" @@ -2256,7 +2256,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2270,7 +2270,7 @@ private: " y ^= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2284,7 +2284,7 @@ private: " y |= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2298,7 +2298,7 @@ private: " y &= 3;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2312,7 +2312,7 @@ private: " y &= 2;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2325,7 +2325,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2346,7 +2346,7 @@ private: " case 7:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2358,7 +2358,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2369,7 +2369,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2380,7 +2380,7 @@ private: " default:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2392,7 +2392,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2404,7 +2404,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2417,7 +2417,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (information) Unmatched suppression: switchCaseFallThrough\n", errout.str()); check_preprocess_suppress( @@ -2430,7 +2430,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2443,7 +2443,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2458,7 +2458,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2472,7 +2472,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2485,7 +2485,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2499,7 +2499,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2513,7 +2513,7 @@ private: " }\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Switch falls through case without comment. 'break;' missing?\n", errout.str()); check_preprocess_suppress( @@ -2523,7 +2523,7 @@ private: " case 1:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2540,7 +2540,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); // This fails because the switch parsing code currently doesn't understand // that all paths after g() actually return. It's a pretty unusual case // (no pun intended). @@ -2558,7 +2558,7 @@ private: " case 2:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( @@ -2574,7 +2574,7 @@ private: " g();\n" " return;\n" " }\n" - "}\n"); + "}"); // This fails because Tokenizer::simplifyGoto() copies the "leave:" block // into where the goto is, but because it contains a "return", it omits // copying a final return after the block. @@ -2611,13 +2611,13 @@ private: " default:\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_preprocess_suppress( "void foo() {\n" " // unrelated comment saying 'fall through'\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2629,20 +2629,20 @@ private: " continue;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("int foo(int a) {\n" " return 0;\n" " return(a-1);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("int foo(int a) {\n" " A:" " return(0);\n" " goto A;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("void foo(int a)\n" @@ -2656,7 +2656,7 @@ private: " c++;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("void foo(int a)\n" @@ -2669,7 +2669,7 @@ private: " c++;\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int a)\n" @@ -2680,7 +2680,7 @@ private: " break;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("void foo(int a)\n" @@ -2692,7 +2692,7 @@ private: " }\n" " a+=2;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str()); check("void foo(int a)\n" @@ -2703,7 +2703,7 @@ private: " }\n" " a+=2;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int foo() {\n" @@ -2977,19 +2977,19 @@ private: " int x = 1;\n" " x = x;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Redundant assignment of 'x' to itself.\n", errout.str()); check("void foo()\n" "{\n" " int x = x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'x' to itself.\n", errout.str()); check("void foo()\n" "{\n" " std::string var = var = \"test\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of 'var' to itself.\n", errout.str()); // #4073 (segmentation fault) @@ -2997,21 +2997,21 @@ private: "{\n" " if (a == 42)\n" " a = a;\n" - "}\n"); + "}"); check("void foo()\n" "{\n" " int x = 1;\n" " x = x + 1;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" " int *x = getx();\n" " *x = x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -3024,7 +3024,7 @@ private: check("void foo()\n" "{\n" " Fred fred; fred = fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" @@ -3235,7 +3235,7 @@ private: "\n" "void foo() {\n" " stat(\"file.txt\", &st);\n" - "}\n"); + "}"); ASSERT_EQUALS("",errout.str()); } @@ -4261,7 +4261,7 @@ private: " }\n" " else\n" " return true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } @@ -4279,7 +4279,7 @@ private: " }\n" " else\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } @@ -4296,7 +4296,7 @@ private: " }\n" " else\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } @@ -4321,7 +4321,7 @@ private: " }\n" " else\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } @@ -4345,7 +4345,7 @@ private: " }\n" " else\n" " return true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } @@ -4359,7 +4359,7 @@ private: " if(compare1(temp) > compare2(temp)){\n" " printf(\"foo\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("namespace Foo {\n" @@ -4371,7 +4371,7 @@ private: " if(compare1(temp) > compare2(temp)){\n" " printf(\"foo\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int compare1(int temp);\n" @@ -4383,7 +4383,7 @@ private: " printf(\"foo\");\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); check("int compare1(int temp);\n" @@ -4395,7 +4395,7 @@ private: " printf(\"foo\");\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool compare1(int temp);\n" @@ -4404,7 +4404,7 @@ private: " if(foo.compare1(temp) > compare2(temp)){\n" " printf(\"foo\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4857,11 +4857,11 @@ private: void incrementBoolean() { check("bool bValue = true;\n" - "void f() { bValue++; }\n"); + "void f() { bValue++; }"); ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); check("_Bool bValue = true;\n" - "void f() { bValue++; }\n"); + "void f() { bValue++; }"); ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); check("void f(bool test){\n" @@ -5087,7 +5087,7 @@ private: " {\n" " std::cout << \"A\";\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:7]: (style) Duplicate conditions in 'if' and related 'else if'.\n", errout.str()); } @@ -5158,7 +5158,7 @@ private: " frac = (front)/(front-back);\n" " else\n" " frac = (front)/(front-back);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f()\n" @@ -5167,7 +5167,7 @@ private: " { frac = (front)/(front-back);}\n" " else\n" " frac = (front)/(front-back);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f()\n" @@ -5176,7 +5176,7 @@ private: " { frac = (front)/(front-back);}\n" " else\n" " frac = (front)/((front-back));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); } @@ -5188,7 +5188,7 @@ private: " $;\n" " else\n" " $;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5277,7 +5277,7 @@ private: " if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\n" " ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\n" " ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5299,7 +5299,7 @@ private: " {\n" " return -1;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5362,14 +5362,14 @@ private: " A a;\n" " if (b.bar(1) && b.bar(1)) {}\n" " if (a.bar(1) && a.bar(1)) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:11]: (style) Same expression on both sides of '&&'.\n", errout.str()); check("class D { void strcmp(); };\n" "void foo() {\n" " D d;\n" " if (d.strcmp() && d.strcmp()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -5411,7 +5411,7 @@ private: void duplicateExpression6() { // #4639 check("float IsNan(float value) { return !(value == value); }\n" "double IsNan(double value) { return !(value == value); }\n" - "long double IsNan(long double value) { return !(value == value); }\n"); + "long double IsNan(long double value) { return !(value == value); }"); ASSERT_EQUALS("", errout.str()); } @@ -5543,13 +5543,13 @@ private: // Ticket #4257 check("bool foo() {\n" "MyString *str=Getter();\n" - "return *str==\"bug\"; }\n"); + "return *str==\"bug\"; }"); ASSERT_EQUALS("", errout.str()); // Ticket #4257 check("bool foo() {\n" "MyString **str=OtherGetter();\n" - "return *str==\"bug\"; }\n"); + "return *str==\"bug\"; }"); TODO_ASSERT_EQUALS("[test.cpp:2]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead?\n", "", errout.str()); @@ -5557,7 +5557,7 @@ private: // Ticket #4257 check("bool foo() {\n" "MyString str=OtherGetter2();\n" - "return &str==\"bug\"; }\n"); + "return &str==\"bug\"; }"); TODO_ASSERT_EQUALS("[test.cpp:2]: (warning) String literal compared with variable 'c'. Did you intend to use strcmp() instead?\n", "", errout.str()); @@ -5761,7 +5761,7 @@ private: "{\n" " int * pIntArray[10];\n" " memset(pIntArray, 0, sizeof(pIntArray));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -6683,7 +6683,7 @@ private: "{\n" " const A a = getA();\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (performance) Use const reference for 'a' to avoid unnecessary data copying.\n", errout.str()); check_redundant_copy("const int& getA(){static int a;return a;}\n" @@ -6691,7 +6691,7 @@ private: "{\n" " const int a = getA();\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_redundant_copy("const int& getA(){static int a;return a;}\n" @@ -6700,7 +6700,7 @@ private: " int getA = 0;\n" " const int a = getA + 3;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_redundant_copy("class A{public:A(){}};\n" @@ -6709,7 +6709,7 @@ private: "{\n" " const A a(getA());\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (performance) Use const reference for 'a' to avoid unnecessary data copying.\n", errout.str()); check_redundant_copy("const int& getA(){static int a;return a;}\n" @@ -6717,7 +6717,7 @@ private: "{\n" " const int a(getA());\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_redundant_copy("class A{\n" @@ -6729,7 +6729,7 @@ private: "{\n" " const A a = getA() + 1;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check_redundant_copy("class A{\n" @@ -6741,7 +6741,7 @@ private: "{\n" " const A a(getA()+1);\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -7183,7 +7183,7 @@ private: " {\n" " bar(c);\n" " } ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout.str()); check("void f() {\n" @@ -7192,7 +7192,7 @@ private: " {\n" " bar(c);\n" " } ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout.str()); check("void f() {\n" @@ -7201,7 +7201,7 @@ private: " {\n" " bar(c);\n" " } ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Storing getchar() return value in char variable and then comparing with EOF.\n", errout.str()); check("void f() {\n" @@ -7210,7 +7210,7 @@ private: " {\n" " bar(i);\n" " } ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -7219,7 +7219,7 @@ private: " {\n" " bar(i);\n" " } ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -7229,7 +7229,7 @@ private: "do {\n" " c = getc (pFile);\n" "} while (c != EOF)" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Storing getc() return value in char variable and then comparing with EOF.\n", errout.str()); check("voif f (FILE * pFile){\n" @@ -7237,7 +7237,7 @@ private: "do {\n" " c = getc (pFile);\n" "} while (EOF != c)" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Storing getc() return value in char variable and then comparing with EOF.\n", errout.str()); check("voif f (FILE * pFile){\n" @@ -7245,7 +7245,7 @@ private: "do {\n" " i = getc (pFile);\n" "} while (i != EOF)" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("voif f (FILE * pFile){\n" @@ -7253,7 +7253,7 @@ private: "do {\n" " i = getc (pFile);\n" "} while (EOF != i)" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -7263,7 +7263,7 @@ private: "do {\n" " c = fgetc (pFile);\n" "} while (c != EOF)" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Storing fgetc() return value in char variable and then comparing with EOF.\n", errout.str()); check("voif f (FILE * pFile){\n" @@ -7271,7 +7271,7 @@ private: "do {\n" " c = fgetc (pFile);\n" "} while (EOF != c)" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Storing fgetc() return value in char variable and then comparing with EOF.\n", errout.str()); check("voif f (FILE * pFile){\n" @@ -7279,7 +7279,7 @@ private: "do {\n" " c = fgetc (pFile);\n" "} while (EOF != c)" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("voif f (FILE * pFile){\n" @@ -7287,7 +7287,7 @@ private: "do {\n" " i = fgetc (pFile);\n" "} while (i != EOF)" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("voif f (FILE * pFile){\n" @@ -7295,7 +7295,7 @@ private: "do {\n" " i = fgetc (pFile);\n" "} while (EOF != i)" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // cin.get() diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 6723bb98c..be1093b1d 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -83,7 +83,7 @@ private: " k--;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class K {};" @@ -94,7 +94,7 @@ private: " k++;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("struct K {};" @@ -102,7 +102,7 @@ private: "{\n" " K k(0);\n" " k++;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("union K {};" @@ -110,7 +110,7 @@ private: "{\n" " K k(0);\n" " k++;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("class K {};" @@ -123,7 +123,7 @@ private: " }\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("class K {};" @@ -137,7 +137,7 @@ private: " k++;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); @@ -149,7 +149,7 @@ private: " k--;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("class K {};" @@ -160,7 +160,7 @@ private: " ++k;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class K {};" @@ -171,7 +171,7 @@ private: " --k;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -183,7 +183,7 @@ private: " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class K {};\n" @@ -193,7 +193,7 @@ private: " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("class K {};\n" @@ -203,7 +203,7 @@ private: " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class K {};\n" @@ -213,7 +213,7 @@ private: " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("class K {};\n" @@ -223,7 +223,7 @@ private: " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -237,7 +237,7 @@ private: " std::cout << k++ << std::endl;\n" " std::cout << k-- << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class K {};\n" @@ -247,7 +247,7 @@ private: " std::cout << k << std::endl;\n" " std::cout << k-- << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("class K {};\n" @@ -258,7 +258,7 @@ private: " std::cout << ++k << std::endl;\n" " std::cout << --k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -271,7 +271,7 @@ private: " k++;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("", "[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); } @@ -287,7 +287,7 @@ private: " }\n" " v.clear();\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("int main() {\n" @@ -301,7 +301,7 @@ private: " it++;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("int main() {\n" @@ -314,7 +314,7 @@ private: " it++;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); check("int main() {\n" @@ -328,14 +328,14 @@ private: " rit--;\n" " }\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); } void test2168() { check("--> declare allocator lock here\n" - "int main(){}\n"); + "int main(){}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 665359d6a..954b155a5 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1319,7 +1319,7 @@ private: "{\n" " int *n;\n" " sizeof *(n);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5537,7 +5537,7 @@ private: "{\n" " B * b = new B;\n" " b->f = new A::F * [ 10 ];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/teststl.cpp b/test/teststl.cpp index f8419aade..e6961dd84 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -158,7 +158,7 @@ private: " list l2;\n" " for (list::iterator it = l1.begin(); it != l2.end(); ++it)\n" " { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); // Same check with reverse iterator @@ -168,7 +168,7 @@ private: " list l2;\n" " for (list::const_reverse_iterator it = l1.rbegin(); it != l2.rend(); ++it)\n" " { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); } @@ -182,7 +182,7 @@ private: " {\n" " ++it;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); } @@ -193,7 +193,7 @@ private: " list l2;\n" " list::iterator it = l1.begin();\n" " l2.insert(it, 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); } @@ -207,7 +207,7 @@ private: " {\n" " result.insert(cit->size());\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -217,7 +217,7 @@ private: " std::vector ints1;\n" " std::vector ints2;\n" " std::vector::iterator it = std::find(ints1.begin(), ints2.end(), 22);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers are used together.\n", errout.str()); } @@ -229,7 +229,7 @@ private: " std::set::iterator it1 = ints1.begin();\n" " std::set::iterator it2 = ints1.end();\n" " ints2.insert(it1, it2);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(const std::set &ints1)\n" @@ -238,7 +238,7 @@ private: " std::set::iterator it1 = ints1.begin();\n" " std::set::iterator it2 = ints2.end();\n" " ints2.insert(it1, it2);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Iterators of different containers are used together.\n", "", errout.str()); } @@ -248,7 +248,7 @@ private: " std::vector ints1;\n" " std::vector ints2;\n" " std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints1.rbegin(), 5), ints2.end());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers are used together.\n", errout.str()); check("void foo()\n" @@ -256,7 +256,7 @@ private: " std::vector ints1;\n" " std::vector ints2;\n" " std::vector::iterator it = std::inplace_merge(ints1.begin(), std::advance(ints2.rbegin(), 5), ints1.end());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -266,7 +266,7 @@ private: " std::vector ints1;\n" " std::vector ints2;\n" " std::vector::iterator it = std::find_first_of(ints1.begin(), ints2.end(), ints1.begin(), ints1.end());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers are used together.\n", errout.str()); check("void foo()\n" @@ -274,7 +274,7 @@ private: " std::vector ints1;\n" " std::vector ints2;\n" " std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints1.end());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers are used together.\n", errout.str()); check("void foo()\n" @@ -290,7 +290,7 @@ private: " std::vector ints1;\n" " std::vector ints2;\n" " std::vector::iterator it = std::find_first_of(ints1.begin(), ints1.end(), ints2.begin(), ints2.end());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -308,7 +308,7 @@ private: " }\n" " ++aI;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #2481 @@ -324,7 +324,7 @@ private: " }\n" " ++aI;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Execution path checking.. @@ -343,7 +343,7 @@ private: " }\n" " ++aI;\n" " }\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.", "", errout.str()); } @@ -358,7 +358,7 @@ private: " if (true) { }\n" " if (it != s2.end()) continue;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Same iterator is used with different containers 's1' and 's2'.\n", errout.str()); } @@ -369,7 +369,7 @@ private: " vector myVector;\n" " for(vector::iterator x = myVector.begin(); x != myVector.end(); x++)\n" " myMap.erase(*x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -380,7 +380,7 @@ private: " std::map map2;\n" " std::map::const_iterator it = map1.find(123);\n" " if (it == map2.end()) { }" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Same iterator is used with different containers 'map1' and 'map2'.\n", errout.str()); check("void f(std::string &s) {\n" @@ -444,7 +444,7 @@ private: " iter = ints.begin() + 2;\n" " ints.erase(iter);\n" " std::cout << (*iter) << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str()); } @@ -461,7 +461,7 @@ private: " break;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -473,7 +473,7 @@ private: " iter = ints.begin();\n" " ints.erase(iter);\n" " std::cout << iter->first << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str()); // Reverse iterator @@ -484,7 +484,7 @@ private: " iter = ints.rbegin();\n" " ints.erase(iter);\n" " std::cout << iter->first << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str()); } @@ -497,7 +497,7 @@ private: " {\n" " foo[ii] = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) When ii==foo.size(), foo[ii] is out of bounds.\n", errout.str()); check("void foo(std::vector foo) {\n" @@ -538,7 +538,7 @@ private: " }\n" " int ii = 0;\n" " foo[ii] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -551,7 +551,7 @@ private: " {\n" " foo[ii] = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -562,7 +562,7 @@ private: " for (unsigned int ii = 0; ii <= foo.size(); ++ii)\n" " {\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -580,7 +580,7 @@ private: " foo[ii] = 0;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -607,7 +607,7 @@ private: " for (it = foo.begin(); it != foo.end(); ++it) {\n" " foo.erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Iterator 'it' used after element has been erased.\n" "[test.cpp:6] -> [test.cpp:7]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); @@ -616,7 +616,7 @@ private: " std::list::iterator i = ints.begin();\n" " i = ints.erase(i);\n" " *i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #2101 @@ -627,7 +627,7 @@ private: " if (*it % 2)\n" " it = ints[i].erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -640,7 +640,7 @@ private: " next++;\n" " foo.erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -650,7 +650,7 @@ private: " std::list::iterator it = foo.begin();\n" " foo.erase(it->a);\n" " if (it->b);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -662,7 +662,7 @@ private: " {\n" " foo.erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); check("void f()\n" @@ -672,7 +672,7 @@ private: " {\n" " foo.erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); check("void f()\n" @@ -682,7 +682,7 @@ private: " {\n" " foo.erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); check("void f()\n" @@ -692,7 +692,7 @@ private: " {\n" " foo.erase(++it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); } @@ -706,7 +706,7 @@ private: " if (*it == 123)\n" " foo.erase(it);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); } @@ -732,7 +732,7 @@ private: " if (x)" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); check("void f()\n" @@ -744,7 +744,7 @@ private: " break;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x)\n" @@ -755,7 +755,7 @@ private: " if (x)" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); } @@ -772,7 +772,7 @@ private: " continue;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -786,7 +786,7 @@ private: " foo.erase(it);\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -806,7 +806,7 @@ private: " return;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -825,7 +825,7 @@ private: " return;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" @@ -841,7 +841,7 @@ private: " *it = 0;\n" " }\n" " }\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", "", errout.str()); } @@ -854,7 +854,7 @@ private: " goto abc;\n" " }\n" "bar:\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -866,7 +866,7 @@ private: " foo.erase(it);\n" " it = foo.begin();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -884,7 +884,7 @@ private: " ++it;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -913,7 +913,7 @@ private: " iter = ints.begin() + 2;\n" " ints.erase(iter);\n" " ints.erase(iter);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Invalid iterator: iter\n", errout.str()); } @@ -925,7 +925,7 @@ private: " {\n" " foo.erase(*it);\n" " }\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\n", "", errout.str()); check("int f(std::set foo) {\n" @@ -940,7 +940,7 @@ private: " std::set foo;\n" " std::set::iterator it = foo.begin();\n" " foo.erase(*it);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -951,7 +951,7 @@ private: " std::vector::const_iterator it = foo.begin();\n" " foo.push_back(123);\n" " *it;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } @@ -964,7 +964,7 @@ private: " int *it = &foo[0];\n" " *it = 456;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -978,7 +978,7 @@ private: " {\n" " foo.push_back(123);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } @@ -990,7 +990,7 @@ private: " int *first = &ints[0];\n" " ints.push_back(2);\n" " *first;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Invalid pointer 'first' after push_back().\n", errout.str()); } @@ -1023,7 +1023,7 @@ private: " if (*it == 1)\n" " v.push_back(10);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); check("void f()\n" @@ -1036,7 +1036,7 @@ private: " if (*it == 1)\n" " v.push_back(10);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } @@ -1050,7 +1050,7 @@ private: " {\n" " foo.push_back(123);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } @@ -1066,7 +1066,7 @@ private: " {\n" " sum += *it;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) After push_back(), the iterator 'end' may be invalid.\n", errout.str()); } @@ -1086,7 +1086,7 @@ private: " a.ints.push_back(*i);\n" " ++i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1096,7 +1096,7 @@ private: " std::vector::const_iterator it = foo.begin();\n" " foo.reserve(100);\n" " *it = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) After reserve(), the iterator 'it' may be invalid.\n", errout.str()); // in loop @@ -1109,7 +1109,7 @@ private: " {\n" " foo.reserve(123);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) After reserve(), the iterator 'it' may be invalid.\n", errout.str()); } @@ -1150,7 +1150,7 @@ private: " std::vector::iterator iter = ints.begin() + 5;\n" " ints.insert(ints.begin(), 1);\n" " ++iter;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) After insert(), the iterator 'iter' may be invalid.\n", errout.str()); check("void f()\n" @@ -1158,7 +1158,7 @@ private: " std::vector ints;\n" " std::vector::iterator iter = ints.begin();\n" " ints.insert(iter, 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" @@ -1167,7 +1167,7 @@ private: " std::vector::iterator iter = ints.begin();\n" " ints.insert(iter, 1);\n" " ints.insert(iter, 2);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) After insert(), the iterator 'iter' may be invalid.\n", errout.str()); check("void* f(const std::vector& bars) {\n" @@ -1219,7 +1219,7 @@ private: " vec.insert(iter, 0);\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::vector &vec) {\n" @@ -1230,7 +1230,7 @@ private: " return;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1263,7 +1263,7 @@ private: " std::" + stlCont[i] + "::iterator it;\n" " for (it = ab.begin(); it < ab.end(); ++it)\n" " ;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous iterator comparison using operator< on 'std::" + stlCont[i] + "'.\n", errout.str()); } @@ -1282,7 +1282,7 @@ private: " std::vector::const_iterator it;\n" " for (it = files.begin(); it < files.end(); it++) { }\n" " for (it = files.begin(); it < files.end(); it++) { };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1296,7 +1296,7 @@ private: " {\n" " assert(*current < 100)\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -1360,84 +1360,84 @@ private: check("void f(std::set s)\n" "{\n" " if (s.find(12)) { }\n" - "}\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()); // error (pointer) check("void f(std::set *s)\n" "{\n" " if (*s.find(12)) { }\n" - "}\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()); // error (array-like pointer) check("void f(std::set *s)\n" "{\n" " if (s[0].find(12)) { }\n" - "}\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()); // error (array) check("void f(std::set s [10])\n" "{\n" " if (s[0].find(12)) { }\n" - "}\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()); // error (undefined length array) check("void f(std::set s [])\n" "{\n" " if (s[0].find(12)) { }\n" - "}\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()); // error (vector) check("void f(std::vector > s)\n" "{\n" " if (s[0].find(12)) { }\n" - "}\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()); // ok (simple) check("void f(std::set s)\n" "{\n" " if (s.find(123) != s.end()) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ok (pointer) check("void f(std::set *s)\n" "{\n" " if (*s.find(12) != s.end()) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ok (array-like pointer) check("void f(std::set *s)\n" "{\n" " if (s[0].find(12) != s.end()) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ok (array) check("void f(std::set s [10])\n" "{\n" " if (s[0].find(123) != s.end()) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ok (undefined length array) check("void f(std::set s [])\n" "{\n" " if (s[0].find(123) != s.end()) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ok (vector) check("void f(std::vector > s)\n" "{\n" " if (s[0].find(123) != s.end()) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -1449,14 +1449,14 @@ private: check("void f()\n" "{\n" " if (std::find(a,b,c)) { }\n" - "}\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()); // ok check("void f()\n" "{\n" " if (std::find(a,b,c) != c) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #3714 - segmentation fault for syntax error @@ -1467,7 +1467,7 @@ private: // #3865 check("void f() {\n" " if ((std::find(a,b,c)) != b) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1476,21 +1476,21 @@ private: check("void f(const std::string &s)\n" "{\n" " if (s.find(\"abc\")) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::compare() would be faster.\n", errout.str()); // error (pointer) check("void f(const std::string *s)\n" "{\n" " if (*s.find(\"abc\")) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::compare() would be faster.\n", errout.str()); // error (vector) check("void f(const std::vector &s)\n" "{\n" " if (s[0].find(\"abc\")) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find() in condition; string::compare() would be faster.\n", errout.str()); // #3162 @@ -1521,119 +1521,119 @@ private: "void Fred::foo()\n" "{\n" " if (x.size() == 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("std::list x;\n" "void f()\n" "{\n" " if (x.size() == 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() == 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (0 == x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() != 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (0 != x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() > 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (0 < x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() >= 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size() < 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (1 <= x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (1 > x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " if (!x.size()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " fun(x.size());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " fun(!x.size());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f()\n" "{\n" " std::list x;\n" " fun(a && x.size());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("void f() {\n" // #4039 @@ -1660,7 +1660,7 @@ private: "{\n" " if (haystack.find(needle) != haystack.end())\n" " haystack.remove(needle);" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant checking of STL container element existence before removing it.\n", errout.str()); } @@ -1675,7 +1675,7 @@ private: "void Wilma::foo()\n" "{\n" " if (f.x.size() == 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); } @@ -1690,7 +1690,7 @@ private: "Zzz * zzz;\n" "int main() {\n" " if (zzz->x.size() > 0) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); check("namespace N {\n" @@ -1703,7 +1703,7 @@ private: "int main() {\n" " Zzz * zzz;\n" " if (zzz->x.size() > 0) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); } @@ -1726,7 +1726,7 @@ private: " {\n" " haystack.remove(needle);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant checking of STL container element existence before removing it.\n", errout.str()); } @@ -1737,14 +1737,14 @@ private: " it++;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Missing bounds check for extra iterator increment in loop.\n", errout.str()); check("void f(std::map &ints) {\n" " for (std::map::iterator it = ints.begin(); it != ints.end(); ++it) {\n" " ++it->second;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1757,7 +1757,7 @@ private: " return;\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1767,7 +1767,7 @@ private: " for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\n" " { }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1982,7 +1982,7 @@ private: "const char *f()\n" "{\n" " return hello().c_str();\n" - "}\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()); check("class Fred {\n" @@ -1996,7 +1996,7 @@ private: "const char *Fred::f()\n" "{\n" " return hello().c_str();\n" - "}\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()); // #4183 - using MyStringClass.c_str() @@ -2017,7 +2017,7 @@ private: " std::vector vec;\n" " vec.push_back(new int(3));\n" " std::auto_ptr ret(vec[0]);\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); // ticket 2839 @@ -2029,32 +2029,32 @@ private: "};\n" "class SafeSharedMemory : public Guarded\n" "{\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" " auto_ptr< ns1:::MyClass > y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f()\n" "{\n" " auto_ptr p2;\n" " p2 = new T;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo()\n" "{\n" " std::vector< std::auto_ptr< ns1::MyClass> > v;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) You can randomly lose access to pointers if you store 'auto_ptr' pointers in an STL container.\n", errout.str()); check("void foo()\n" "{\n" " std::vector< auto_ptr< MyClass> > v;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) You can randomly lose access to pointers if you store 'auto_ptr' pointers in an STL container.\n", errout.str()); check("void foo()\n" @@ -2063,7 +2063,7 @@ private: " auto_ptr x(i);\n" " auto_ptr y;\n" " y = x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Copying 'auto_ptr' pointer to another does not create two equal objects since one has lost its ownership of the pointer.\n", errout.str()); check("std::auto_ptr function();\n" @@ -2077,78 +2077,78 @@ private: "{\n" " T* var = new T[10];\n" " auto_ptr p2( var );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " foo::bar::baz* var = new foo::bar::baz[10];\n" " auto_ptr p2( var );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2( new T[] );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2( new T[5] );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p(new foo::bar[10]);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2;\n" " p2.reset( new T[] );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2( new T[][] );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2;\n" " p2 = new T[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2;\n" " p2 = new T::B[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2;\n" " p2.reset( new T[10] );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); check("void f()\n" "{\n" " auto_ptr p2;\n" " p2.reset( new T::B[10] );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); // ticket #2887 (infinite loop) - check("A::A(std::auto_ptr e){}\n"); + check("A::A(std::auto_ptr e){}"); ASSERT_EQUALS("", errout.str()); // ticket #2967 (segmentation fault) @@ -2162,7 +2162,7 @@ private: " string s1, s2;\n" " s1.swap(s2);\n" " s2.swap(s2);\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)'\n", errout.str()); check("void f()\n" @@ -2172,7 +2172,7 @@ private: " s2.compare(s2);\n" " s1.compare(s2.c_str());\n" " s1.compare(0, s1.size(), s1);\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:5]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0.\n", errout.str()); check("void f()\n" @@ -2184,7 +2184,7 @@ private: " s1 = s2.substr(0, x);\n" " s1 = s2.substr(0,std::string::npos);\n" " s1 = s2.substr(x+5-n, 0);\n" - "};\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 " @@ -2219,7 +2219,7 @@ private: " x = std::remove(a.begin(), a.end(), val);\n" " a.erase(std::remove(a.begin(), a.end(), val));\n" " std::remove(\"foo.txt\");\n" - "}\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()); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 2e77f801c..939450349 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -966,7 +966,7 @@ private: " class X { X(int); };\n" " }\n" "}\n" - "namespace barney { X::X(int) { } }\n"); + "namespace barney { X::X(int) { } }"); // Locate the scope for the class.. const Scope *scope = NULL; @@ -1000,7 +1000,7 @@ private: " namespace barney {\n" " X::X(int) { }\n" " }\n" - "}\n"); + "}"); // Locate the scope for the class.. const Scope *scope = NULL; @@ -1026,7 +1026,7 @@ private: void namespaces3() { // #3854 - namespace with unknown macro GET_SYMBOL_DB("namespace fred UNKNOWN_MACRO(default) {\n" - "}\n"); + "}"); ASSERT_EQUALS(2U, db->scopeList.size()); ASSERT_EQUALS(Scope::eGlobal, db->scopeList.front().type); ASSERT_EQUALS(Scope::eNamespace, db->scopeList.back().type); @@ -1039,7 +1039,7 @@ private: " catch (const X::Error2 & x) { }\n" " catch (Error3 x) { }\n" " catch (X::Error4 x) { }\n" - "}\n"); + "}"); GET_SYMBOL_DB(str.c_str()) check(str.c_str(), false); ASSERT_EQUALS("", errout.str()); @@ -1077,7 +1077,7 @@ private: check("typedef void (func_type)();\n" "struct A {\n" " friend func_type f : 2;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1088,7 +1088,7 @@ private: "static void function_declaration_after(void) __attribute__((__used__));\n"); ASSERT_EQUALS("", errout.str()); - check("main(int argc, char *argv[]) { }\n"); + check("main(int argc, char *argv[]) { }"); ASSERT_EQUALS("", errout.str()); check("namespace boost {\n" @@ -1096,7 +1096,7 @@ private: " {\n" " return std::locale();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("namespace X {\n" @@ -1104,12 +1104,12 @@ private: " static void function_declaration_before(void) {}\n" " static void function_declaration_after(void) {}\n" " static void function_declaration_after(void) __attribute__((__used__));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("testing::testing()\n" "{\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1117,7 +1117,7 @@ private: // ticket #2178 - segmentation fault check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n" " return (sign ? cl_I() : 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1144,7 +1144,7 @@ private: "{\n" "public:\n" " int f() { return C< ::D,int>::f(); }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1157,7 +1157,7 @@ private: " {\n" " return vcl::unotools::createStandardColorSpace();\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1184,7 +1184,7 @@ private: "};\n" "class B {\n" " friend void A::f();\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1194,7 +1194,7 @@ private: check("int g ();\n" "struct S {\n" " int i : (false ? g () : 1);\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1203,7 +1203,7 @@ private: // ticket #2547 - segmentation fault check("class foo {\n" " void bar2 () = __null;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1212,7 +1212,7 @@ private: // ticket #2577 - segmentation fault check("class foo {\n" " void bar2 () = A::f;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1240,7 +1240,7 @@ private: void symboldatabase17() { // ticket #2657 - segmentation fault - check("return f(){}\n"); + check("return f(){}"); ASSERT_EQUALS("", errout.str()); } @@ -1254,7 +1254,7 @@ private: void symboldatabase19() { // ticket #2991 - segmentation fault - check("::y(){x}\n"); + check("::y(){x}"); ASSERT_EQUALS("", errout.str()); } @@ -1273,7 +1273,7 @@ private: "};\n" "Fred::func() const {\n" " Foo foo;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1287,7 +1287,7 @@ private: // #ticket 3435 (std::vector) void symboldatabase23() { - GET_SYMBOL_DB("class A { std::vector ints; };\n"); + GET_SYMBOL_DB("class A { std::vector ints; };"); ASSERT_EQUALS(2U, db->scopeList.size()); const Scope &scope = db->scopeList.back(); ASSERT_EQUALS(1U, scope.varlist.size()); @@ -1367,7 +1367,7 @@ private: "{\n" " B1()\n" " {} C(int) : B1() class\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index d8abfd897..2bd0cc228 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -87,25 +87,25 @@ private: checkUninitVar("void foo() {\n" " int a;\n" " b = c - a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("void foo() {\n" " int a;\n" " b = a - c;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("void foo() {\n" " int *p;\n" " realloc(p,10);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("void foo() {\n" " int *p = NULL;\n" " realloc(p,10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // dereferencing uninitialized pointer.. @@ -113,132 +113,132 @@ private: "{\n" " Foo *p;\n" " p->abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " Foo *p;\n" " p->abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("void f(Foo *p)\n" "{\n" " int a;\n" " p->a = malloc(4 * a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " delete p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " delete [] p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " *p = 135;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int *p;\n" " p[0] = 135;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int *x;\n" " int y = *x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int *x;\n" " int &y(*x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar("void foo()\n" "{\n" " int x;\n" " int *y = &x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " int *x;\n" " int *&y = x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " int x = xyz::x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" "{\n" " int a;\n" " a = 5 + a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("void f()\n" "{\n" " int a;\n" " a++;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("void f()\n" "{\n" " extern int a;\n" " a++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" "{\n" " int a;\n" " bar(4 * a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int i;\n" " if (i);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int i;\n" " for (int x = 0; i < 10; x++);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar("static void foo()\n" "{\n" " int i;\n" " for (int x = 0; x < 10; i++);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar("static int foo(int x)\n" @@ -247,7 +247,7 @@ private: " if (x)\n" " i = 0;\n" " i++;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar("static void foo()\n" @@ -255,7 +255,7 @@ private: " int ar[10];\n" " int i;\n" " ar[i] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar("static void foo()\n" @@ -263,7 +263,7 @@ private: " int x, y;\n" " x = (y = 10);\n" " int z = y * 2;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #3597 @@ -271,27 +271,27 @@ private: " int a;\n" " int b = 1;\n" " (b += a) = 1;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n","", errout.str()); checkUninitVar("int f() {\n" " int a,b,c;\n" " a = b = c;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n", "", errout.str()); checkUninitVar("static void foo()\n" "{\n" " Foo p;\n" " p.abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("static void foo()\n" "{\n" " Foo p;\n" " int x = p.abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Unknown types @@ -300,7 +300,7 @@ private: "{\n" " A ret;\n" " return ret;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void a()\n" @@ -324,7 +324,7 @@ private: "{\n" " int x[10];\n" " int *y = x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void a()\n" @@ -333,7 +333,7 @@ private: " int *y = &x;\n" " *y = 0;\n" " x++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void a()\n" @@ -342,7 +342,7 @@ private: " char *z = x;\n" " memset(z, 0, sizeof(x));\n" " memcpy(y, x, sizeof(x));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Handling >> and << @@ -351,7 +351,7 @@ private: " int ret;\n" " std::cin >> ret;\n" " ret++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int a() {\n" @@ -366,14 +366,14 @@ private: " Node node;\n" " int x;\n" " node[\"abcd\"] >> x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int a(FArchive &arc) {\n" // #3060 (initialization through operator<<) " int *p;\n" " arc << p;\n" " return *p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int a() {\n" @@ -389,7 +389,7 @@ private: " int a;\n" " a << 1;\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -397,21 +397,21 @@ private: " int x;\n" " asm();\n" " x++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void a()\n" "{\n" " int x[10];\n" " struct xyz xyz1 = { .x = x };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void a()\n" "{\n" " struct S *s;\n" " s->x = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str()); checkUninitVar("void a()\n" @@ -419,7 +419,7 @@ private: " struct S *s;\n" " FOREACH() { }\n" " s->x = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s\n", errout.str()); checkUninitVar("void a()\n" @@ -428,7 +428,7 @@ private: " struct S *s2;\n" " FOREACH(s1) { }\n" " s2->x = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s2\n", errout.str()); // #1533 @@ -438,14 +438,14 @@ private: " struct A msg = { .buf = {&key} };\n" " init(&msg);\n" " key++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " char *buf = malloc(100);\n" " struct ABC *abc = buf;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("class Fred {\n" @@ -456,7 +456,7 @@ private: "Fred::~Fred()\n" "{\n" " fclose(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -464,7 +464,7 @@ private: " int c;\n" " ab(sizeof(xyz), &c);\n" " if (c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -472,7 +472,7 @@ private: " int c;\n" " a = (f2(&c));\n" " c++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f(int a)\n" @@ -481,7 +481,7 @@ private: " char *p;\n" " *p = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: p\n", errout.str()); // += @@ -489,21 +489,21 @@ private: "{\n" " int c;\n" " c += 2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str()); checkUninitVar("void f()\n" "{\n" " char *s = malloc(100);\n" " *s += 10;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory is allocated but not initialized: s\n", errout.str()); checkUninitVar("void f()\n" "{\n" " int a[10];\n" " a[0] = 10 - a[1];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); // goto/setjmp/longjmp.. @@ -519,7 +519,7 @@ private: "\n" "found:\n" " int a = b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int foo()\n" @@ -531,7 +531,7 @@ private: " return a;\n" " a = 1;\n" " longjmp(env, 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // macro_for.. @@ -545,7 +545,7 @@ private: " else\n" " retval = 2;\n" " return retval;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int foo()\n" @@ -554,14 +554,14 @@ private: " goto exit;\n" " i++;\n" "exit:\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #3480 - Don't crash garbage code checkUninitVar("int f()\n" "{\n" " return if\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) syntax error\n", errout.str()); // Ticket #3873 (false positive) @@ -570,7 +570,7 @@ private: " if (!Range)\n" " Range = new MachineLoopRange(Loop, Allocator, *Indexes);\n" " return Range;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #4040 - False positive @@ -603,7 +603,7 @@ private: " _Bit_reference(_Bit_type * __x, _Bit_type __y)\n" " : _M_p(__x), _M_mask(__y) { }\n" " };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -611,13 +611,13 @@ private: checkUninitVar("void foo() {\n" " int b;\n" " c = a | b;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout.str()); checkUninitVar("void foo() {\n" " int b;\n" " c = b | a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout.str()); } @@ -629,7 +629,7 @@ private: " if (x)\n" " p = new Foo;\n" " p->abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("static void foo(int x)\n" @@ -638,7 +638,7 @@ private: " if (x==1);\n" " if (x==2);\n" " x = a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("int foo()\n" @@ -649,7 +649,7 @@ private: " else\n" " i = 33;\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int foo()\n" @@ -663,7 +663,7 @@ private: " i = 33;\n" " }\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int foo()\n" @@ -679,7 +679,7 @@ private: " i = 33;\n" " }\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("static void foo(int x)\n" @@ -689,7 +689,7 @@ private: " p = new Foo;\n" " if (x)\n" " p->abcd();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo(int a)\n" @@ -707,7 +707,7 @@ private: " if( n == 0) {\n" " a=condition;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -715,7 +715,7 @@ private: " C *c;\n" " if (fun(&c));\n" " c->Release();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f() {\n" @@ -732,7 +732,7 @@ private: " else\n" " return 3;\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #2207 - False positive @@ -743,7 +743,7 @@ private: " if (!x)\n" " return;\n" " b = (c - a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int foo()\n" @@ -754,7 +754,7 @@ private: " else\n" " throw 3;\n" " return ret;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int f(int a)\n" @@ -765,7 +765,7 @@ private: " else\n" " XYZ ret = 2;\n" // XYZ may be an unexpanded macro so bailout the checking of "ret". " return ret;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int f(int a, int b)\n" @@ -778,7 +778,7 @@ private: " x = b;\n" " }\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo(long verbose,bool bFlag)\n" @@ -791,7 +791,7 @@ private: " if (verbose)\n" " std::cout << (12-t);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int test(int cond1, int cond2) {\n" @@ -803,7 +803,7 @@ private: " if (cond2) {\n" " int t = foo*foo;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // ? : @@ -811,7 +811,7 @@ private: "{\n" " int x;\n" " x = v <= 0 ? -1 : x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar("void foo()\n" @@ -823,14 +823,14 @@ private: " }\n" " ret = ret <= 0 ? -1 :\n" " strcmp(msgid1, msgid2) == 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo(int a, int b)\n" "{\n" " int x; x = (afoo();\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" "{\n" " Fred *fred = malloc(sizeof(Fred));\n" " x(&fred->f);\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" "{\n" " Fred *fred = malloc(sizeof(Fred));\n" " x(fred->f);\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo(char *s)\n" "{\n" " char *a = malloc(100);\n" " *a = *s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " char *a;\n" " if (a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar("void foo()\n" "{\n" " char *a = malloc(100);\n" " if (a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " ABC *abc = malloc(100);\n" " abc->a = 123;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " ABC *abc = malloc(100);\n" " abc->a.word = 123;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" @@ -1403,14 +1403,14 @@ private: " ABC *abc = malloc(100);\n" " abc->a = 123;\n" " abc->a += 123;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " ABC *abc = malloc(100);\n" " free(abc);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -1419,14 +1419,14 @@ private: " if (!s)\n" " return;\n" " char c = *s;\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (error) Memory is allocated but not initialized: s\n", errout.str()); // #3708 - false positive when using ptr typedef checkUninitVar("void f() {\n" " uintptr_t x = malloc(100);\n" " uintptr_t y = x + 10;\n" // <- not bad usage - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1436,7 +1436,7 @@ private: "{\n" " int i;\n" " int a() { return i; }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -1447,7 +1447,7 @@ private: " surface->MoveTo();\n" " }\n" " };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -1456,7 +1456,7 @@ private: " int a,b;\n" " int get_a() { return a; }" " } = { 0, 0 };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -1469,13 +1469,13 @@ private: " i = 0;\n" " }\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f(int x) {\n" " struct AB ab;\n" " x = ab.x = 12;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1486,7 +1486,7 @@ private: " enum AB { a, b };\n" " AB ab;\n" " if (ab);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab\n", errout.str()); } @@ -1498,7 +1498,7 @@ private: " int &b = a;\n" " b = 0;\n" " int x = a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f(struct blame_entry *ent)\n" @@ -1506,14 +1506,14 @@ private: " struct origin *suspect = ent->suspect;\n" " char hex[41];\n" " strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " const std::string s(x());\n" " strchr(s.c_str(), ',');\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1523,27 +1523,27 @@ private: "{\n" " int ret;\n" " return ret;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ret\n", errout.str()); checkUninitVar("static int foo()\n" "{\n" " int ret;\n" " return ret+5;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ret\n", errout.str()); checkUninitVar("static int foo() {\n" " int ret;\n" " return ret = 5;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); { checkUninitVar("static int foo() {\n" " int ret;\n" " return cin >> ret;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("static int foo() {\n" @@ -1557,7 +1557,7 @@ private: checkUninitVar("int f(int x) {\n" " int y;\n" " return x ? 1 : y;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: y\n", errout.str()); // Ticket #3106 - False positive @@ -1565,13 +1565,13 @@ private: checkUninitVar("int f() {\n" " int i;\n" " return x(&i) ? i : 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int f() {\n" " int i;\n" " return x() ? i : 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout.str()); } @@ -1584,7 +1584,7 @@ private: " char a[100];\n" " strncpy(a, s, 20);\n" " strncat(a, s, 20);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\n", errout.str()); checkUninitVar("void f()\n" @@ -1592,7 +1592,7 @@ private: " char a[100];\n" " strncpy(a, \"hello\", 3);\n" " strncat(a, \"world\", 20);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\n", errout.str()); checkUninitVar("void f()\n" @@ -1600,7 +1600,7 @@ private: " char a[100];\n" " strncpy(a, \"hello\", sizeof(a));\n" " strncat(a, \"world\", 20);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #3245 - false positive @@ -1625,7 +1625,7 @@ private: " char buf[10];\n" " strncpy(buf, dev, 10);\n" " strncpy(str, buf, 10);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1635,7 +1635,7 @@ private: " char a[20];\n" " memset(a, 'a', 20);\n" " strcat(a, s);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of 'a' (not null-terminated).\n", errout.str()); } @@ -1644,7 +1644,7 @@ private: " int a[20];\n" " memset(a, 1, 20);\n" " a[0] |= 2;\n" - "}\n"); + "}"); ASSERT_EQUALS(errout.str(), ""); } @@ -1692,7 +1692,7 @@ private: " int i;\n" " assignOne(i);\n" " return i;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int f(int (*assign)(int *p))\n" @@ -1700,28 +1700,28 @@ private: " int i;\n" " (*assign)(&i);\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int f()\n" "{\n" " char s[10];\n" " return bar(s);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" "{\n" " FILE *f;\n" " fflush(f);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str()); checkUninitVar("void f()\n" "{\n" " int i;\n" " x(i+2);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar("void f()\n" @@ -1729,7 +1729,7 @@ private: " char *p = malloc(10);\n" " read(p + 1);\n" " return p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f()\n" @@ -1743,14 +1743,14 @@ private: "{\n" " Foo *p;\n" " x = bar(sizeof(*p));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void foo()\n" "{\n" " Foo *p;\n" " x = bar(p->begin());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("int foo(int x) { return x; }\n" @@ -1758,28 +1758,28 @@ private: "{\n" " int x;\n" " foo(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar("void foo(const char *s)\n" "{\n" " char *p;\n" " memcpy(p, s, 100);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar("void foo(const char *s)\n" "{\n" " char *p = malloc(100);\n" " memcpy(p, s, 100);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("int calc(const int *p, int n);\n" "void f() {\n" " int x[10];\n" " calc(x,10);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", "", errout.str()); @@ -1788,7 +1788,7 @@ private: " int x;\n" " INIT(x);\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #3222 - calling function through function pointer @@ -1802,7 +1802,7 @@ private: checkUninitVar("void f() {\n" // #3586 - calling template function " int i;\n" " a::b(i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // using uninitialized function pointer.. @@ -1810,7 +1810,7 @@ private: "{\n" " void (*f)();\n" " f();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str()); // calling noreturn function.. @@ -1840,13 +1840,13 @@ private: " char cmd[10];\n" " init(cmd);\n" " return cmd[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("char fn(FILE *f) {\n" " char buf[10];\n" " fread(buf, 1, 10, f);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #2775 - uninitialized struct pointer in subfunction @@ -1857,7 +1857,7 @@ private: "void b() {\n" " struct Fred *p;\n" " a(p);\n" - "}\n"); + "}"); // TODO: See #2946 TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: p\n", "", errout.str()); @@ -1888,34 +1888,34 @@ private: // valid and invalid use of 'int a(int x) { return x + x; }' void func_uninit_var() { - const std::string funca("int a(int x) { return x + x; }\n"); + const std::string funca("int a(int x) { return x + x; }"); checkUninitVar((funca + "void b() {\n" " int x;\n" " a(x);\n" "}").c_str()); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar((funca + "void b() {\n" " int *p;\n" " a(*p);\n" "}").c_str()); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str()); } // valid and invalid use of 'void a(int *p) { *p = 0; }' void func_uninit_pointer() { - const std::string funca("void a(int *p) { *p = 0; }\n"); + const std::string funca("void a(int *p) { *p = 0; }"); // ok - initialized pointer checkUninitVar((funca + "void b() {\n" " int buf[10];\n" " a(buf);\n" - "}\n").c_str()); + "}").c_str()); ASSERT_EQUALS("", errout.str()); // not ok - uninitialized pointer @@ -1923,27 +1923,27 @@ private: "void b() {\n" " int *p;\n" " a(p);\n" - "}\n").c_str()); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); + "}").c_str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str()); } void uninitvar_typeof() { checkUninitVar("void f() {\n" " struct Fred *fred;\n" " typeof(fred->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f() {\n" " struct SData * s;\n" " ab(typeof(s->status));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("void f() {\n" " struct SData * s;\n" " TYPEOF(s->status);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2065,7 +2065,7 @@ private: checkUninitVar2("void f() {\n" " int i, i2;\n" " strm >> i >> i2;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // unconditional initialization @@ -2083,7 +2083,7 @@ private: " if (y == 1) { x = 1; }\n" " else if (y == 2) { x = 1; }\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar2("void f() {\n" @@ -2092,7 +2092,7 @@ private: " else if (y == 2) { x = 1; }\n" " if (y == 3) { }\n" // <- ignore condition " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: x\n", errout.str()); // initialization in condition @@ -2100,7 +2100,7 @@ private: " int a;\n" " if (init(&a)) { }\n" " a++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // return, break, continue, goto @@ -2109,14 +2109,14 @@ private: " if (y == 1) { return; }\n" " else { x = 1; }\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f() {\n" " int x;\n" " if (y == 1) { return; }\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar2("void f() {\n" @@ -2124,7 +2124,7 @@ private: " return;\n" "err:\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("int f(int x) {\n" @@ -2156,7 +2156,7 @@ private: " for (i=0;i<9;++i)\n" " if (foo) break;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar2("int f() {\n" @@ -2164,7 +2164,7 @@ private: " while (foo)\n" " if (bar) break;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str()); // try @@ -2180,7 +2180,7 @@ private: " if (y == 1) { exit(0); }\n" " else { x = 1; }\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // strange code.. don't crash (#3415) @@ -2216,34 +2216,34 @@ private: " if (x) { }\n" " else if (y==2) { a=1; b=2; }\n" " if (a) { ++b; }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("static void f(int x, int y) {\n" " int a;\n" " if (x == 0) { a = y; }\n" " if (x == 0 && (a == 1)) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("static void f(int x, int y) {\n" " int a;\n" " if (x == 0 && (a == 1)) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); checkUninitVar2("void f() {\n" " int a;\n" " if (x) { a = 0; }\n" " if (x) { if (y) { a++; } }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f() {\n" " int a;\n" " if (x) { a = 0; }\n" " if (x) { if (y) { } else { a++; } }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("struct AB { int a; int b; };\n" @@ -2273,7 +2273,7 @@ private: " if (x) y = 123;\n" // <- y is always initialized " else y = 456;\n" " return y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // asm @@ -2322,20 +2322,20 @@ private: " x;\n" " int a, a2, a2*x; if () ;\n" " )\n" - "}\n"); + "}"); // Ticket #3890 - False positive for std::map checkUninitVar2("void f() {\n" " std::map x;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Ticket #3906 - False positive for std::vector pointer checkUninitVar2("void f() {\n" " std::vector *x = NULL;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // & @@ -2383,7 +2383,7 @@ private: checkUninitVar2("void f() {\n" " int a;\n" " a << 1;\n" // there might be a operator<< - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2511,7 +2511,7 @@ private: " if (y != 0) return;\n" " i++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f() {\n" @@ -2521,7 +2521,7 @@ private: " if (y != 0) return;\n" " i++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f() {\n" @@ -2530,21 +2530,21 @@ private: " else y = get_value(i);\n" " if (y != 0) return;\n" // <- condition is always true if i is uninitialized " i++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f(int x) {\n" " int i;\n" " if (!x) i = 0;\n" " if (!x || i>0) {}\n" // <- error - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar2("void f(int x) {\n" " int i;\n" " if (x) i = 0;\n" " if (!x || i>0) {}\n" // <- no error - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f(int x) {\n" @@ -2552,7 +2552,7 @@ private: " if (!x) { }\n" " else i = 0;\n" " if (x || i>0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: i\n", errout.str()); checkUninitVar2("void f(int x) {\n" @@ -2560,7 +2560,7 @@ private: " if (x) { }\n" " else i = 0;\n" " if (x || i>0) {}\n" // <- no error - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Unknown => bail out.. @@ -2569,7 +2569,7 @@ private: " if (a(x)) i = 0;\n" " if (b(x)) return;\n" " i++;\n" // <- no error if b(x) is always true when a(x) is false - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2578,7 +2578,7 @@ private: "void f(void) {\n" " struct AB ab;\n" " int a = ab.a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout.str()); checkUninitVar2("struct AB { int a; int b; };\n" @@ -2717,7 +2717,7 @@ private: " while (a) {\n" " x = x + 1;\n" " }\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); checkUninitVar2("void f() {\n" @@ -2726,7 +2726,7 @@ private: " if (b) x++;\n" " else x = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f() {\n" @@ -2734,13 +2734,13 @@ private: " for (int i = 0; i < 10; i += x) {\n" " x = y;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f() {\n" " int x;\n" " for (int i = 0; i < 10; i += x) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar2("int f() {\n" @@ -2749,7 +2749,7 @@ private: " if (foo()) goto out;\n" "out:\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2(">{ x while (y) z int = }"); // #4175 : don't crash @@ -2772,7 +2772,7 @@ private: " int a = x+1;\n" " do_something(a);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); checkUninitVar2("struct AB {int a; int b;};\n" @@ -2793,7 +2793,7 @@ private: " for (int i=0;i<10;i++)\n" " buffer[i] = 0;\n" // <- fp " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar2("void f(){\n" // #4519 - fp: inline assembler in loop @@ -2827,7 +2827,7 @@ private: " void ff(void) { char *p; ::N1::Fred::f2(p); }\n" " void fg(void) { char *p; Foo::f1(p); }\n" " void fh(void) { char *p; Foo::f2(p); }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: p\n" "[test.cpp:8]: (error) Uninitialized variable: p\n" "[test.cpp:13]: (error) Uninitialized variable: p\n" @@ -2842,7 +2842,7 @@ private: "void f(void) {\n" " char *p;\n" " fred.f1(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: p\n", errout.str()); checkUninitVar2("class Fred {\n" @@ -2865,7 +2865,7 @@ private: "void f(void) {\n" " char *p;\n" " fred.wilma.barney.betty.f1(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:20]: (error) Uninitialized variable: p\n", errout.str()); } }; diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index e22d45f77..4981d708b 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -78,7 +78,7 @@ private: "{\n" " if (f1())\n" " { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -86,7 +86,7 @@ private: check("int f1()\n" "{\n" " return f1();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -94,7 +94,7 @@ private: check("char * foo()\n" "{\n" " return *foo();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -102,7 +102,7 @@ private: check("void f1()\n" "{\n" " void (*f)() = cond ? f1 : NULL;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -111,7 +111,7 @@ private: "{\n" " if (cond) ;\n" " else f1();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -124,7 +124,7 @@ private: "{\n" " f(&abc::foo);\n" " return 0\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("namespace abc {\n" @@ -135,7 +135,7 @@ private: "{\n" " f = &abc::foo;\n" " return 0\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("namespace abc {\n" // #3875 @@ -146,7 +146,7 @@ private: "{\n" " f(abc::foo);\n" " return 0\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -157,7 +157,7 @@ private: "{\n" " foo();\n" " return 0\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -167,12 +167,12 @@ private: "template void g()\n" "{\n" " f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void throwIsNotAFunction() { - check("struct A {void f() const throw () {}}; int main() {A a; a.f();}\n"); + check("struct A {void f() const throw () {}}; int main() {A a; a.f();}"); ASSERT_EQUALS("", errout.str()); } @@ -195,20 +195,20 @@ private: } void unusedMain() { - check("int main() { }\n"); + check("int main() { }"); ASSERT_EQUALS("", errout.str()); - check("int _tmain() { }\n"); + check("int _tmain() { }"); ASSERT_EQUALS("", errout.str()); - check("int WinMain() { }\n"); + check("int WinMain() { }"); ASSERT_EQUALS("", errout.str()); } void initializationIsNotAFunction() { check("struct B: N::A {\n" " B(): N::A() {};\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 63e768880..ba97d78fd 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -106,7 +106,7 @@ private: "{ }\n" "\n" "unsigned int Fred::f()\n" - "{ }\n"); + "{ }"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function: 'Fred::f'\n", errout.str()); @@ -124,7 +124,7 @@ private: "{ }\n" "\n" "unsigned int Fred::f()\n" - "{ }\n"); + "{ }"); ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str()); @@ -140,7 +140,7 @@ private: "\n" "void Fred::f()\n" "{\n" - "}\n"); + "}"); ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str()); // Don't warn about include files which implementation we don't see @@ -156,7 +156,7 @@ private: "\n" "int main()\n" "{\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -174,7 +174,7 @@ private: "};\n" "\n" "A::A()\n" - "{ }\n"); + "{ }"); ASSERT_EQUALS("", errout.str()); } @@ -189,7 +189,7 @@ private: "};\n" "\n" "A::~A()\n" - "{ B(); }\n"); + "{ B(); }"); ASSERT_EQUALS("", errout.str()); } @@ -204,7 +204,7 @@ private: "};\n" "\n" "A::A() : _owner(false)\n" - "{ b(); }\n"); + "{ b(); }"); ASSERT_EQUALS("", errout.str()); } @@ -215,14 +215,14 @@ private: " A() : lock(new Lock())\n" " { }\n" " Lock *lock;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } void test6() { // ticket #2602 segmentation fault check("class A {\n" " A& operator=(const A&);\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -249,7 +249,7 @@ private: "};\n" "\n" "Fred::Fred()\n" - "{}\n"); + "{}"); ASSERT_EQUALS("[test.cpp:6]: (style) Unused private function: 'Fred::get'\n", errout.str()); } @@ -268,7 +268,7 @@ private: " void callback(const& unsigned) const {}\n" "\n" " Observer mObserver;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -282,7 +282,7 @@ private: "\n" "private:\n" " void f1() const {}\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -296,7 +296,7 @@ private: " void (*fptr)();\n" "};\n" "myclass::myclass() { fptr = &f; }\n" - "void myclass::f() {}\n"); + "void myclass::f() {}"); ASSERT_EQUALS("", errout.str()); } @@ -308,7 +308,7 @@ private: " void (*f)();\n" "private:\n" " static void func() { }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -324,7 +324,7 @@ private: " }\n" "\n" " int numOfThreads;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -342,7 +342,7 @@ private: "private:\n" " static void f()\n" " { }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'A::f'\n", errout.str()); check("class A\n" @@ -361,7 +361,7 @@ private: " B(A *a)\n" " { a->f(); }\n" " };\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -396,7 +396,7 @@ private: "};\n" "#endfile\n" "A::A() { }\n" - "void A::b() { }\n"); + "void A::b() { }"); ASSERT_EQUALS("", errout.str()); } @@ -408,7 +408,7 @@ private: " derived() : base() { }\n" "private:\n" " void f();\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("class base {\n" @@ -522,7 +522,7 @@ private: "template \n" "T A::getVal() const {\n" " return internalGetVal();\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -538,7 +538,7 @@ private: "private:\n" " void startListening() {\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("class Fred\n" @@ -550,7 +550,7 @@ private: "private:\n" " void startListening() {\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function: 'Fred::startListening'\n", errout.str()); } @@ -649,7 +649,7 @@ private: "#endfile\n" "void Fred::Init()\n" "{\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 69114d4a2..59d0d01b1 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -178,7 +178,7 @@ private: " int a;\n" " int b;\n" " int c;\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:3]: (style) struct or union member 'abc::a' is never used.\n" "[test.cpp:4]: (style) struct or union member 'abc::b' is never used.\n" "[test.cpp:5]: (style) struct or union member 'abc::c' is never used.\n", errout.str()); @@ -198,7 +198,7 @@ private: " int a = abc.a;\n" " int b = abc.b;\n" " int c = abc.c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -217,7 +217,7 @@ private: " int a = abc[0].a;\n" " int b = abc[0].b;\n" " int c = abc[0].c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -231,7 +231,7 @@ private: "{\n" " ABC abc;\n" " if (abc.a == 2);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -251,7 +251,7 @@ private: "{\n" " struct AB ab;\n" " ab.reset();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -265,7 +265,7 @@ private: "void foo(char *buf)\n" "{\n" " struct AB *ab = (struct AB *)&buf[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkStructMemberUsage("struct AB\n" @@ -277,7 +277,7 @@ private: "void foo(char *buf)\n" "{\n" " struct AB *ab = (AB *)&buf[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -291,7 +291,7 @@ private: "void foo(struct AB *ab)\n" "{\n" " ab->a = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkStructMemberUsage("struct AB\n" @@ -303,7 +303,7 @@ private: "void foo(struct AB _shuge *ab)\n" "{\n" " ab->a = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -317,7 +317,7 @@ private: "void foo(char *ab)\n" "{\n" " ((AB *)ab)->b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -327,7 +327,7 @@ private: "};\n" "\n" "struct derived : public base {" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -335,19 +335,19 @@ private: // Fred may have some useful side-effects checkStructMemberUsage("struct abc {\n" " Fred fred;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } void structmember11() { // #4168 checkStructMemberUsage("struct abc { int x; };\n" "struct abc s = {0};\n" - "void f() { do_something(&s); }\n"); + "void f() { do_something(&s); }"); ASSERT_EQUALS("", errout.str()); checkStructMemberUsage("struct abc { int x; };\n" "struct abc s = {0};\n" - "void f() { }\n"); + "void f() { }"); TODO_ASSERT_EQUALS("abc::x is not used", "", errout.str()); } @@ -362,7 +362,7 @@ private: "void foo()\n" "{\n" " ab.b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // global linkage => no false positive @@ -375,7 +375,7 @@ private: "void foo()\n" "{\n" " ab.b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // static linkage => error message @@ -388,7 +388,7 @@ private: "void foo()\n" "{\n" " ab.b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) struct or union member 'AB::a' is never used.\n", errout.str()); } @@ -414,13 +414,13 @@ private: functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); // if a is undefined then Cppcheck can't determine if "int i(a)" is a @@ -429,14 +429,14 @@ private: functionVariableUsage("void foo()\n" "{\n" " int i(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int j = 0;\n" " int i(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -444,7 +444,7 @@ private: " int j = 0;\n" " int & i = j;\n" " x(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -452,7 +452,7 @@ private: " int j = 0;\n" " const int & i = j;\n" " x(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -460,7 +460,7 @@ private: " int j = 0;\n" " int & i(j);\n" " x(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -468,47 +468,47 @@ private: " int j = 0;\n" " const int & i(j);\n" " x(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int * j = 0;\n" " int * i(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int * j = 0;\n" " const int * i(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " bool i = false;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " bool i = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char *i;\n" " i = fgets();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); // undefined variables are not reported because they may be classes with constructors functionVariableUsage("undefined foo()\n" "{\n" " undefined i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("undefined foo()\n" @@ -521,92 +521,92 @@ private: functionVariableUsage("void foo()\n" "{\n" " int i = undefined;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int * i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " void * i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " const void * i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " struct S * i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " const struct S * i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " struct S & i = j;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " const struct S & i = j;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " undefined * i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" " int j = i;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'j' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i[10] = { 0 };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo(int n)\n" "{\n" " int i[n] = { 0 };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char i[10] = \"123456789\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char *i = \"123456789\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -616,7 +616,7 @@ private: " std::cout<f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char * i;\n" " if (i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char * i = 0;\n" " if (i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char * i = new char[10];\n" " if (i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char *i;\n" " f(i);\n" - "}\n"); + "}"); functionVariableUsage("int a;\n" "void foo()\n" "{\n" " return &a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int a[10];\n" @@ -1207,7 +1207,7 @@ private: " int *p = a;\n" " for (int i = 0; i < 10; i++)\n" " p[i] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int a[10];\n" @@ -1216,7 +1216,7 @@ private: " int *p = &a[0];\n" " for (int i = 0; i < 10; i++)\n" " p[i] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -1225,14 +1225,14 @@ private: " int x;\n" " a[0] = 0;\n" " x = a[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int a, b, c;\n" " a = b = c = f();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n" "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n" "[test.cpp:4]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); @@ -1240,7 +1240,7 @@ private: functionVariableUsage("int * foo()\n" "{\n" " return &undefined[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1251,7 +1251,7 @@ private: " int a[10];\n" " for (int i = 0; i < 10; )\n" " a[i++] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); } @@ -1264,7 +1264,7 @@ private: " } else {\n" " int i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n" "[test.cpp:5]: (style) Unused variable: i\n" "[test.cpp:7]: (style) Unused variable: i\n", errout.str()); @@ -1276,7 +1276,7 @@ private: " int i;\n" " else\n" " int i;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n" "[test.cpp:5]: (style) Unused variable: i\n" "[test.cpp:7]: (style) Unused variable: i\n", errout.str()); @@ -1289,7 +1289,7 @@ private: " } else {\n" " int i = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n" "[test.cpp:5]: (style) Unused variable: i\n" "[test.cpp:7]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); @@ -1303,7 +1303,7 @@ private: " int i;\n" " }\n" " i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (style) Variable 'i' is assigned a value that is never used.\n" "[test.cpp:5]: (style) Unused variable: i\n" "[test.cpp:7]: (style) Unused variable: i\n", errout.str()); @@ -1319,7 +1319,7 @@ private: " return;\n" " }\n" " x = a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // The variable 'a' is initialized. But the initialized value is @@ -1334,7 +1334,7 @@ private: " else\n" " return;\n" " x = a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1345,7 +1345,7 @@ private: " int a, b, c, d, e, f;\n" " a = b = c = d = e = f = 0;\n" "\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n" "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n" @@ -1360,7 +1360,7 @@ private: " int a, b, c = 0;\n" " a = b = c;\n" "\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS( "[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n" @@ -1377,7 +1377,7 @@ private: "{\n" " int x;\n" " x = obj->ySize / 8;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); } @@ -1386,7 +1386,7 @@ private: functionVariableUsage("void foo()\n" "{\n" " int a[10];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n", errout.str()); } @@ -1397,7 +1397,7 @@ private: " int b[a];\n" " b[0] = 0;\n" " return b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo()\n" @@ -1406,7 +1406,7 @@ private: " int * b[a];\n" " b[0] = &c;\n" " return *b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int * foo()\n" @@ -1415,7 +1415,7 @@ private: " const int * b[a];\n" " b[0] = &c;\n" " return b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct B * foo()\n" @@ -1424,7 +1424,7 @@ private: " struct B * b[a];\n" " b[0] = &c;\n" " return b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("const struct B * foo()\n" @@ -1433,7 +1433,7 @@ private: " const struct B * b[a];\n" " b[0] = &c;\n" " return b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1443,7 +1443,7 @@ private: " char buf[5];\n" " char *ptr = buf;\n" " *(ptr++) = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'buf' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("int foo()\n" @@ -1451,7 +1451,7 @@ private: " char buf[5];\n" " char *ptr = buf - 1;\n" " *(++ptr) = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'buf' is not assigned a value.\n", errout.str()); // #3910 @@ -1460,7 +1460,7 @@ private: " char *data[2];\n" " data[0] = buf;\n" " do_something(data);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo() {\n" @@ -1470,7 +1470,7 @@ private: " data[0] = buf1;\n" " data[1] = buf2;\n" " do_something(data);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1486,7 +1486,7 @@ private: " line_start = ptr;\n" " data->info = k;\n" " line_start = ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (style) Variable 'line_start' is assigned a value that is never used.\n", errout.str()); } @@ -1494,7 +1494,7 @@ private: functionVariableUsage("A::A(int iValue) {\n" " UserDefinedException* pe = new UserDefinedException();\n" " throw pe;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1534,7 +1534,7 @@ private: " h = 0 ? u : v;\n" " i = 1 ? u : v;\n" " return h + i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1556,7 +1556,7 @@ private: " {\n" " throw *this;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1567,7 +1567,7 @@ private: " const char*edge = ppos? \" +\" : pneg ? \" -\" : \"\";\n" " printf(\"This should be a '+' -> %s\n\", edge);\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1576,7 +1576,7 @@ private: " const Fred &fred = getfred();\n" " int *p = fred.x();\n" " *p = 0;" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1584,7 +1584,7 @@ private: functionVariableUsage("void f(struct s *ptr) {\n" " int param = 1;\n" " ptr->param = param++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1593,7 +1593,7 @@ private: " char* pos = buffer;\n" " int size = value;\n" " *(int*)pos = size;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1602,7 +1602,7 @@ private: " float s_ranges[] = { 0, 256 };\n" " float* ranges[] = { s_ranges };\n" " cout << ranges[0][0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1610,7 +1610,7 @@ private: functionVariableUsage("void f() {\n" " Engine *engine = e;\n" " x->engine = engine->clone();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1618,7 +1618,7 @@ private: functionVariableUsage("void f() {\n" " int x = 0;\n" " a.x = x - b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1627,7 +1627,7 @@ private: " int x;\n" " fstream &f = getfile();\n" " f >> x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1637,7 +1637,7 @@ private: " while (0 != (abc = abc->next())) {\n" " ++nOldNum;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1648,7 +1648,7 @@ private: " } else {\n" " j -= i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1656,7 +1656,7 @@ private: functionVariableUsage("void f() {\n" " int a, b;\n" " x(1,a,b);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1665,13 +1665,13 @@ private: " int a, b;\n" " a = 2 * (b = 3);\n" " return a + b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int f() {\n" // ticket #4318 " int a,b;\n" " x(a, b=2);\n" // <- if param2 is passed-by-reference then b might be used in x - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1679,7 +1679,7 @@ private: functionVariableUsage("void f() {\n" " int a = 2;\n" " ints.at(a) = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1689,7 +1689,7 @@ private: " const std::string s1(sizeof_(code));\n" " const std::string s2 = sizeof_(code);\n" " return(s1+s2);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1697,7 +1697,7 @@ private: functionVariableUsage("void f() {\n" " int a = 1;\n" " foo(x*a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1705,7 +1705,7 @@ private: functionVariableUsage("int f() {\n" " int a = 1;\n" " return x & a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1714,7 +1714,7 @@ private: functionVariableUsage("{\n" " if (1) = x\n" " else abort s[2]\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1724,7 +1724,7 @@ private: " int x = 1;\n" " int y = FOO::VALUE * x;\n" " return y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1736,7 +1736,7 @@ private: " const float floatA = 2.2f;\n" " const float floatTot = g_float * floatA;\n" " SomeTestFunc(floatTot);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("float g_float = 1;\n" @@ -1746,7 +1746,7 @@ private: " const float floatB = 2.2f;\n" " const float floatTot = floatB * g_float;\n" " SomeTestFunc(floatTot);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("float g_float = 1;\n" @@ -1756,7 +1756,7 @@ private: " const float floatC = 2.2f;\n" " float floatTot = g_float * floatC;\n" " SomeTestFunc(floatTot);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1782,7 +1782,7 @@ private: " piArray[uiIndex] = -1234;\n" " }\n" " delete [] piArray;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1800,7 +1800,7 @@ private: "{\n" " int a;\n" " int *b = &a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n" "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); @@ -1808,7 +1808,7 @@ private: "{\n" " int a[10];\n" " int *b = a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n" "[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); @@ -1817,7 +1817,7 @@ private: " int a;\n" " int *b = &a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1825,7 +1825,7 @@ private: " int a;\n" " char *b = (char *)&a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1833,7 +1833,7 @@ private: " int a;\n" " char *b = (char *)(&a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1841,7 +1841,7 @@ private: " int a;\n" " const char *b = (const char *)&a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1849,7 +1849,7 @@ private: " int a;\n" " const char *b = (const char *)(&a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1857,7 +1857,7 @@ private: " int a;\n" " char *b = static_cast(&a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1865,7 +1865,7 @@ private: " int a;\n" " const char *b = static_cast(&a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); // a is not a local variable and b is aliased to it @@ -1873,14 +1873,14 @@ private: "void foo()\n" "{\n" " int *b = &a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); // a is not a local variable and b is aliased to it functionVariableUsage("void foo(int a)\n" "{\n" " int *b = &a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); // a is not a local variable and b is aliased to it @@ -1891,7 +1891,7 @@ private: " {\n" " int *b = &a;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("int a;\n" @@ -1899,14 +1899,14 @@ private: "{\n" " int *b = &a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo(int a)\n" "{\n" " int *b = &a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class A\n" @@ -1917,7 +1917,7 @@ private: " int *b = &a;\n" " *b = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -1925,7 +1925,7 @@ private: " int a[10];\n" " int *b = a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1933,7 +1933,7 @@ private: " int a[10];\n" " char *b = (char *)a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1941,7 +1941,7 @@ private: " int a[10];\n" " char *b = (char *)(a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1949,7 +1949,7 @@ private: " int a[10];\n" " const char *b = (const char *)a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1957,7 +1957,7 @@ private: " int a[10];\n" " const char *b = (const char *)(a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1965,7 +1965,7 @@ private: " int a[10];\n" " char *b = static_cast(a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -1973,7 +1973,7 @@ private: " int a[10];\n" " const char *b = static_cast(a);\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("int a[10];\n" @@ -1981,7 +1981,7 @@ private: "{\n" " int *b = a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int a[10];\n" @@ -1990,7 +1990,7 @@ private: " int *b = a;\n" " int *c = b;\n" " *c = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -1998,7 +1998,7 @@ private: " int *b = a;\n" " int *c = b;\n" " *c = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -2006,7 +2006,7 @@ private: " int *b = a;\n" " int *c = b;\n" " *c = b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -2014,7 +2014,7 @@ private: " int *b = a;\n" " int *c;\n" " *c = b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'c' is not assigned a value.\n", errout.str()); functionVariableUsage("int a[10];\n" @@ -2023,7 +2023,7 @@ private: " int *b = a;\n" " int c = b[0];\n" " x(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -2031,7 +2031,7 @@ private: " int *b = a;\n" " int c = b[0];\n" " x(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int a[10];\n" @@ -2039,28 +2039,28 @@ private: "{\n" " int *b = &a[0];\n" " a[0] = b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int *b = &a[0];\n" " a[0] = b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" "{\n" " int *b = a;\n" " a[0] = b[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo(int a[10])\n" "{\n" " int *b = a;\n" " *b = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class A\n" @@ -2071,7 +2071,7 @@ private: " int *b = a;\n" " *b = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -2080,7 +2080,7 @@ private: " int *b = a;\n" " int *c = b;\n" " *c = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -2090,7 +2090,7 @@ private: " int *c = a;\n" " int *d = b;\n" " *d = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n" "[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n" "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); @@ -2102,7 +2102,7 @@ private: " int *c = a;\n" " c = b;\n" " *c = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n" "[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); @@ -2115,7 +2115,7 @@ private: " *c = 0;\n" " c = a;\n" " *c = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (style) Variable 'a' is assigned a value that is never used.\n" "[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); @@ -2123,7 +2123,7 @@ private: "{\n" " int a[10], * b = a + 10;\n" " b[-10] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -2131,7 +2131,7 @@ private: " int a[10], * b = a + 10;\n" " b[-10] = 0;\n" " int * c = b - 10;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n" "[test.cpp:5]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); @@ -2140,7 +2140,7 @@ private: " int a[10], * b = a + 10;\n" " int * c = b - 10;\n" " x = c[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is not assigned a value.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -2148,7 +2148,7 @@ private: " int a[10], * b = a + 10;\n" " int * c = b - 10;\n" " c[1] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -2156,7 +2156,7 @@ private: " int a[10], * b = a + 10;\n" " int * c = b - 10;\n" " c[1] = c[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -2165,7 +2165,7 @@ private: " int * c = b - 10;\n" " int d = c[0];\n" " f(d);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is not assigned a value.\n", errout.str()); functionVariableUsage("void foo() {\n" // #4022 - FP (a is assigned a value that is never used) @@ -2174,7 +2174,7 @@ private: " b[0] = &a[0];\n" " int *d = b[0];\n" " return *d;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo() {\n" // #4022 - FP (a is assigned a value that is never used) @@ -2183,7 +2183,7 @@ private: " b[0] = &a[0];\n" " int d = b[0].value;\n" " return d;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct S { char c[100]; };\n" @@ -2192,7 +2192,7 @@ private: " char a[100];\n" " struct S * s = (struct S *)a;\n" " s->c[0] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct S { char c[100]; };\n" @@ -2200,7 +2200,7 @@ private: "{\n" " char a[100];\n" " struct S * s = (struct S *)a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: a\n" "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); @@ -2209,7 +2209,7 @@ private: "{\n" " char a[100];\n" " const struct S * s = (const struct S *)a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: a\n" "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); @@ -2218,7 +2218,7 @@ private: "{\n" " char a[100];\n" " struct S * s = static_cast(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: a\n" "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); @@ -2227,7 +2227,7 @@ private: "{\n" " char a[100];\n" " const struct S * s = static_cast(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: a\n" "[test.cpp:5]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); @@ -2241,7 +2241,7 @@ private: " d = a;\n" " d = c;\n" " *d = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: b\n" "[test.cpp:10]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); @@ -2254,7 +2254,7 @@ private: " d = b; *d = 0;\n" " d = a; *d = 0;\n" " d = c; *d = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'b' is assigned a value that is never used.\n" "[test.cpp:9]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); } @@ -2264,7 +2264,7 @@ private: "{\n" " int * a;\n" " x(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2275,7 +2275,7 @@ private: " char szDisplayName[MAX_PATH];\n" " info.pszDisplayName = szDisplayName;\n" " SHBrowseForFolder(&info);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2284,7 +2284,7 @@ private: "void foo()\n" "{\n" " int * a = &ab.a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("struct AB { int a; int b; } ab;\n" @@ -2292,7 +2292,7 @@ private: "{\n" " int * a = &ab.a;\n" " *a = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct AB { int a; int b; };\n" @@ -2300,7 +2300,7 @@ private: "{\n" " struct AB ab;\n" " int * a = &ab.a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ab' is not assigned a value.\n" "[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); @@ -2310,7 +2310,7 @@ private: " struct AB ab;\n" " int * a = &ab.a;\n" " *a = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2321,7 +2321,7 @@ private: " char *p = &buf[0];\n" " *p++ = 0;\n" " return buf[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("char foo()\n" @@ -2330,7 +2330,7 @@ private: " char *p = &buf[1];\n" " *p-- = 0;\n" " return buf[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("char foo()\n" @@ -2339,7 +2339,7 @@ private: " char *p = &buf[0];\n" " *++p = 0;\n" " return buf[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("char foo()\n" @@ -2348,7 +2348,7 @@ private: " char *p = &buf[1];\n" " *--p = 0;\n" " return buf[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2741,7 +2741,7 @@ private: " int x=1,y;\n" " y = (x * a) / 100;\n" " return y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2767,7 +2767,7 @@ private: " int a;\n" " asm();\n" " b = a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2776,7 +2776,7 @@ private: "{\n" " static const struct{ int x, y, w, h; } bounds = {1,2,3,4};\n" " return bounds.x + bounds.y + bounds.w + bounds.h;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2785,7 +2785,7 @@ private: "{\n" " struct ABC { int a, b, c; };\n" " struct ABC abc = { 1, 2, 3 };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'abc' is assigned a value that is never used.\n", errout.str()); } @@ -2797,7 +2797,7 @@ private: " do {\n" " func();\n" " } while(a--);\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: x\n" "[test.cpp:4]: (style) Unused variable: z\n", "", errout.str()); } @@ -2813,13 +2813,13 @@ private: functionVariableUsage("int foo() {\n" " A a;\n" " return a.i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo() {\n" @@ -2833,14 +2833,14 @@ private: "int foo() {\n" " A a;\n" " return a.i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class A { int i; };\n" "int foo() {\n" " A a;\n" " return a.i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct A { int i; };\n" @@ -2848,7 +2848,7 @@ private: " A a;\n" " a.i = 0;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class A { int i; };\n" @@ -2856,63 +2856,63 @@ private: " A a;\n" " a.i = 0;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct A { int i; };\n" "int foo() {\n" " A a = { 0 };\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("class A { int i; };\n" "int foo() {\n" " A a = { 0 };\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("class A { int i; public: A(); { } };\n" "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct A { int i; };\n" "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n", errout.str()); functionVariableUsage("class A { int i; };\n" "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n", errout.str()); functionVariableUsage("class A { int i; public: A(); { } };\n" "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class A { unknown i; };\n" "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class A : public Fred { int i; };\n" "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class Fred {char c;};\n" @@ -2920,7 +2920,7 @@ private: "int foo() {\n" " A a;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: a\n", errout.str()); } @@ -2931,7 +2931,7 @@ private: " Type & get() { return t; }\n" "private:\n" " Type t;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -2951,7 +2951,7 @@ private: "{\n" " int tmp = 10;\n" " return 123 " + std::string(1, *p) + " tmp;\n" - "}\n"); + "}"); functionVariableUsage(code.c_str()); ASSERT_EQUALS("", errout.str()); } @@ -2962,7 +2962,7 @@ private: "{\n" " int tmp = 10;\n" " return ~tmp;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2973,7 +2973,7 @@ private: " if ( tmp )\n" " return 1;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2984,7 +2984,7 @@ private: " int tmp2 = 2;\n" " int tmp3 = 3;\n" " return tmp1 ? tmp2 : tmp3;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2994,13 +2994,13 @@ private: " int a = 1;\n" " int b = 2;\n" " a |= b;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo() {\n" " int a = 1;\n" " (b).x += a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3009,7 +3009,7 @@ private: "{\n" " int a = 1;\n" " for (;a;);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo() {\n" @@ -3027,7 +3027,7 @@ private: " if (i==x) return x;\n" " i = x;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo() {\n" @@ -3036,7 +3036,7 @@ private: " FOREACH_X (int x, a) {\n" " i = x;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo() {\n" @@ -3046,7 +3046,7 @@ private: " if (i==x) return x;\n" " i = x;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); } @@ -3055,7 +3055,7 @@ private: "{\n" " int var = 1;\n" " return 1 >> var;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3064,7 +3064,7 @@ private: "{\n" " int var = 1;\n" " while (var = var >> 1) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3073,14 +3073,14 @@ private: "{\n" " QList ints;\n" " ints << 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo() {\n" // #4320 " int x;\n" " x << 1;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3090,7 +3090,7 @@ private: " int a = 1;\n" " int b = static_cast(a);\n" " return b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3101,7 +3101,7 @@ private: " int a;\n" " int f() { return a; }\n" " } b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3109,25 +3109,25 @@ private: functionVariableUsage("int foo()\n" "{\n" " bool test __attribute__((unused));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo()\n" "{\n" " bool test __attribute__((unused)) = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo()\n" "{\n" " bool __attribute__((unused)) test;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("int foo()\n" "{\n" " bool __attribute__((unused)) test = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3146,26 +3146,26 @@ private: functionVariableUsage("void foo()\n" "{\n" " static int i;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " static int i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " static int i(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " static int j = 0;\n" " static int i(j);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("int * foo(int x)\n" @@ -3191,7 +3191,7 @@ private: functionVariableUsage("void foo() {\n" " extern int i;\n" " i = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3200,28 +3200,28 @@ private: "{\n" " void* ptr = malloc(16);\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " void* ptr = g_malloc(16);\n" " g_free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " void* ptr = kmalloc(16, GFP_KERNEL);\n" " kfree(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " void* ptr = vmalloc(16, GFP_KERNEL);\n" " vfree(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); @@ -3229,28 +3229,28 @@ private: "{\n" " char* ptr = new char[16];\n" " delete[] ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char* ptr = new ( nothrow ) char[16];\n" " delete[] ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char* ptr = new ( std::nothrow ) char[16];\n" " delete[] ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" "{\n" " char* ptr = new char;\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("void foo()\n" @@ -3258,7 +3258,7 @@ private: " void* ptr = malloc(16);\n" " ptr[0] = 123;\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -3266,7 +3266,7 @@ private: " char* ptr = new char[16];\n" " ptr[0] = 123;\n" " delete[] ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -3274,7 +3274,7 @@ private: " Fred* fred = new Fred;\n" " std::cout << \"test\" << std::endl;\n" " delete fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct Fred { int a; };\n" @@ -3283,7 +3283,7 @@ private: " Fred* fred = new Fred;\n" " std::cout << \"test\" << std::endl;\n" " delete fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'fred' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int a; Fred() : a(0) {} };\n" @@ -3292,7 +3292,7 @@ private: " Fred* fred = new Fred;\n" " std::cout << \"test\" << std::endl;\n" " delete fred;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void foo()\n" @@ -3300,7 +3300,7 @@ private: " Fred* fred = malloc(sizeof(Fred));\n" " std::cout << \"test\" << std::endl;\n" " free(fred);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'fred' is allocated memory that is never used.\n", errout.str()); @@ -3308,7 +3308,7 @@ private: "{\n" " char* ptr = names[i];\n" " delete[] ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3318,7 +3318,7 @@ private: "{\n" " Fred* ptr = malloc(sizeof(Fred));\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3327,7 +3327,7 @@ private: " Fred* ptr = malloc(sizeof(Fred));\n" " ptr->i = 0;\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3335,7 +3335,7 @@ private: "{\n" " struct Fred* ptr = malloc(sizeof(Fred));\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3344,7 +3344,7 @@ private: " struct Fred* ptr = malloc(sizeof(Fred));\n" " ptr->i = 0;\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3352,7 +3352,7 @@ private: "{\n" " Fred* ptr = new Fred();\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3360,7 +3360,7 @@ private: "{\n" " Fred* ptr = new (nothrow ) Fred();\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3368,7 +3368,7 @@ private: "{\n" " Fred* ptr = new (std::nothrow) Fred();\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3377,7 +3377,7 @@ private: " Fred* ptr = new Fred();\n" " ptr->i = 0;\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3385,7 +3385,7 @@ private: "{\n" " struct Fred* ptr = new Fred();\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("struct Fred { int i; };\n" @@ -3394,7 +3394,7 @@ private: " struct Fred* ptr = new Fred();\n" " ptr->i = 0;\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class Fred { public: int i; };\n" @@ -3402,7 +3402,7 @@ private: "{\n" " Fred* ptr = malloc(sizeof(Fred));\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("class Fred { public: int i; };\n" @@ -3411,7 +3411,7 @@ private: " Fred* ptr = malloc(sizeof(Fred));\n" " ptr->i = 0;\n" " free(ptr);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("class Fred { public: int i; };\n" @@ -3419,7 +3419,7 @@ private: "{\n" " Fred* ptr = new Fred();\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'ptr' is allocated memory that is never used.\n", errout.str()); functionVariableUsage("class Fred { public: int i; };\n" @@ -3428,7 +3428,7 @@ private: " Fred* ptr = new Fred();\n" " ptr->i = 0;\n" " delete ptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3439,7 +3439,7 @@ private: " int* p = data;\n" " for ( int i = 0; i < 10; ++i )\n" " p++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3447,7 +3447,7 @@ private: functionVariableUsage("void foo() {\n" " int p[5];\n" " *p = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3456,7 +3456,7 @@ private: " int p[5][5];\n" " p[0][0] = 0;\n" " return p[0][0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3465,37 +3465,37 @@ private: " int p[5][5];\n" " *((int*)p[0]) = 0;\n" " return p[0][0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void localvarstring1() { // ticket #1597 functionVariableUsage("void foo() {\n" " std::string s;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: s\n", errout.str()); functionVariableUsage("void foo() {\n" " std::string s;\n" " s = \"foo\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void foo() {\n" " std::string s = \"foo\";\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Variable 's' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("std::string foo() {\n" " std::string s;\n" // Class instances are initialized. Assignement is not necessary " return s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("std::string foo() {\n" " std::string s = \"foo\";\n" " return s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3503,7 +3503,7 @@ private: functionVariableUsage("void foo() {\n" " std::string s;\n" " int i;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: s\n" "[test.cpp:3]: (style) Unused variable: i\n", errout.str()); } @@ -3511,7 +3511,7 @@ private: void localvarconst1() { functionVariableUsage("void foo() {\n" " const bool b = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); } @@ -3519,7 +3519,7 @@ private: functionVariableUsage("void foo() {\n" " const int N = 10;\n" " struct X { int x[N]; };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3633,7 +3633,7 @@ private: " }\n" " }\n" " return j;\n" - "}\n"); // #4585 + "}"); // #4585 ASSERT_EQUALS("", errout.str()); } };