checkFloatToIntegerOverflow: check all calculations, not only in function bodies

This commit is contained in:
Daniel Marjamäki 2017-09-19 19:30:24 +02:00
parent 9268c2034a
commit 840c7eb258
2 changed files with 51 additions and 53 deletions

View File

@ -344,11 +344,7 @@ void CheckType::longCastReturnError(const Token *tok)
void CheckType::checkFloatToIntegerOverflow()
{
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()) {
const ValueType *vtint, *vtfloat;
const std::list<ValueFlow::Value> *floatValues;
@ -405,7 +401,6 @@ void CheckType::checkFloatToIntegerOverflow()
}
}
}
}
}
void CheckType::floatToIntegerOverflowError(const Token *tok, const ValueFlow::Value &value)

View File

@ -235,6 +235,9 @@ private:
}
void checkFloatToIntegerOverflow() {
check("x = (int)1E100;");
ASSERT_EQUALS("[test.cpp:1]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
check("void f(void) {\n"
" return (int)1E100;\n"
"}\n");