Fixed crash on wrong __attribute__((constructor)) syntax

This commit is contained in:
PKEuS 2014-03-16 16:39:07 +01:00
parent 4cad45e084
commit 6b16b519a2
2 changed files with 7 additions and 2 deletions

View File

@ -9099,7 +9099,7 @@ void Tokenizer::simplifyAttribute()
// prototype for constructor is: void func(void);
if (tok->next()->link()->next()->str() == "void") // __attribute__((constructor)) void func() {}
tok->next()->link()->next()->next()->isAttributeConstructor(true);
else if (tok->next()->link()->next()->str() == ";") // void func() __attribute__((constructor));
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1)) // void func() __attribute__((constructor));
tok->previous()->link()->previous()->isAttributeConstructor(true);
else // void __attribute__((constructor)) func() {}
tok->next()->link()->next()->isAttributeConstructor(true);
@ -9109,7 +9109,7 @@ void Tokenizer::simplifyAttribute()
// prototype for destructor is: void func(void);
if (tok->next()->link()->next()->str() == "void") // __attribute__((destructor)) void func() {}
tok->next()->link()->next()->next()->isAttributeDestructor(true);
else if (tok->next()->link()->next()->str() == ";") // void func() __attribute__((destructor));
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1)) // void func() __attribute__((destructor));
tok->previous()->link()->previous()->isAttributeDestructor(true);
else // void __attribute__((destructor)) func() {}
tok->next()->link()->next()->isAttributeDestructor(true);

View File

@ -277,6 +277,11 @@ private:
check("void f() __attribute__((destructor(1000)));\n"
"void f() { }");
ASSERT_EQUALS("", errout.str());
// Don't crash on wrong syntax
check("int x __attribute__((constructor));\n"
"int x __attribute__((destructor));");
ASSERT_EQUALS("", errout.str());
}