Skip to content

Commit e6a394d

Browse files
committed
CheckBool::checkAssignBoolToFloat() - don't crash on unknown variables
1 parent 38aaa46 commit e6a394d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/checkbool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ void CheckBool::checkAssignBoolToFloat()
485485
const Scope * scope = symbolDatabase->functionScopes[i];
486486
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
487487
if (Token::Match(tok, "!!* %var% = %bool% ;")) {
488-
const Variable *var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
489-
if (var->isFloatingType())
488+
const Variable * const var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
489+
if (var && var->isFloatingType())
490490
assignBoolToFloatError(tok->next());
491491
}
492492
}

test/testbool.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ class TestBool : public TestFixture {
155155
" long double d = (2>1);\n"
156156
"}");
157157
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Boolean value assigned to floating point variable.\n", "", errout.str());
158+
159+
// stability - don't crash:
160+
check("void foo4() {\n"
161+
" unknown = false;\n"
162+
"}");
163+
ASSERT_EQUALS("", errout.str());
158164
}
159165

160166
void comparisonOfBoolExpressionWithInt1() {

0 commit comments

Comments
 (0)