minor refactoring, use 'else if' when appropriate

This commit is contained in:
Daniel Marjamäki 2016-01-06 15:49:44 +01:00
parent c70764631f
commit b2386fa011
1 changed files with 3 additions and 7 deletions

View File

@ -1470,8 +1470,7 @@ void CheckOther::checkCharVariable()
const Token *index = tok->next()->astOperand2(); const Token *index = tok->next()->astOperand2();
if (astIsSignedChar(index) && index->getValueGE(0x80, _settings)) if (astIsSignedChar(index) && index->getValueGE(0x80, _settings))
charArrayIndexError(tok); charArrayIndexError(tok);
} } else if (Token::Match(tok, "[&|^]") && tok->astOperand2() && tok->astOperand1()) {
if (Token::Match(tok, "[&|^]") && tok->astOperand2() && tok->astOperand1()) {
bool warn = false; bool warn = false;
if (astIsSignedChar(tok->astOperand1())) { if (astIsSignedChar(tok->astOperand1())) {
const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, _settings); const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, _settings);
@ -1480,8 +1479,7 @@ void CheckOther::checkCharVariable()
v1 = tok->astOperand1()->getValueGE(0x80, _settings); v1 = tok->astOperand1()->getValueGE(0x80, _settings);
if (v1 && !(tok->str() == "&" && v2 && v2->isKnown() && v2->intvalue >= 0 && v2->intvalue < 0x100)) if (v1 && !(tok->str() == "&" && v2 && v2->isKnown() && v2->intvalue >= 0 && v2->intvalue < 0x100))
warn = true; warn = true;
} } else if (!warn && astIsSignedChar(tok->astOperand2())) {
if (!warn && astIsSignedChar(tok->astOperand2())) {
const ValueFlow::Value *v1 = tok->astOperand2()->getValueLE(-1, _settings); const ValueFlow::Value *v1 = tok->astOperand2()->getValueLE(-1, _settings);
const ValueFlow::Value *v2 = tok->astOperand1()->getMaxValue(false); const ValueFlow::Value *v2 = tok->astOperand1()->getMaxValue(false);
if (!v1) if (!v1)
@ -1489,11 +1487,9 @@ void CheckOther::checkCharVariable()
if (v1 && !(tok->str() == "&" && v2 && v2->isKnown() && v2->intvalue >= 0 && v2->intvalue < 0x100)) if (v1 && !(tok->str() == "&" && v2 && v2->isKnown() && v2->intvalue >= 0 && v2->intvalue < 0x100))
warn = true; warn = true;
} }
if (!warn)
continue;
// is the result stored in a short|int|long? // is the result stored in a short|int|long?
if (Token::simpleMatch(tok->astParent(), "=")) { if (warn && Token::simpleMatch(tok->astParent(), "=")) {
const Token *lhs = tok->astParent()->astOperand1(); const Token *lhs = tok->astParent()->astOperand1();
if (lhs && lhs->valueType() && lhs->valueType()->type >= ValueType::Type::SHORT) if (lhs && lhs->valueType() && lhs->valueType()->type >= ValueType::Type::SHORT)
charBitOpError(tok); // This is an error.. charBitOpError(tok); // This is an error..