From ac42382cd924627a5af468f8c55bca6f0931cf03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 9 Mar 2019 19:15:06 +0100 Subject: [PATCH] Rewrite CheckBool::checkAssignBoolToPointer to use ValueType --- lib/checkbool.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 30fbb06c0..18fa4625c 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -293,15 +293,16 @@ void CheckBool::checkAssignBoolToPointer() const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { - if (tok->str() == "=" && astIsBool(tok->astOperand2())) { - const Token *lhs = tok->astOperand1(); - while (lhs && (lhs->str() == "." || lhs->str() == "::")) - lhs = lhs->astOperand2(); - if (!lhs || !lhs->variable() || !lhs->variable()->isPointer()) - continue; + if (tok->str() != "=") + continue; + const ValueType *lhsType = tok->astOperand1() ? tok->astOperand1()->valueType() : nullptr; + if (!lhsType || lhsType->pointer == 0) + continue; + const ValueType *rhsType = tok->astOperand2() ? tok->astOperand2()->valueType() : nullptr; + if (!rhsType || rhsType->pointer > 0 || rhsType->type != ValueType::Type::BOOL) + continue; - assignBoolToPointerError(tok); - } + assignBoolToPointerError(tok); } } }