Fix crash with statement expression (#4142)
This commit is contained in:
parent
16af6561c2
commit
16a4449901
|
@ -442,7 +442,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check assignments in the if-statement. Skip multiple assignments since we don't track those
|
// Check assignments in the if-statement. Skip multiple assignments since we don't track those
|
||||||
if (Token::Match(innerTok, "%var% =") && innerTok->astParent() == innerTok->next() && !innerTok->next()->astParent()->isAssignmentOp()) {
|
if (Token::Match(innerTok, "%var% =") && innerTok->astParent() == innerTok->next() &&
|
||||||
|
!(innerTok->next()->astParent() && innerTok->next()->astParent()->isAssignmentOp())) {
|
||||||
// allocation?
|
// allocation?
|
||||||
// right ast part (after `=` operator)
|
// right ast part (after `=` operator)
|
||||||
const Token* tokRightAstOperand = innerTok->next()->astOperand2();
|
const Token* tokRightAstOperand = innerTok->next()->astOperand2();
|
||||||
|
|
|
@ -165,6 +165,7 @@ private:
|
||||||
TEST_CASE(ifelse23); // #5473
|
TEST_CASE(ifelse23); // #5473
|
||||||
TEST_CASE(ifelse24); // #1733
|
TEST_CASE(ifelse24); // #1733
|
||||||
TEST_CASE(ifelse25); // #9966
|
TEST_CASE(ifelse25); // #9966
|
||||||
|
TEST_CASE(ifelse26);
|
||||||
|
|
||||||
// switch
|
// switch
|
||||||
TEST_CASE(switch1);
|
TEST_CASE(switch1);
|
||||||
|
@ -1839,6 +1840,17 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ifelse26() { // don't crash
|
||||||
|
check("union tidi {\n"
|
||||||
|
" long long ti;\n"
|
||||||
|
" unsigned int di[2];\n"
|
||||||
|
"};\n"
|
||||||
|
"void f(long long val) {\n"
|
||||||
|
" if (val == ({ union tidi d = {.di = {0x0, 0x80000000}}; d.ti; })) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void switch1() {
|
void switch1() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char *p = 0;\n"
|
" char *p = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue