Fix issue 6850: Valueflow: pointer alias, conditional value (#2402)
This commit is contained in:
parent
91dd8d3b6f
commit
79a2e61721
|
@ -1698,6 +1698,9 @@ static void valueFlowReverse(TokenList *tokenlist,
|
|||
tokenlist,
|
||||
errorLogger,
|
||||
settings);
|
||||
// Only reverse analysis supported with variables
|
||||
if (assignTok->varId() > 0)
|
||||
valueFlowReverse(tokenlist, tok2->previous(), assignTok, val, val2, errorLogger, settings);
|
||||
}
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist, errorLogger, tok2, "assignment of " + tok2->str());
|
||||
|
|
|
@ -85,6 +85,7 @@ private:
|
|||
TEST_CASE(nullpointer43); // #9404
|
||||
TEST_CASE(nullpointer44); // #9395, #9423
|
||||
TEST_CASE(nullpointer45);
|
||||
TEST_CASE(nullpointer46); // #6850
|
||||
TEST_CASE(nullpointer_addressOf); // address of
|
||||
TEST_CASE(nullpointerSwitch); // #2626
|
||||
TEST_CASE(nullpointer_cast); // #4692
|
||||
|
@ -1613,6 +1614,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer46() {
|
||||
check("void f(int *p) {\n"
|
||||
" if(!p[0]) {}\n"
|
||||
" const int *const a = p;\n"
|
||||
" if(!a){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p.\n", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer_addressOf() { // address of
|
||||
check("void f() {\n"
|
||||
" struct X *x = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue