Fix issue 9980: FP nullPointerRedundantCheck - condition after while loop (#2912)

This commit is contained in:
Paul Fultz II 2020-11-20 02:36:09 -06:00 committed by GitHub
parent 317a2d039f
commit f6399c4cba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -173,7 +173,7 @@ struct ReverseTraversal {
if (!continueB)
break;
valueFlowGenericForward(assignTop->astOperand2(), analyzer, settings);
tok = previousBeforeAstLeftmostLeaf(assignTop);
tok = previousBeforeAstLeftmostLeaf(assignTop)->next();
continue;
}
if (tok->str() == "}") {

View File

@ -105,6 +105,7 @@ private:
TEST_CASE(nullpointer62);
TEST_CASE(nullpointer63);
TEST_CASE(nullpointer64);
TEST_CASE(nullpointer65); // #9980
TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692
@ -2011,6 +2012,26 @@ private:
ASSERT_EQUALS("", errout.str());
}
void nullpointer65() {
check("struct A {\n"
" double get();\n"
"};\n"
"double x;\n"
"double run(A** begin, A** end) {\n"
" A* a = nullptr;\n"
" while (begin != end) {\n"
" a = *begin;\n"
" x = a->get();\n"
" ++begin;\n"
" }\n"
" x = 0;\n"
" if (a)\n"
" return a->get();\n"
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_addressOf() { // address of
check("void f() {\n"
" struct X *x = 0;\n"