Fixed crashs on garbage code (#5604)
This commit is contained in:
parent
aa527cb408
commit
060f9035c9
|
@ -2562,10 +2562,12 @@ void Tokenizer::setVarId()
|
||||||
if (tokStart) {
|
if (tokStart) {
|
||||||
for (const Token *tok2 = tokStart->next(); tok2 != tokStart->link(); tok2 = tok2->next()) {
|
for (const Token *tok2 = tokStart->next(); tok2 != tokStart->link(); tok2 = tok2->next()) {
|
||||||
// skip parentheses..
|
// skip parentheses..
|
||||||
if (tok2->str() == "{")
|
if (tok2->link()) {
|
||||||
tok2 = tok2->link();
|
if (tok2->str() == "{")
|
||||||
else if (tok2->str() == "(")
|
tok2 = tok2->link();
|
||||||
tok2 = tok2->link();
|
else if (tok2->str() == "(")
|
||||||
|
tok2 = tok2->link();
|
||||||
|
}
|
||||||
|
|
||||||
// Found a member variable..
|
// Found a member variable..
|
||||||
else if (tok2->varId() > 0)
|
else if (tok2->varId() > 0)
|
||||||
|
@ -7575,9 +7577,11 @@ void Tokenizer::simplifyEnum()
|
||||||
// are there shadow variables in the scope?
|
// are there shadow variables in the scope?
|
||||||
std::set<std::string> shadowVars;
|
std::set<std::string> shadowVars;
|
||||||
for (const Token *tok3 = tok2->next(); tok3 && tok3->str() != "}"; tok3 = tok3->next()) {
|
for (const Token *tok3 = tok2->next(); tok3 && tok3->str() != "}"; tok3 = tok3->next()) {
|
||||||
if (tok3->str() == "{")
|
if (tok3->str() == "{") {
|
||||||
tok3 = tok3->link(); // skip inner scopes
|
tok3 = tok3->link(); // skip inner scopes
|
||||||
else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
if (tok3 == nullptr)
|
||||||
|
break;
|
||||||
|
} else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
||||||
const Token *prev = tok3->previous();
|
const Token *prev = tok3->previous();
|
||||||
if ((prev->isName() && !Token::Match(prev,"return|case|throw")) ||
|
if ((prev->isName() && !Token::Match(prev,"return|case|throw")) ||
|
||||||
Token::Match(prev, "&|* %type% =")) {
|
Token::Match(prev, "&|* %type% =")) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
TEST_CASE(garbageCode6); // #5214
|
TEST_CASE(garbageCode6); // #5214
|
||||||
TEST_CASE(garbageCode7);
|
TEST_CASE(garbageCode7);
|
||||||
TEST_CASE(garbageCode8); // #5511
|
TEST_CASE(garbageCode8); // #5511
|
||||||
|
TEST_CASE(garbageCode9); // #5604
|
||||||
|
|
||||||
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
|
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
|
||||||
|
|
||||||
|
@ -1030,8 +1031,20 @@ private:
|
||||||
tokenizeAndStringify("foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...)", /*simplify=*/true);
|
tokenizeAndStringify("foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...)", /*simplify=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode8() {
|
void garbageCode8() { // #5604
|
||||||
ASSERT_THROW(tokenizeAndStringify("{ enum struct : };", true), InternalError);
|
ASSERT_THROW(tokenizeAndStringify("{ enum struct : };", true), InternalError);
|
||||||
|
ASSERT_THROW(tokenizeAndStringify("int ScopedEnum{ template<typename T> { { e = T::error }; };\n"
|
||||||
|
"ScopedEnum1<int> se1; { enum class E : T { e = 0 = e ScopedEnum2<void*> struct UnscopedEnum3 { T{ e = 4 }; };\n"
|
||||||
|
"arr[(int) E::e]; }; UnscopedEnum3<int> e2 = f()\n"
|
||||||
|
"{ { e = e1; T::error } int test1 ue2; g() { enum class E { e = T::error }; return E::e; } int test2 = } \n"
|
||||||
|
"namespace UnscopedEnum { template<typename T> struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1<int> { enum E : { e = 0 }; };\n"
|
||||||
|
"UnscopedEnum2<void*> ue3; template<typename T> struct UnscopedEnum3 { enum { }; }; int arr[E::e]; };\n"
|
||||||
|
"UnscopedEnum3<int> namespace template<typename T> int f() { enum E { e }; T::error }; return (int) E(); } int test1 int g() { enum E { e = E };\n"
|
||||||
|
"E::e; } int test2 = g<int>(); }", true), InternalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
void garbageCode9() {
|
||||||
|
ASSERT_THROW(tokenizeAndStringify("enum { e = { } } ( ) { { enum { } } } { e } ", true), InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
|
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
|
||||||
|
|
Loading…
Reference in New Issue