fix simplifyUsing crash and hang (#3145)
This commit is contained in:
parent
02ac2b08a0
commit
a07f93f819
|
@ -1928,10 +1928,14 @@ namespace {
|
|||
tok1 = tok1->previous();
|
||||
if (tok1->strAt(-1) != ")")
|
||||
return;
|
||||
} else if (Token::Match(tok->tokAt(-2), ":|, %name%")) {
|
||||
tok1 = tok1->tokAt(-2);
|
||||
if (tok1->strAt(-1) != ")")
|
||||
return;
|
||||
tok1 = tok1->linkAt(-1);
|
||||
} else {
|
||||
while (Token::Match(tok1->tokAt(-2), ":|, %name%")) {
|
||||
tok1 = tok1->tokAt(-2);
|
||||
if (tok1->strAt(-1) != ")")
|
||||
return;
|
||||
tok1 = tok1->linkAt(-1);
|
||||
}
|
||||
}
|
||||
if (tok1->strAt(-1) == ">")
|
||||
tok1 = tok1->previous()->findOpeningBracket();
|
||||
|
@ -2356,6 +2360,9 @@ bool Tokenizer::simplifyUsing()
|
|||
if (tok1->str() == "enum")
|
||||
skipEnumBody(&tok1);
|
||||
|
||||
if (!tok1)
|
||||
break;
|
||||
|
||||
// check for member function and adjust scope
|
||||
if (isMemberFunction(tok1)) {
|
||||
if (!scope1.empty())
|
||||
|
@ -2505,6 +2512,10 @@ bool Tokenizer::simplifyUsing()
|
|||
} while (type && type->str() == "[");
|
||||
}
|
||||
|
||||
// make sure we are in a good state
|
||||
if (!tok1 || !tok1->next())
|
||||
break; // bail
|
||||
|
||||
Token* after = tok1->next();
|
||||
// check if type was parsed
|
||||
if (type && type == usingEnd) {
|
||||
|
|
|
@ -67,6 +67,8 @@ private:
|
|||
TEST_CASE(simplifyUsing18);
|
||||
TEST_CASE(simplifyUsing19);
|
||||
TEST_CASE(simplifyUsing20);
|
||||
TEST_CASE(simplifyUsing21);
|
||||
TEST_CASE(simplifyUsing22);
|
||||
|
||||
TEST_CASE(simplifyUsing8970);
|
||||
TEST_CASE(simplifyUsing8971);
|
||||
|
@ -521,6 +523,37 @@ private:
|
|||
tok(code, false); // don't hang
|
||||
}
|
||||
|
||||
void simplifyUsing21() {
|
||||
const char code[] = "using a = b;\n"
|
||||
"enum {}";
|
||||
tok(code, false); // don't crash
|
||||
}
|
||||
|
||||
void simplifyUsing22() {
|
||||
const char code[] = "namespace aa { namespace bb { namespace cc { namespace dd { namespace ee {\n"
|
||||
"class fff {\n"
|
||||
"public:\n"
|
||||
" using icmsp = std::shared_ptr<aa::bb::ee::cm::api::icm>;\n"
|
||||
"private:\n"
|
||||
" using Connection = boost::signals2::connection;\n"
|
||||
" using ESdk = sdk::common::api::Sdk::ESdk;\n"
|
||||
" using co = aa::bb::ee::com::api::com2;\n"
|
||||
"};\n"
|
||||
"fff::fff() : m_icm(icm) {\n"
|
||||
" using ESdk = aa::bb::sdk::common::api::Sdk::ESdk;\n"
|
||||
"}\n"
|
||||
"}}}}}";
|
||||
const char expected[] = "namespace aa { namespace bb { namespace cc { namespace dd { namespace ee { "
|
||||
"class fff { "
|
||||
"public: "
|
||||
"private: "
|
||||
"} ; "
|
||||
"fff :: fff ( ) : m_icm ( icm ) { "
|
||||
"} "
|
||||
"} } } } }";
|
||||
ASSERT_EQUALS(expected, tok(code, false)); // don't hang
|
||||
}
|
||||
|
||||
void simplifyUsing8970() {
|
||||
const char code[] = "using V = std::vector<int>;\n"
|
||||
"struct A {\n"
|
||||
|
|
Loading…
Reference in New Issue