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);
|
mValues.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Settings* settings = nullptr);
|
||||||
|
|
||||||
static bool evaluateCondition(const std::string& op,
|
static bool evaluateCondition(const std::string& op,
|
||||||
MathLib::bigint r,
|
MathLib::bigint r,
|
||||||
const Token* condition,
|
const Token* condition,
|
||||||
|
@ -331,13 +333,7 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
|
||||||
}
|
}
|
||||||
if (!setvar) {
|
if (!setvar) {
|
||||||
if (!pm.hasValue(vartok->exprId())) {
|
if (!pm.hasValue(vartok->exprId())) {
|
||||||
MathLib::bigint result = 0;
|
pm.setValue(vartok, execute(valuetok, pm));
|
||||||
bool error = false;
|
|
||||||
execute(valuetok, &pm, &result, &error);
|
|
||||||
if (!error)
|
|
||||||
pm.setIntValue(vartok, result);
|
|
||||||
else
|
|
||||||
pm.setUnknown(vartok);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (tok2->exprId() > 0 && Token::Match(tok2, ".|(|[|*|%var%") && !pm.hasValue(tok2->exprId()) &&
|
} 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;
|
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)
|
static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const Settings* settings)
|
||||||
{
|
{
|
||||||
ValueFlow::Value unknown = ValueFlow::Value::unknown();
|
ValueFlow::Value unknown = ValueFlow::Value::unknown();
|
||||||
|
|
|
@ -844,6 +844,16 @@ private:
|
||||||
"const std::vector<int> A::v = {1, 2};\n");
|
"const std::vector<int> A::v = {1, 2};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void outOfBoundsSymbolic()
|
||||||
|
|
Loading…
Reference in New Issue