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
+59Lines changed: 59 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,10 @@ class TestNullPointer : public TestFixture {
78
78
TEST_CASE(nullpointer36); // #9264
79
79
TEST_CASE(nullpointer37); // #9315
80
80
TEST_CASE(nullpointer38);
81
+
TEST_CASE(nullpointer39); // #2153
82
+
TEST_CASE(nullpointer40);
83
+
TEST_CASE(nullpointer41);
84
+
TEST_CASE(nullpointer42);
81
85
TEST_CASE(nullpointer_addressOf); // address of
82
86
TEST_CASE(nullpointerSwitch); // #2626
83
87
TEST_CASE(nullpointer_cast); // #4692
@@ -1474,6 +1478,61 @@ class TestNullPointer : public TestFixture {
1474
1478
ASSERT_EQUALS("", errout.str());
1475
1479
}
1476
1480
1481
+
voidnullpointer39()
1482
+
{
1483
+
check("struct A { int * x; };\n"
1484
+
"void f(struct A *a) {\n"
1485
+
" if (a->x == NULL) {}\n"
1486
+
" *(a->x);\n"
1487
+
"}\n");
1488
+
ASSERT_EQUALS(
1489
+
"[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x.\n",
1490
+
errout.str());
1491
+
}
1492
+
1493
+
voidnullpointer40()
1494
+
{
1495
+
check("struct A { std::unique_ptr<int> x; };\n"
1496
+
"void f(struct A *a) {\n"
1497
+
" if (a->x == nullptr) {}\n"
1498
+
" *(a->x);\n"
1499
+
"}\n");
1500
+
ASSERT_EQUALS(
1501
+
"[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x.\n",
1502
+
errout.str());
1503
+
}
1504
+
1505
+
voidnullpointer41()
1506
+
{
1507
+
check("struct A { int * g() const; };\n"
1508
+
"void f(struct A *a) {\n"
1509
+
" if (a->g() == nullptr) {}\n"
1510
+
" *(a->g());\n"
1511
+
"}\n");
1512
+
ASSERT_EQUALS(
1513
+
"[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g().\n",
1514
+
errout.str());
1515
+
1516
+
check("struct A { int * g(); };\n"
1517
+
"void f(struct A *a) {\n"
1518
+
" if (a->g() == nullptr) {}\n"
1519
+
" *(a->g());\n"
1520
+
"}\n");
1521
+
ASSERT_EQUALS("", errout.str());
1522
+
}
1523
+
1524
+
voidnullpointer42()
1525
+
{
1526
+
check("struct A { std::unique_ptr<int> g() const; };\n"
1527
+
"void f(struct A *a) {\n"
1528
+
" if (a->g() == nullptr) {}\n"
1529
+
" *(a->g());\n"
1530
+
"}\n");
1531
+
ASSERT_EQUALS(
1532
+
"[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g().\n",
0 commit comments