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/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2986,7 +2986,7 @@ bool isVariablesChanged(const Token* start,
const bool globalvar = std::any_of(vars.cbegin(), vars.cend(), [](const Variable* var) {
return var->isGlobal();
});
for (const Token* tok = start; tok != end; tok = tok->next()) {
for (const Token* tok = start; tok && tok != end; tok = tok->next()) {
if (tok->varId() == 0 || varids.count(tok->varId()) == 0) {
if (globalvar && Token::Match(tok, "%name% ("))
// TODO: Is global variable really changed by function call?
Expand Down
4 changes: 3 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,9 @@ bool Variable::isUnsigned() const
const Token * Variable::declEndToken() const
{
Token const * declEnd = typeStartToken();
while (declEnd && !Token::Match(declEnd, "[;,)={]")) {
if (declEnd->tokAt(-1) && Token::simpleMatch(declEnd->tokAt(-2), "for ("))
declEnd = nameToken();
while (declEnd && !Token::Match(declEnd, "[;:,)={]")) {
if (declEnd->link() && Token::Match(declEnd,"(|[|<"))
declEnd = declEnd->link();
declEnd = declEnd->next();
Expand Down
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,8 @@ struct LifetimeStore {
if (!var)
continue;
const Token * const varDeclEndToken = var->declEndToken();
if (!varDeclEndToken)
continue;
for (const Token *tok3 = tok; tok3 && tok3 != varDeclEndToken; tok3 = tok3->previous()) {
if (tok3->varId() == var->declarationId()) {
update |= LifetimeStore{tok3, message, type, inconclusive}
Expand Down
11 changes: 11 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7820,6 +7820,17 @@ class TestOther : public TestFixture {
" for (; t && t->str() == s; t = t->next());\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(std::string &out, const std::vector<std::string> &list) {\n" // #13669
" for (int i = 0, size = list.size(); i < size; i++) {\n"
" out += list[i];\n"
" if (size > 0 && i < (size - 2))\n"
" out += \",\";\n"
" else if (i == (size - 1))\n"
" out += \".\";\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void duplicateExpressionTernary() { // #6391
Expand Down