You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testnullpointer.cpp
+13-50Lines changed: 13 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -1124,12 +1124,6 @@ class TestNullPointer : public TestFixture {
1124
1124
}
1125
1125
1126
1126
voidnullpointer8() {
1127
-
check("void foo()\n"
1128
-
"{\n"
1129
-
" const char * x = 0;\n"
1130
-
" strdup(x);\n"
1131
-
"}");
1132
-
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
1133
1127
check("void foo()\n"
1134
1128
"{\n"
1135
1129
" char const * x = 0;\n"
@@ -1154,39 +1148,9 @@ class TestNullPointer : public TestFixture {
1154
1148
" p->x = 0;\n"
1155
1149
"}");
1156
1150
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
1157
-
1158
-
check("void foo()\n"
1159
-
"{\n"
1160
-
" struct my_type* p;\n"
1161
-
" p = 0;\n"
1162
-
" p->x = 0;\n"
1163
-
"}");
1164
-
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
1165
1151
}
1166
1152
1167
1153
voidnullpointer11() { // ticket #2812
1168
-
check("int foo()\n"
1169
-
"{\n"
1170
-
" my_type* p = 0;\n"
1171
-
" return p->x;\n"
1172
-
"}");
1173
-
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
1174
-
1175
-
check("int foo()\n"
1176
-
"{\n"
1177
-
" struct my_type* p = 0;\n"
1178
-
" return p->x;\n"
1179
-
"}");
1180
-
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
1181
-
1182
-
check("int foo()\n"
1183
-
"{\n"
1184
-
" my_type* p;\n"
1185
-
" p = 0;\n"
1186
-
" return p->x;\n"
1187
-
"}");
1188
-
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
1189
-
1190
1154
check("int foo()\n"
1191
1155
"{\n"
1192
1156
" struct my_type* p;\n"
@@ -1429,21 +1393,20 @@ class TestNullPointer : public TestFixture {
1429
1393
"}");
1430
1394
ASSERT_EQUALS("", errout.str());
1431
1395
1432
-
check("void foo(char *p) {\n"
1433
-
" if (!p) {\n"
1434
-
" abort();\n"
1435
-
" }\n"
1436
-
" *p = 0;\n"
1437
-
"}");
1438
-
ASSERT_EQUALS("", errout.str());
1396
+
{
1397
+
staticconstchar code[] =
1398
+
"void foo(char *p) {\n"
1399
+
" if (!p) {\n"
1400
+
" abort();\n"
1401
+
" }\n"
1402
+
" *p = 0;\n"
1403
+
"}";
1404
+
check(code, false);
1405
+
ASSERT_EQUALS("", errout.str());
1439
1406
1440
-
check("void foo(char *p) {\n"
1441
-
" if (!p) {\n"
1442
-
" abort();\n"
1443
-
" }\n"
1444
-
" *p = 0;\n"
1445
-
"}\n", true);
1446
-
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());
1407
+
check(code, true);
1408
+
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());
Copy file name to clipboardExpand all lines: test/testother.cpp
+2-45Lines changed: 2 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -2844,13 +2844,6 @@ class TestOther : public TestFixture {
2844
2844
}
2845
2845
2846
2846
voidsuspiciousEqualityComparison() {
2847
-
check("void foo(int c) {\n"
2848
-
" if (c == 1) {\n"
2849
-
" c == 0;\n"
2850
-
" }\n"
2851
-
"}");
2852
-
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout.str());
2853
-
2854
2847
check("void foo(int c) {\n"
2855
2848
" if (c == 1) c == 0;\n"
2856
2849
"}");
@@ -2916,13 +2909,6 @@ class TestOther : public TestFixture {
2916
2909
"}");
2917
2910
ASSERT_EQUALS("", errout.str());
2918
2911
2919
-
check("void foo(int c) {\n"
2920
-
" for (; running == 1;) {\n"
2921
-
" c ++;\n"
2922
-
" }\n"
2923
-
"}");
2924
-
ASSERT_EQUALS("", errout.str());
2925
-
2926
2912
check("void foo(int c) {\n"
2927
2913
" printf(\"%i\n\", ({x==0;}));\n"
2928
2914
"}");
@@ -3446,14 +3432,6 @@ class TestOther : public TestFixture {
3446
3432
);
3447
3433
ASSERT_EQUALS("[test.cpp:4]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6.\n", errout.str());
3448
3434
3449
-
check("void f(int x, int y) {\n"
3450
-
" const int ERR1 = 5;\n"
3451
-
" if ((x != ERR1) || (y != ERR1))\n"
3452
-
" a++;\n"
3453
-
"}\n"
3454
-
);
3455
-
ASSERT_EQUALS("", errout.str());
3456
-
3457
3435
check("void f(unsigned int a, unsigned int b, unsigned int c) {\n"
3458
3436
" if((a != b) || (c != b) || (c != a))\n"
3459
3437
" {\n"
@@ -3849,8 +3827,6 @@ class TestOther : public TestFixture {
0 commit comments