Fixed crash on garbage code (#7120)

This commit is contained in:
PKEuS 2015-11-09 17:25:20 +01:00
parent 389d30fe44
commit f15f8514f6
2 changed files with 7 additions and 2 deletions

View File

@ -517,7 +517,7 @@ void CheckOther::checkRedundantAssignment()
}
std::map<unsigned int, const Token*>::iterator it = varAssignments.find(tok->varId());
if (tok->next()->isAssignmentOp() && Token::Match(startToken, "[;{}]")) { // Assignment
if (tok->next() && tok->next()->isAssignmentOp() && Token::Match(startToken, "[;{}]")) { // Assignment
if (it != varAssignments.end()) {
bool error = true; // Ensure that variable is not used on right side
for (const Token* tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
@ -550,7 +550,7 @@ void CheckOther::checkRedundantAssignment()
varAssignments[tok->varId()] = tok;
memAssignments.erase(tok->varId());
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
} else if (tok->next()->tokType() == Token::eIncDecOp || (tok->previous()->tokType() == Token::eIncDecOp && tok->strAt(1) == ";")) { // Variable incremented/decremented; Prefix-Increment is only suspicious, if its return value is unused
} else if (tok->next() && tok->next()->tokType() == Token::eIncDecOp || (tok->previous()->tokType() == Token::eIncDecOp && tok->strAt(1) == ";")) { // Variable incremented/decremented; Prefix-Increment is only suspicious, if its return value is unused
varAssignments[tok->varId()] = tok;
memAssignments.erase(tok->varId());
eraseMemberAssignments(tok->varId(), membervars, varAssignments);

View File

@ -204,6 +204,7 @@ private:
TEST_CASE(garbageCode153);
TEST_CASE(garbageCode154); // #7112
TEST_CASE(garbageCode155); // #7118
TEST_CASE(garbageCode156); // #7120
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -1227,6 +1228,10 @@ private:
checkCode("&p(!{}e x){({(0?:?){({})}()})}");
}
void garbageCode156() { // #7120
checkCode("struct {}a; d f() { c ? : } {}a.p");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"