Fix issue 9120: crash in valueflow (#1822)

This commit is contained in:
Paul Fultz II 2019-05-05 02:51:36 -05:00 committed by Daniel Marjamäki
parent 0b3342abe5
commit a688df0ea1
3 changed files with 17 additions and 0 deletions

View File

@ -981,6 +981,13 @@ public:
/** Add token value. Return true if value is added. */
bool addValue(const ValueFlow::Value &value);
template<class Predicate>
void removeValues(Predicate pred)
{
if (mImpl->mValues)
mImpl->mValues->remove_if(pred);
}
private:
void next(Token *nextToken) {

View File

@ -4997,7 +4997,10 @@ static void valueFlowSmartPointer(TokenList *tokenlist, ErrorLogger * errorLogge
values.push_back(v);
valueFlowForwardAssign(tok->tokAt(4), var, values, false, false, tokenlist, errorLogger, settings);
} else {
tok->removeValues(std::mem_fn(&ValueFlow::Value::isIntValue));
const Token * inTok = tok->tokAt(3)->astOperand2();
if (!inTok)
continue;
std::list<ValueFlow::Value> values = inTok->values();
const bool constValue = inTok->isNumber();
valueFlowForwardAssign(const_cast<Token *>(inTok), var, values, constValue, false, tokenlist, errorLogger, settings);

View File

@ -2332,6 +2332,13 @@ private:
" dostuff(p->x);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
check("struct A {};\n"
"void f(int n) {\n"
" std::unique_ptr<const A*[]> p;\n"
" p.reset(new const A*[n]);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void functioncall() { // #3443 - function calls