diff --git a/lib/checktype.cpp b/lib/checktype.cpp index d97bad519..5eacee222 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -132,7 +132,7 @@ void CheckType::checkIntegerOverflow() const ValueFlow::Value *value = tok->getValueGE(maxint + 1, _settings); if (!value) value = tok->getValueLE(-maxint - 2, _settings); - if (!value) + if (!value || !_settings->isEnabled(value,false)) continue; // For left shift, it's common practice to shift into the sign bit @@ -155,7 +155,7 @@ void CheckType::integerOverflowError(const Token *tok, const ValueFlow::Value &v else msg = "Signed integer overflow for expression '" + expr + "'."; - reportError(tok, + reportError(getErrorPath(tok, &value, "Integer overflow"), value.condition ? Severity::warning : Severity::error, "integerOverflow", msg, diff --git a/test/testtype.cpp b/test/testtype.cpp index 22684983a..fb9da76ab 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -124,13 +124,13 @@ private: " if (x==123456) {}\n" " return x * x;\n" "}",&settings); - ASSERT_EQUALS("[test.cpp:3]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression 'x*x'.\n", errout.str()); check("int foo(signed int x) {\n" " if (x==123456) {}\n" " return -123456 * x;\n" "}",&settings); - ASSERT_EQUALS("[test.cpp:3]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression '-123456*x'.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition 'x==123456' is redundant or there is signed integer overflow for expression '-123456*x'.\n", errout.str()); check("int foo(signed int x) {\n" " if (x==123456) {}\n"