checkSignConversion: check all calculations, not only in function bodies
This commit is contained in:
parent
f6e30eee19
commit
9268c2034a
|
@ -210,11 +210,7 @@ void CheckType::checkSignConversion()
|
|||
if (!_settings->isEnabled(Settings::WARNING))
|
||||
return;
|
||||
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (!tok->isArithmeticalOp() || Token::Match(tok,"+|-"))
|
||||
continue;
|
||||
|
||||
|
@ -238,7 +234,6 @@ void CheckType::checkSignConversion()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckType::signConversionError(const Token *tok, const bool constvalue)
|
||||
{
|
||||
|
|
|
@ -148,6 +148,9 @@ private:
|
|||
}
|
||||
|
||||
void signConversion() {
|
||||
check("x = -4 * (unsigned)y;");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious code: sign conversion of -4 in calculation because '-4' has a negative value\n", errout.str());
|
||||
|
||||
check("unsigned int f1(signed int x, unsigned int y) {" // x is signed
|
||||
" return x * y;\n"
|
||||
"}\n"
|
||||
|
|
Loading…
Reference in New Issue