Check pointers for NULL before utilizing and do not check it later
This commit is contained in:
parent
7a90b763f6
commit
2d0ecc08c1
|
@ -663,7 +663,7 @@ void CheckCondition::checkIncorrectLogicOperator()
|
||||||
|
|
||||||
// 'A && (!A || B)' is equivalent with 'A && B'
|
// 'A && (!A || B)' is equivalent with 'A && B'
|
||||||
// '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() == "&&") ||
|
||||||
(tok->str() == "&&" && tok->astOperand2()->str() == "||"))) {
|
(tok->str() == "&&" && tok->astOperand2()->str() == "||"))) {
|
||||||
const Token* tok2 = tok->astOperand2()->astOperand1();
|
const Token* tok2 = tok->astOperand2()->astOperand1();
|
||||||
|
|
|
@ -2583,6 +2583,8 @@ void Tokenizer::setVarIdClassDeclaration(Token * const startToken,
|
||||||
bool initList = false;
|
bool initList = false;
|
||||||
const Token *initListArgLastToken = nullptr;
|
const Token *initListArgLastToken = nullptr;
|
||||||
for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) {
|
for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) {
|
||||||
|
if (!tok)
|
||||||
|
syntaxError(nullptr); // #7089 invalid code
|
||||||
if (initList) {
|
if (initList) {
|
||||||
if (tok == initListArgLastToken)
|
if (tok == initListArgLastToken)
|
||||||
initListArgLastToken = nullptr;
|
initListArgLastToken = nullptr;
|
||||||
|
@ -2591,8 +2593,6 @@ void Tokenizer::setVarIdClassDeclaration(Token * const startToken,
|
||||||
Token::Match(tok->link(), "}|) ,|{"))
|
Token::Match(tok->link(), "}|) ,|{"))
|
||||||
initListArgLastToken = tok->link();
|
initListArgLastToken = tok->link();
|
||||||
}
|
}
|
||||||
if (!tok)
|
|
||||||
syntaxError(nullptr); // #7089 invalid code
|
|
||||||
if (tok->str() == "{") {
|
if (tok->str() == "{") {
|
||||||
if (initList && !initListArgLastToken)
|
if (initList && !initListArgLastToken)
|
||||||
initList = false;
|
initList = false;
|
||||||
|
|
|
@ -744,6 +744,9 @@ static void valueFlowReverse(TokenList *tokenlist,
|
||||||
{
|
{
|
||||||
const MathLib::bigint num = val.intvalue;
|
const MathLib::bigint num = val.intvalue;
|
||||||
const Variable * const var = varToken->variable();
|
const Variable * const var = varToken->variable();
|
||||||
|
if (!var)
|
||||||
|
return;
|
||||||
|
|
||||||
const unsigned int varid = varToken->varId();
|
const unsigned int varid = varToken->varId();
|
||||||
const Token * const startToken = var->nameToken();
|
const Token * const startToken = var->nameToken();
|
||||||
|
|
||||||
|
@ -811,7 +814,7 @@ static void valueFlowReverse(TokenList *tokenlist,
|
||||||
setTokenValue(tok2, val);
|
setTokenValue(tok2, val);
|
||||||
if (val2.condition)
|
if (val2.condition)
|
||||||
setTokenValue(tok2,val2);
|
setTokenValue(tok2,val2);
|
||||||
if (var && tok2 == var->nameToken())
|
if (tok2 == var->nameToken())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -833,8 +836,7 @@ static void valueFlowReverse(TokenList *tokenlist,
|
||||||
if (vartok) {
|
if (vartok) {
|
||||||
if (settings->debugwarnings) {
|
if (settings->debugwarnings) {
|
||||||
std::string errmsg = "variable ";
|
std::string errmsg = "variable ";
|
||||||
if (var)
|
errmsg += var->name() + " ";
|
||||||
errmsg += var->name() + " ";
|
|
||||||
errmsg += "stopping on }";
|
errmsg += "stopping on }";
|
||||||
bailout(tokenlist, errorLogger, tok2, errmsg);
|
bailout(tokenlist, errorLogger, tok2, errmsg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue