Fix 11027: False positive: containerOutOfBounds from condition in assert (#4084)
* Fix 11027: False positive: containerOutOfBounds from condition in assert * Format
This commit is contained in:
parent
5afd6880c3
commit
8d16ee946c
|
@ -193,6 +193,8 @@ void ProgramMemory::insert(const ProgramMemory &pm)
|
|||
mValues.insert(p);
|
||||
}
|
||||
|
||||
static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Settings* settings = nullptr);
|
||||
|
||||
static bool evaluateCondition(const std::string& op,
|
||||
MathLib::bigint r,
|
||||
const Token* condition,
|
||||
|
@ -331,13 +333,7 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
|
|||
}
|
||||
if (!setvar) {
|
||||
if (!pm.hasValue(vartok->exprId())) {
|
||||
MathLib::bigint result = 0;
|
||||
bool error = false;
|
||||
execute(valuetok, &pm, &result, &error);
|
||||
if (!error)
|
||||
pm.setIntValue(vartok, result);
|
||||
else
|
||||
pm.setUnknown(vartok);
|
||||
pm.setValue(vartok, execute(valuetok, pm));
|
||||
}
|
||||
}
|
||||
} else if (tok2->exprId() > 0 && Token::Match(tok2, ".|(|[|*|%var%") && !pm.hasValue(tok2->exprId()) &&
|
||||
|
@ -575,8 +571,6 @@ static ValueFlow::Value evaluate(const std::string& op, const ValueFlow::Value&
|
|||
return result;
|
||||
}
|
||||
|
||||
static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Settings* settings = nullptr);
|
||||
|
||||
static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const Settings* settings)
|
||||
{
|
||||
ValueFlow::Value unknown = ValueFlow::Value::unknown();
|
||||
|
|
|
@ -844,6 +844,16 @@ private:
|
|||
"const std::vector<int> A::v = {1, 2};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNormal("struct a {\n"
|
||||
" std::vector<int> g() const;\n"
|
||||
"};\n"
|
||||
"int f(const a& b) {\n"
|
||||
" auto c = b.g();\n"
|
||||
" assert(not c.empty());\n"
|
||||
" int d = c.front();\n"
|
||||
" return d;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void outOfBoundsSymbolic()
|
||||
|
|
Loading…
Reference in New Issue