Removed more duplicate unit tests
This commit is contained in:
parent
8e4f99884b
commit
693c6e84cb
|
@ -1124,12 +1124,6 @@ private:
|
|||
}
|
||||
|
||||
void nullpointer8() {
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" const char * x = 0;\n"
|
||||
" strdup(x);\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"
|
||||
|
@ -1154,39 +1148,9 @@ private:
|
|||
" p->x = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" struct my_type* p;\n"
|
||||
" p = 0;\n"
|
||||
" p->x = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer11() { // ticket #2812
|
||||
check("int foo()\n"
|
||||
"{\n"
|
||||
" my_type* p = 0;\n"
|
||||
" return p->x;\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"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("int foo()\n"
|
||||
"{\n"
|
||||
" my_type* p;\n"
|
||||
" p = 0;\n"
|
||||
" return p->x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("int foo()\n"
|
||||
"{\n"
|
||||
" struct my_type* p;\n"
|
||||
|
@ -1429,21 +1393,20 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(char *p) {\n"
|
||||
{
|
||||
static const char code[] =
|
||||
"void foo(char *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" abort();\n"
|
||||
" }\n"
|
||||
" *p = 0;\n"
|
||||
"}");
|
||||
"}";
|
||||
check(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(char *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" abort();\n"
|
||||
" }\n"
|
||||
" *p = 0;\n"
|
||||
"}\n", true);
|
||||
check(code, true);
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (warning, inconclusive) 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"
|
||||
|
|
|
@ -2844,13 +2844,6 @@ private:
|
|||
}
|
||||
|
||||
void suspiciousEqualityComparison() {
|
||||
check("void foo(int c) {\n"
|
||||
" if (c == 1) {\n"
|
||||
" c == 0;\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout.str());
|
||||
|
||||
check("void foo(int c) {\n"
|
||||
" if (c == 1) c == 0;\n"
|
||||
"}");
|
||||
|
@ -2916,13 +2909,6 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(int c) {\n"
|
||||
" for (; running == 1;) {\n"
|
||||
" c ++;\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(int c) {\n"
|
||||
" printf(\"%i\n\", ({x==0;}));\n"
|
||||
"}");
|
||||
|
@ -3446,14 +3432,6 @@ private:
|
|||
);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6.\n", errout.str());
|
||||
|
||||
check("void f(int x, int y) {\n"
|
||||
" const int ERR1 = 5;\n"
|
||||
" if ((x != ERR1) || (y != ERR1))\n"
|
||||
" a++;\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(unsigned int a, unsigned int b, unsigned int c) {\n"
|
||||
" if((a != b) || (c != b) || (c != a))\n"
|
||||
" {\n"
|
||||
|
@ -3849,8 +3827,6 @@ private:
|
|||
check("setegid(getegid());\n", NULL, false , false, true);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Redundant get and set of user id.\n", errout.str());
|
||||
|
||||
check("seteuid(getuid());\n", NULL, false , false, true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("seteuid(getuid());\n", NULL, false , false, true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("seteuid(foo());\n", NULL, false , false, true);
|
||||
|
@ -4089,12 +4065,12 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" if (\"Hello\" && 1) { }\n"
|
||||
" if (\"Hello\" && test) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" if (1 && \"Hello\") { }\n"
|
||||
" if (test && \"Hello\") { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str());
|
||||
|
||||
|
@ -4286,15 +4262,6 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" if (front < 0)\n"
|
||||
" { frac = (front)/(front-back);}\n"
|
||||
" else\n"
|
||||
" frac = (front)/(front-back);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" if (front < 0)\n"
|
||||
|
@ -5017,16 +4984,6 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Suspicious use of ; at the end of 'for' statement.\n", errout.str());
|
||||
|
||||
// Block with some tokens to make sure the tokenizer output
|
||||
// stays the same for "for(); {}"
|
||||
check(
|
||||
"void foo() {\n"
|
||||
" for(int i = 0; i < 10; ++i); {\n"
|
||||
" int j = 123;\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Suspicious use of ; at the end of 'for' statement.\n", errout.str());
|
||||
|
||||
check(
|
||||
"void foo() {\n"
|
||||
" while (!quit); {\n"
|
||||
|
|
|
@ -2584,7 +2584,6 @@ private:
|
|||
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false));
|
||||
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(x==0);", false));
|
||||
ASSERT_EQUALS("if ( ! ( a = b ) ) { ; }", tok("if(0==(a=b));", false));
|
||||
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(x==0);", false));
|
||||
ASSERT_EQUALS("if ( ! a && b ( ) ) { ; }", tok("if( 0 == a && b() );", false));
|
||||
ASSERT_EQUALS("if ( b ( ) && ! a ) { ; }", tok("if( b() && 0 == a );", false));
|
||||
ASSERT_EQUALS("if ( ! ( a = b ) ) { ; }", tok("if((a=b)==0);", false));
|
||||
|
|
Loading…
Reference in New Issue