Clarify integerOverflow messages
This commit is contained in:
parent
9374055238
commit
0cb1c4f221
@ -132,7 +132,7 @@ void CheckType::checkIntegerOverflow()
|
|||||||
const ValueFlow::Value *value = tok->getValueGE(maxint + 1, _settings);
|
const ValueFlow::Value *value = tok->getValueGE(maxint + 1, _settings);
|
||||||
if (!value)
|
if (!value)
|
||||||
value = tok->getValueLE(-maxint - 2, _settings);
|
value = tok->getValueLE(-maxint - 2, _settings);
|
||||||
if (!value)
|
if (!value || !_settings->isEnabled(value,false))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// For left shift, it's common practice to shift into the sign bit
|
// 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
|
else
|
||||||
msg = "Signed integer overflow for expression '" + expr + "'.";
|
msg = "Signed integer overflow for expression '" + expr + "'.";
|
||||||
|
|
||||||
reportError(tok,
|
reportError(getErrorPath(tok, &value, "Integer overflow"),
|
||||||
value.condition ? Severity::warning : Severity::error,
|
value.condition ? Severity::warning : Severity::error,
|
||||||
"integerOverflow",
|
"integerOverflow",
|
||||||
msg,
|
msg,
|
||||||
|
@ -124,13 +124,13 @@ private:
|
|||||||
" if (x==123456) {}\n"
|
" if (x==123456) {}\n"
|
||||||
" return x * x;\n"
|
" return x * x;\n"
|
||||||
"}",&settings);
|
"}",&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"
|
check("int foo(signed int x) {\n"
|
||||||
" if (x==123456) {}\n"
|
" if (x==123456) {}\n"
|
||||||
" return -123456 * x;\n"
|
" return -123456 * x;\n"
|
||||||
"}",&settings);
|
"}",&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"
|
check("int foo(signed int x) {\n"
|
||||||
" if (x==123456) {}\n"
|
" if (x==123456) {}\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user