Fix 10284: False positive; valueFlowBeforeCondition does not seem to care about increment (#3287)
This commit is contained in:
parent
a14922ed85
commit
668b88d7c0
|
@ -2034,7 +2034,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
|||
}
|
||||
|
||||
// increment/decrement
|
||||
if (Token::Match(tok->previous(), "++|-- %name%") || Token::Match(tok, "%name% ++|--")) {
|
||||
if (Token::Match(tok->astParent(), "++|--")) {
|
||||
return Action::Read | Action::Write | Action::Incremental;
|
||||
}
|
||||
return Action::None;
|
||||
|
|
|
@ -133,6 +133,7 @@ private:
|
|||
TEST_CASE(array_index_53); // #4750
|
||||
TEST_CASE(array_index_54); // #10268
|
||||
TEST_CASE(array_index_55); // #10254
|
||||
TEST_CASE(array_index_56); // #10284
|
||||
TEST_CASE(array_index_57); // #10023
|
||||
TEST_CASE(array_index_multidim);
|
||||
TEST_CASE(array_index_switch_in_for);
|
||||
|
@ -1594,6 +1595,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_56() {
|
||||
check("struct s {\n"
|
||||
" int array[1];\n"
|
||||
" int index;\n"
|
||||
"};\n"
|
||||
"void f(struct s foo) {\n"
|
||||
" foo.array[foo.index++] = 1;\n"
|
||||
" if (foo.index == 1) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_57() {
|
||||
check("void f(std::vector<int>& v) {\n"
|
||||
" int a[3] = { 1, 2, 3 };\n"
|
||||
|
|
Loading…
Reference in New Issue