From 6b16b519a2cb3693426c5df335e8751a5b3a9e7a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 16 Mar 2014 16:39:07 +0100 Subject: [PATCH] Fixed crash on wrong __attribute__((constructor)) syntax --- lib/tokenize.cpp | 4 ++-- test/testunusedfunctions.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a590da6fd..ce92b39af 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 7c60717dd..9460f75ae 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -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()); }