Fixed #7807 (false positive: (error) Signed integer overflow for expression 'int32_max-1'.)

This commit is contained in:
Daniel Marjamäki 2016-11-07 22:29:40 +01:00
parent 1245f1d621
commit 4de5dc75aa
2 changed files with 7 additions and 1 deletions

View File

@ -117,7 +117,7 @@ void CheckType::checkIntegerOverflow()
return;
// max int value according to platform settings.
const MathLib::bigint maxint = (1LL << (_settings->int_bit - 2)) - 1;
const MathLib::bigint maxint = (1LL << (_settings->int_bit - 1)) - 1;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();

View File

@ -113,6 +113,12 @@ private:
"}",&settings);
ASSERT_EQUALS("[test.cpp:3]: (error) Signed integer overflow for expression 'intmax+1'.\n", errout.str());
check("void foo() {\n"
" int intmax = 0x7fffffff;\n"
" return intmax - 1;\n"
"}",&settings);
ASSERT_EQUALS("", errout.str());
check("int foo(signed int x) {\n"
" if (x==123456) {}\n"
" return x * x;\n"