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
{{ message }}
Repository navigation
Commit 03c04ee
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: test/testnullpointer.cpp
+31Lines changed: 31 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3409,6 +3409,37 @@ class TestNullPointer : public TestFixture {
3409
3409
"}\n");
3410
3410
ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:14:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n",
3411
3411
errout_str());
3412
+
3413
+
check("bool g();\n"// the path that sets w assigns p, the other path keeps it
3414
+
"void use(int);\n"
3415
+
"void f(const int *p, const int *q) {\n"
3416
+
" if (!p) {\n"
3417
+
" bool w = false;\n"
3418
+
" if (g())\n"
3419
+
" w = true;\n"
3420
+
" if (w)\n"
3421
+
" p = q;\n"
3422
+
" }\n"
3423
+
" use(*p);\n"
3424
+
"}\n");
3425
+
ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:11:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n",
3426
+
errout_str());
3427
+
3428
+
check("bool g();\n"// the path that keeps p returns
Copy file name to clipboardExpand all lines: test/testother.cpp
+64Lines changed: 64 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -973,6 +973,70 @@ class TestOther : public TestFixture {
973
973
TODO_ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:12:15]: (warning) Either the condition 'a==0' is redundant or there is division by zero at line 12. [zerodivcond]\n",
974
974
"",
975
975
errout_str());
976
+
977
+
// the path that sets w changes a, the other path keeps it
978
+
check("bool g();\n"
979
+
"int f(int a) {\n"
980
+
" if (a == 0) {\n"
981
+
" bool w = false;\n"
982
+
" if (g())\n"
983
+
" w = true;\n"
984
+
" if (w)\n"
985
+
" a = 1;\n"
986
+
" }\n"
987
+
" return 10 / a;\n"
988
+
"}\n");
989
+
ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:10:15]: (warning) Either the condition 'a==0' is redundant or there is division by zero at line 10. [zerodivcond]\n",
990
+
errout_str());
991
+
992
+
check("bool g();\n" // the path that keeps a goes through an else block
993
+
"bool h();\n"
994
+
"int f(int a) {\n"
995
+
" if (a == 0) {\n"
996
+
" bool w = false;\n"
997
+
" if (g())\n"
998
+
" w = true;\n"
999
+
" if (w) {\n"
1000
+
" a = 1;\n"
1001
+
" } else {\n"
1002
+
" if (h())\n"
1003
+
" return 0;\n"
1004
+
" }\n"
1005
+
" }\n"
1006
+
" return 10 / a;\n"
1007
+
"}\n");
1008
+
ASSERT_EQUALS("[test.cpp:4:11] -> [test.cpp:15:15]: (warning) Either the condition 'a==0' is redundant or there is division by zero at line 15. [zerodivcond]\n",
1009
+
errout_str());
1010
+
1011
+
check("bool g();\n" // the path that keeps a returns
0 commit comments