Minor tweaks for new CheckOther::checkIntegerOverflow checker

This commit is contained in:
Daniel Marjamäki 2014-09-10 17:26:20 +02:00
parent 974c8688c3
commit a46f5c00a8
1 changed files with 11 additions and 9 deletions

View File

@ -2799,6 +2799,9 @@ void CheckOther::checkIntegerOverflow()
if (_settings->platformType == Settings::Unspecified)
return;
// max int value according to platform settings.
const MathLib::bigint maxint = (1LL << (8 * _settings->sizeof_int - 1)) - 1;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
@ -2807,6 +2810,13 @@ void CheckOther::checkIntegerOverflow()
if (!tok->isArithmeticalOp())
continue;
// is there a overflow result value
const ValueFlow::Value *value = tok->getValueGE(maxint + 1, _settings);
if (!value)
value = tok->getValueLE(-maxint - 2, _settings);
if (!value)
continue;
// get size and sign of result..
int size = 0;
char sign = 0;
@ -2815,15 +2825,7 @@ void CheckOther::checkIntegerOverflow()
if (sign != 's') // only signed integer overflow is UB
continue;
// max int value according to platform settings.
const MathLib::bigint maxint = (1LL << 8 * (_settings->sizeof_int - 1)) - 1;
// is there a overflow result value
const ValueFlow::Value *value = tok->getValueGE(maxint + 1, _settings);
if (!value)
value = tok->getValueLE(-maxint - 2, _settings);
if (value)
integerOverflowError(tok, *value);
integerOverflowError(tok, *value);
}
}
}