Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4531,7 +4531,7 @@ struct ConditionHandler {
}

// Variable changed in loop code
const Token* const start = top;
const Token* const start = top->strAt(-1) == "for" ? top->astOperand2() : top; // skip init statement
const Token* const block = top->link()->next();
const Token* const end = block->link();

Expand Down
6 changes: 6 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,12 @@ class TestStl : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:2:12] -> [test.cpp:4:21]: (warning) Either the condition 'col>textline.size()' is redundant or 'col' can have the value textline.size(). Expression 'textline[col]' causes access out of bounds. [containerOutOfBounds]\n",
errout_str());

check("void f(const std::vector<int>& v) {\n" // #12742
" for (unsigned i = 0; i < v.size();)\n"
" (void)v[i++];\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void outOfBoundsIndexExpression() {
Expand Down