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);
|
||||
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,
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue