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
+32-32Lines changed: 32 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -308,7 +308,7 @@ class TestNullPointer : public TestFixture {
308
308
" return;\n"
309
309
" }\n"
310
310
" if (!abc);\n"
311
-
"}");
311
+
"}", false, "test.cpp", false);
312
312
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (warning) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
313
313
314
314
// TODO: False negative if member of member is dereferenced
@@ -323,7 +323,7 @@ class TestNullPointer : public TestFixture {
323
323
" abc->a = 0;\n"
324
324
" if (abc && abc->b == 0)\n"
325
325
" ;\n"
326
-
"}");
326
+
"}", false, "test.cpp", false);
327
327
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", errout.str());
328
328
329
329
// ok dereferencing in a condition
@@ -560,7 +560,7 @@ class TestNullPointer : public TestFixture {
560
560
"{\n"
561
561
" if (*p == 0) { }\n"
562
562
" if (!p) { }\n"
563
-
"}");
563
+
"}", false, "test.cpp", false);
564
564
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
565
565
566
566
// no error
@@ -597,7 +597,7 @@ class TestNullPointer : public TestFixture {
597
597
" int a = 2 * x;"
598
598
" if (x == 0)\n"
599
599
" ;\n"
600
-
"}", true);
600
+
"}", true, "test.cpp", false);
601
601
ASSERT_EQUALS("", errout.str());
602
602
603
603
check("void foo(int *p)\n"
@@ -823,12 +823,12 @@ class TestNullPointer : public TestFixture {
823
823
check("void f(struct ABC *abc) {\n"
824
824
" WARN_ON(!abc || abc->x == 0);\n"
825
825
" if (!abc) { }\n"
826
-
"}");
826
+
"}", false, "test.cpp", false);
827
827
ASSERT_EQUALS("", errout.str());
828
828
check("void f(struct ABC *abc) {\n"
829
829
" WARN_ON(!abc || abc->x == 7);\n"
830
830
" if (!abc) { }\n"
831
-
"}");
831
+
"}", false, "test.cpp", false);
832
832
ASSERT_EQUALS("", errout.str());
833
833
834
834
// #3425 - false positives when there are macros
@@ -1343,34 +1343,34 @@ class TestNullPointer : public TestFixture {
1343
1343
" if (NULL == p) {\n"
1344
1344
" }\n"
1345
1345
" *p = 0;\n"
1346
-
"}");
1346
+
"}", false, "test.cpp", false);
1347
1347
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1348
1348
1349
1349
check("void foo(char *p) {\n"
1350
1350
" if (p == NULL) {\n"
1351
1351
" }\n"
1352
1352
" *p = 0;\n"
1353
-
"}");
1353
+
"}", false, "test.cpp", false);
1354
1354
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1355
1355
1356
1356
check("void foo(char *p) {\n"
1357
1357
" if (p == NULL) {\n"
1358
1358
" }\n"
1359
1359
" printf(\"%c\", *p);\n"
1360
-
"}");
1360
+
"}", false, "test.cpp", false);
1361
1361
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1362
1362
1363
1363
check("void foo(char *p) {\n"
1364
1364
" if (p && *p == 0) {\n"
1365
1365
" }\n"
1366
1366
" printf(\"%c\", *p);\n"
1367
-
"}");
1367
+
"}", false, "test.cpp", false);
1368
1368
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1369
1369
1370
1370
check("void foo(char *p) {\n"
1371
1371
" if (p && *p == 0) {\n"
1372
1372
" } else { *p = 0; }\n"
1373
-
"}");
1373
+
"}", false, "test.cpp", false);
1374
1374
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1375
1375
1376
1376
check("void foo(char *p) {\n"
@@ -1500,7 +1500,7 @@ class TestNullPointer : public TestFixture {
1500
1500
" MACRO;\n"
1501
1501
" }\n"
1502
1502
" fred->a();\n"
1503
-
"}");
1503
+
"}", false, "test.cpp", false);
1504
1504
ASSERT_EQUALS("", errout.str());
1505
1505
1506
1506
// #2493 - switch
@@ -1513,7 +1513,7 @@ class TestNullPointer : public TestFixture {
1513
1513
" fred->a();\n"
1514
1514
" break;\n"
1515
1515
" };\n"
1516
-
"}");
1516
+
"}", false, "test.cpp", false);
1517
1517
ASSERT_EQUALS("", errout.str());
1518
1518
1519
1519
// #4118 - second if
@@ -1549,7 +1549,7 @@ class TestNullPointer : public TestFixture {
1549
1549
" else {\n"
1550
1550
" int b = *i;\n"
1551
1551
" }\n"
1552
-
"}", true);
1552
+
"}", true, "test.cpp", false);
1553
1553
ASSERT_EQUALS("", errout.str());
1554
1554
1555
1555
// #2696 - false positives nr 1
@@ -1611,7 +1611,7 @@ class TestNullPointer : public TestFixture {
1611
1611
" if (p == 0 && (p = malloc(10)) != 0) {\n"
1612
1612
" *p = 0;\n"
1613
1613
" }\n"
1614
-
"}");
1614
+
"}", false, "test.cpp", false);
1615
1615
ASSERT_EQUALS("", errout.str());
1616
1616
1617
1617
// check, assign and use
@@ -1620,7 +1620,7 @@ class TestNullPointer : public TestFixture {
1620
1620
" if (p == 0 && (p = malloc(10)) != a && (*p = a)) {\n"
1621
1621
" *p = 0;\n"
1622
1622
" }\n"
1623
-
"}");
1623
+
"}", false, "test.cpp", false);
1624
1624
ASSERT_EQUALS("", errout.str());
1625
1625
1626
1626
// check, and use
@@ -1629,7 +1629,7 @@ class TestNullPointer : public TestFixture {
1629
1629
" if (p == 0 && (*p = 0)) {\n"
1630
1630
" return;\n"
1631
1631
" }\n"
1632
-
"}");
1632
+
"}", false, "test.cpp", false);
1633
1633
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1634
1634
1635
1635
// check, and use
@@ -1638,7 +1638,7 @@ class TestNullPointer : public TestFixture {
1638
1638
" if (p == 0 && p->x == 10) {\n"
1639
1639
" return;\n"
1640
1640
" }\n"
1641
-
"}");
1641
+
"}", false, "test.cpp", false);
1642
1642
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1643
1643
1644
1644
// check, and use
@@ -1647,7 +1647,7 @@ class TestNullPointer : public TestFixture {
1647
1647
" if (p == 0 || p->x == 10) {\n"
1648
1648
" return;\n"
1649
1649
" }\n"
1650
-
"}");
1650
+
"}", false, "test.cpp", false);
1651
1651
ASSERT_EQUALS("", errout.str());
1652
1652
1653
1653
// check, and use
@@ -1656,15 +1656,15 @@ class TestNullPointer : public TestFixture {
1656
1656
" if (p == NULL && (*p = a)) {\n"
1657
1657
" return;\n"
1658
1658
" }\n"
1659
-
"}");
1659
+
"}", false, "test.cpp", false);
1660
1660
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1661
1661
1662
1662
// check, and use
1663
1663
check("void f(struct X *p, int x) {\n"
1664
1664
" if (!p && x==1 || p && p->x==0) {\n"
1665
1665
" return;\n"
1666
1666
" }\n"
1667
-
"}");
1667
+
"}", false, "test.cpp", false);
1668
1668
ASSERT_EQUALS("", errout.str());
1669
1669
1670
1670
{
@@ -1673,17 +1673,17 @@ class TestNullPointer : public TestFixture {
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning, inconclusive) Possible null pointer dereference: fred - otherwise it is redundant to check it against null.\n", errout.str());
1681
1681
}
1682
1682
1683
1683
check("void f(char *s) {\n"// #3358
1684
1684
" if (s==0);\n"
1685
1685
" strcpy(a, s?b:c);\n"
1686
-
"}");
1686
+
"}", false, "test.cpp", false);
1687
1687
ASSERT_EQUALS("", errout.str());
1688
1688
1689
1689
// sizeof
@@ -2054,7 +2054,7 @@ class TestNullPointer : public TestFixture {
2054
2054
" std::cin >> p;\n"
2055
2055
" std::cout << abc << p;\n"
2056
2056
" }\n"
2057
-
"}");
2057
+
"}", false, "test.cpp", false);
2058
2058
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"
2059
2059
"[test.cpp:4] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"
2060
2060
"[test.cpp:5] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"
@@ -2281,7 +2281,7 @@ class TestNullPointer : public TestFixture {
2281
2281
check("void f(int *p = 0) {\n"
2282
2282
" if (p != 0 && bar())\n"
2283
2283
" *p = 0;\n"
2284
-
"}");
2284
+
"}", false, "test.cpp", false);
2285
2285
ASSERT_EQUALS("", errout.str());
2286
2286
2287
2287
check("void f(int *p) {\n"
@@ -2292,21 +2292,21 @@ class TestNullPointer : public TestFixture {
2292
2292
check("void f(int *p = 0) {\n"
2293
2293
" if (p != 0)\n"
2294
2294
" *p = 0;\n"
2295
-
"}");
2295
+
"}", false, "test.cpp", false);
2296
2296
ASSERT_EQUALS("", errout.str());
2297
2297
2298
2298
check("void f(int *p = 0) {\n"
2299
2299
" int y;\n"
2300
2300
" if (p == 0)\n"
2301
2301
" p = &y;\n"
2302
2302
" *p = 0;\n"
2303
-
"}");
2303
+
"}", false, "test.cpp", false);
2304
2304
ASSERT_EQUALS("", errout.str());
2305
2305
2306
2306
check("void f(int *p = 0) {\n"
2307
2307
" if (a != 0)\n"
2308
2308
" *p = 0;\n"
2309
-
"}");
2309
+
"}", false, "test.cpp", false);
2310
2310
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout.str());
2311
2311
2312
2312
check("void f(int *p = 0) {\n"
@@ -2326,7 +2326,7 @@ class TestNullPointer : public TestFixture {
2326
2326
" return 0;\n"
2327
2327
" }\n"
2328
2328
" return *p;\n"
2329
-
"}");
2329
+
"}", false, "test.cpp", false);
2330
2330
ASSERT_EQUALS("", errout.str());
2331
2331
2332
2332
check("void f(int *p = 0) {\n"
@@ -2400,15 +2400,15 @@ class TestNullPointer : public TestFixture {
0 commit comments