checkIntegerOverflow: check all calculations, not only in function bodies

This commit is contained in:
Daniel Marjamäki 2017-09-19 14:43:48 +02:00
parent 6bc0df2908
commit cac7146cac
2 changed files with 20 additions and 22 deletions

View File

@ -145,11 +145,7 @@ void CheckType::checkIntegerOverflow()
// max int value according to platform settings.
const MathLib::bigint maxint = (1LL << (_settings->int_bit - 1)) - 1;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (!tok->isArithmeticalOp())
continue;
@ -172,7 +168,6 @@ void CheckType::checkIntegerOverflow()
integerOverflowError(tok, *value);
}
}
}
void CheckType::integerOverflowError(const Token *tok, const ValueFlow::Value &value)
{

View File

@ -110,6 +110,9 @@ private:
settings.platform(Settings::Unix32);
settings.addEnabled("warning");
check("x = (int)0x10000 * (int)0x10000;", &settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Signed integer overflow for expression '(int)65536*(int)65536'.\n", errout.str());
check("void foo() {\n"
" int intmax = 0x7fffffff;\n"
" return intmax + 1;\n"