CheckBool::checkAssignBoolToFloat() - don't crash on unknown variables
This commit is contained in:
parent
38aaa46804
commit
e6a394d514
|
@ -485,8 +485,8 @@ void CheckBool::checkAssignBoolToFloat()
|
|||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||
if (Token::Match(tok, "!!* %var% = %bool% ;")) {
|
||||
const Variable *var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
|
||||
if (var->isFloatingType())
|
||||
const Variable * const var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
|
||||
if (var && var->isFloatingType())
|
||||
assignBoolToFloatError(tok->next());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,12 @@ private:
|
|||
" long double d = (2>1);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", "", errout.str());
|
||||
|
||||
// stability - don't crash:
|
||||
check("void foo4() {\n"
|
||||
" unknown = false;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void comparisonOfBoolExpressionWithInt1() {
|
||||
|
|
Loading…
Reference in New Issue