10062: Fix FP due to assignment in reverseanalyzer (#2983)

reverseanalyzer has a special process for assignments, and would not see
a stop condition on a rhs of an assignment.
This commit is contained in:
Ken-Patrick Lehrmann 2020-12-27 10:14:46 +01:00 committed by GitHub
parent 30fbded406
commit f1169bf2b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -177,7 +177,9 @@ struct ReverseTraversal {
} }
if (!continueB) if (!continueB)
break; break;
valueFlowGenericForward(assignTop->astOperand2(), analyzer, settings); Analyzer::Action a = valueFlowGenericForward(assignTop->astOperand2(), analyzer, settings);
if (a.isModified())
break;
tok = previousBeforeAstLeftmostLeaf(assignTop)->next(); tok = previousBeforeAstLeftmostLeaf(assignTop)->next();
continue; continue;
} }

View File

@ -107,6 +107,7 @@ private:
TEST_CASE(nullpointer64); TEST_CASE(nullpointer64);
TEST_CASE(nullpointer65); // #9980 TEST_CASE(nullpointer65); // #9980
TEST_CASE(nullpointer66); // #10024 TEST_CASE(nullpointer66); // #10024
TEST_CASE(nullpointer67); // #10062
TEST_CASE(nullpointer_addressOf); // address of TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626 TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692 TEST_CASE(nullpointer_cast); // #4692
@ -2050,6 +2051,33 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void nullpointer67() {
check("int result;\n"
"\n"
"int test_b(void) {\n"
" char **string = NULL;\n"
"\n"
" /* The bug disappears if \"result =\" is omitted. */\n"
" result = some_other_call(&string);\n"
" if (string && string[0])\n"
" return 0;\n"
" return -1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("int result;\n"
"\n"
"int test_b(void) {\n"
" char **string = NULL;\n"
"\n"
" some_other_call(&string);\n"
" if (string && string[0])\n"
" return 0;\n"
" return -1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_addressOf() { // address of void nullpointer_addressOf() { // address of
check("void f() {\n" check("void f() {\n"
" struct X *x = 0;\n" " struct X *x = 0;\n"