Check pointers for NULL before utilizing and do not check it later

This commit is contained in:
Aleksandr Pikalev 2015-11-05 21:27:10 +03:00 committed by PKEuS
parent 7a90b763f6
commit 2d0ecc08c1
3 changed files with 8 additions and 6 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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);
}