Fixed crash on garbage code (#7120)
This commit is contained in:
parent
389d30fe44
commit
f15f8514f6
|
@ -517,7 +517,7 @@ void CheckOther::checkRedundantAssignment()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<unsigned int, const Token*>::iterator it = varAssignments.find(tok->varId());
|
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()) {
|
if (it != varAssignments.end()) {
|
||||||
bool error = true; // Ensure that variable is not used on right side
|
bool error = true; // Ensure that variable is not used on right side
|
||||||
for (const Token* tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
for (const Token* tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
||||||
|
@ -550,7 +550,7 @@ void CheckOther::checkRedundantAssignment()
|
||||||
varAssignments[tok->varId()] = tok;
|
varAssignments[tok->varId()] = tok;
|
||||||
memAssignments.erase(tok->varId());
|
memAssignments.erase(tok->varId());
|
||||||
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
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;
|
varAssignments[tok->varId()] = tok;
|
||||||
memAssignments.erase(tok->varId());
|
memAssignments.erase(tok->varId());
|
||||||
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
eraseMemberAssignments(tok->varId(), membervars, varAssignments);
|
||||||
|
|
|
@ -204,6 +204,7 @@ private:
|
||||||
TEST_CASE(garbageCode153);
|
TEST_CASE(garbageCode153);
|
||||||
TEST_CASE(garbageCode154); // #7112
|
TEST_CASE(garbageCode154); // #7112
|
||||||
TEST_CASE(garbageCode155); // #7118
|
TEST_CASE(garbageCode155); // #7118
|
||||||
|
TEST_CASE(garbageCode156); // #7120
|
||||||
|
|
||||||
TEST_CASE(garbageValueFlow);
|
TEST_CASE(garbageValueFlow);
|
||||||
TEST_CASE(garbageSymbolDatabase);
|
TEST_CASE(garbageSymbolDatabase);
|
||||||
|
@ -1227,6 +1228,10 @@ private:
|
||||||
checkCode("&p(!{}e x){({(0?:?){({})}()})}");
|
checkCode("&p(!{}e x){({(0?:?){({})}()})}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void garbageCode156() { // #7120
|
||||||
|
checkCode("struct {}a; d f() { c ? : } {}a.p");
|
||||||
|
}
|
||||||
|
|
||||||
void garbageValueFlow() {
|
void garbageValueFlow() {
|
||||||
// #6089
|
// #6089
|
||||||
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
||||||
|
|
Loading…
Reference in New Issue