fix ubsan errors

This commit is contained in:
Daniel Marjamäki 2020-09-05 21:09:11 +02:00
parent 558090b3cb
commit b0b31feadd
3 changed files with 13 additions and 3 deletions

View File

@ -33,7 +33,7 @@ jobs:
run: |
./testrunner
- name: checkcfg
- name: Bughunting lib
run: |
make checkcfg
./cppcheck -D__CPPCHECK__ --bug-hunting -j$(nproc) lib

View File

@ -1910,6 +1910,8 @@ static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data)
static ExprEngine::ValuePtr executeArrayIndex(const Token *tok, Data &data)
{
if (tok->tokType() == Token::eLambda)
throw ExprEngineException(tok, "FIXME: lambda");
const Token *tok2 = tok;
while (Token::simpleMatch(tok2->astOperand1(), "["))
tok2 = tok2->astOperand1();

View File

@ -617,6 +617,10 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
result.valueType = ValueFlow::Value::FLOAT;
result.floatValue = floatValue1 - floatValue2;
} else {
// Avoid overflow
if (value1.intvalue < 0 && value2.intvalue > value1.intvalue - LLONG_MIN)
break;
result.intvalue = value1.intvalue - value2.intvalue;
}
// If the bound comes from the second value then invert the bound
@ -781,8 +785,12 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (!val.isIntValue() && !val.isFloatValue())
continue;
ValueFlow::Value v(val);
if (v.isIntValue())
if (v.isIntValue()) {
if (v.intvalue == LLONG_MIN)
// Value can't be inverted
continue;
v.intvalue = -v.intvalue;
}
else
v.floatValue = -v.floatValue;
v.invertBound();