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
10 changes: 10 additions & 0 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
pm.setValue(vartok, execute(valuetok, pm, settings));
}
}
} else if (Token::simpleMatch(tok2, ")") && tok2->link() &&
Token::Match(tok2->link()->previous(), "assert|ASSERT ( !!)")) {
const Token* cond = tok2->link()->astOperand2();
if (!conditionIsTrue(cond, state, settings)) {
// TODO: change to assert when we can propagate the assert, for now just bail
if (conditionIsFalse(cond, state, settings))
return;
programMemoryParseCondition(pm, cond, nullptr, settings, true);
}
tok2 = tok2->link()->previous();
} else if (tok2->exprId() > 0 && Token::Match(tok2, ".|(|[|*|%var%") && !pm.hasValue(tok2->exprId()) &&
isVariableChanged(tok2, 0, settings)) {
pm.setUnknown(tok2);
Expand Down
10 changes: 10 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7667,6 +7667,16 @@ class TestUninitVar : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3:24]: (error) Uninitialized variable: b [uninitvar]\n", errout_str());

// #14137
valueFlowUninit("int f(int n) {\n"
" int x;\n"
" assert(n > 0);\n"
" for(int i=0;i<n;i++)\n"
" x = n;\n"
" return x;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void uninitvar_memberfunction() {
Expand Down