Fix 10672: crash: CheckAutoVariables (#3657)

This commit is contained in:
Paul Fultz II 2021-12-31 17:14:36 -06:00 committed by GitHub
parent 922e27de4c
commit 7bf0ca8d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -563,7 +563,9 @@ static const Token* getParentLifetime(bool cpp, const Token* tok, const Library*
const Token* dotTok = tok2->next();
if (!Token::simpleMatch(dotTok, ".")) {
const Token* endTok = nextAfterAstRightmostLeaf(tok2);
if (Token::simpleMatch(endTok, "."))
if (!endTok)
dotTok = tok2->next();
else if (Token::simpleMatch(endTok, "."))
dotTok = endTok;
else if (Token::simpleMatch(endTok->next(), "."))
dotTok = endTok->next();

View File

@ -415,8 +415,8 @@ private:
// #9052
TEST_CASE(noCrash1);
TEST_CASE(noCrash2);
TEST_CASE(noCrash3);
TEST_CASE(noCrash4);
// --check-config
TEST_CASE(checkConfiguration);
@ -6963,6 +6963,15 @@ private:
ASSERT_NO_THROW(tokenizeAndStringify("void a(X<int> x, typename Y1::Y2<int, A::B::C, 2> y, Z z = []{});"));
}
void noCrash4()
{
ASSERT_NO_THROW(tokenizeAndStringify("static int foo() {\n"
" zval ref ;\n"
" p = &(ref).value;\n"
" return result ;\n"
"}\n"));
}
void checkConfig(const char code[]) {
errout.str("");