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: | run: |
./testrunner ./testrunner
- name: checkcfg - name: Bughunting lib
run: | 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) static ExprEngine::ValuePtr executeArrayIndex(const Token *tok, Data &data)
{ {
if (tok->tokType() == Token::eLambda)
throw ExprEngineException(tok, "FIXME: lambda");
const Token *tok2 = tok; const Token *tok2 = tok;
while (Token::simpleMatch(tok2->astOperand1(), "[")) while (Token::simpleMatch(tok2->astOperand1(), "["))
tok2 = 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.valueType = ValueFlow::Value::FLOAT;
result.floatValue = floatValue1 - floatValue2; result.floatValue = floatValue1 - floatValue2;
} else { } else {
// Avoid overflow
if (value1.intvalue < 0 && value2.intvalue > value1.intvalue - LLONG_MIN)
break;
result.intvalue = value1.intvalue - value2.intvalue; result.intvalue = value1.intvalue - value2.intvalue;
} }
// If the bound comes from the second value then invert the bound // 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()) if (!val.isIntValue() && !val.isFloatValue())
continue; continue;
ValueFlow::Value v(val); 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; v.intvalue = -v.intvalue;
}
else else
v.floatValue = -v.floatValue; v.floatValue = -v.floatValue;
v.invertBound(); v.invertBound();