diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index f1a42cef7..12fd8f86f 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -663,7 +663,7 @@ void CheckCondition::checkIncorrectLogicOperator() // 'A && (!A || B)' is equivalent with 'A && B' // 'A || (!A && B)' is equivalent with 'A || B' - if (printStyle && tok->astOperand1() && tok->astOperand2() && + if (printStyle && ((tok->str() == "||" && tok->astOperand2()->str() == "&&") || (tok->str() == "&&" && tok->astOperand2()->str() == "||"))) { const Token* tok2 = tok->astOperand2()->astOperand1(); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e2acc5b55..7ee748630 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2583,6 +2583,8 @@ void Tokenizer::setVarIdClassDeclaration(Token * const startToken, bool initList = false; const Token *initListArgLastToken = nullptr; for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) { + if (!tok) + syntaxError(nullptr); // #7089 invalid code if (initList) { if (tok == initListArgLastToken) initListArgLastToken = nullptr; @@ -2591,8 +2593,6 @@ void Tokenizer::setVarIdClassDeclaration(Token * const startToken, Token::Match(tok->link(), "}|) ,|{")) initListArgLastToken = tok->link(); } - if (!tok) - syntaxError(nullptr); // #7089 invalid code if (tok->str() == "{") { if (initList && !initListArgLastToken) initList = false; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 4ec4a651f..7c3bf53b1 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -744,6 +744,9 @@ static void valueFlowReverse(TokenList *tokenlist, { const MathLib::bigint num = val.intvalue; const Variable * const var = varToken->variable(); + if (!var) + return; + const unsigned int varid = varToken->varId(); const Token * const startToken = var->nameToken(); @@ -811,7 +814,7 @@ static void valueFlowReverse(TokenList *tokenlist, setTokenValue(tok2, val); if (val2.condition) setTokenValue(tok2,val2); - if (var && tok2 == var->nameToken()) + if (tok2 == var->nameToken()) break; } @@ -833,8 +836,7 @@ static void valueFlowReverse(TokenList *tokenlist, if (vartok) { if (settings->debugwarnings) { std::string errmsg = "variable "; - if (var) - errmsg += var->name() + " "; + errmsg += var->name() + " "; errmsg += "stopping on }"; bailout(tokenlist, errorLogger, tok2, errmsg); }