From 4de5dc75aaa8a9af6be7419cd64465057b1880d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 7 Nov 2016 22:29:40 +0100 Subject: [PATCH] Fixed #7807 (false positive: (error) Signed integer overflow for expression 'int32_max-1'.) --- lib/checktype.cpp | 2 +- test/testtype.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 956b3b434..01c371586 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -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(); diff --git a/test/testtype.cpp b/test/testtype.cpp index ec2bbdcb9..997fdf1b5 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -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"