Fix crash with statement expression (#4142)

This commit is contained in:
chrchr-github 2022-05-28 00:11:23 +02:00 committed by GitHub
parent 16af6561c2
commit 16a4449901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -442,7 +442,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
continue;
// 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?
// right ast part (after `=` operator)
const Token* tokRightAstOperand = innerTok->next()->astOperand2();

View File

@ -165,6 +165,7 @@ private:
TEST_CASE(ifelse23); // #5473
TEST_CASE(ifelse24); // #1733
TEST_CASE(ifelse25); // #9966
TEST_CASE(ifelse26);
// switch
TEST_CASE(switch1);
@ -1839,6 +1840,17 @@ private:
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() {
check("void f() {\n"
" char *p = 0;\n"