diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 1b3451b36..148d02fc2 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index a574f4718..af07000ec 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -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& v) {\n" " int a[3] = { 1, 2, 3 };\n"