Fix 10284: False positive; valueFlowBeforeCondition does not seem to care about increment (#3287)

This commit is contained in:
Paul Fultz II 2021-06-04 14:40:57 -05:00 committed by GitHub
parent a14922ed85
commit 668b88d7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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;

View File

@ -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"