Fix issue 9701: False positive. 3rd expression in for uses comma operator. (#2664)
This commit is contained in:
parent
27fc5f1a2f
commit
c9798590ba
|
@ -1876,6 +1876,8 @@ static void valueFlowReverse(TokenList *tokenlist,
|
|||
break;
|
||||
} else {
|
||||
tok2 = tok2->link();
|
||||
if (Token::simpleMatch(tok2->previous(), ") {") && Token::Match(tok2->previous()->link()->previous(), "for|while ("))
|
||||
tok2 = tok2->previous()->link();
|
||||
}
|
||||
} else if (tok2->str() == "{") {
|
||||
// if variable is assigned in loop don't look before the loop
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
TEST_CASE(nullpointer53); // #8005
|
||||
TEST_CASE(nullpointer54); // #9573
|
||||
TEST_CASE(nullpointer55); // #8144
|
||||
TEST_CASE(nullpointer56); // #9701
|
||||
TEST_CASE(nullpointer_addressOf); // address of
|
||||
TEST_CASE(nullpointerSwitch); // #2626
|
||||
TEST_CASE(nullpointer_cast); // #4692
|
||||
|
@ -1811,6 +1812,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer56() {
|
||||
check("struct ListEntry {\n"
|
||||
" struct ListEntry *next;\n"
|
||||
"};\n"
|
||||
"static void dostuff(ListEntry * listHead) {\n"
|
||||
" ListEntry *prev = NULL;\n"
|
||||
" for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\n"
|
||||
" if (prev) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer_addressOf() { // address of
|
||||
check("void f() {\n"
|
||||
" struct X *x = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue