#6724 segmentation fault (invalid code) Token::isAttributeConstructor. Local fix to avoid access to NULL-token

This commit is contained in:
Alexander Mai 2015-05-30 19:15:53 +02:00
parent 4050d56169
commit ddc80246c2
2 changed files with 7 additions and 2 deletions

View File

@ -9177,7 +9177,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() == ";" && tok->linkAt(-1)) // void func() __attribute__((constructor));
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // void func() __attribute__((constructor));
tok->previous()->link()->previous()->isAttributeConstructor(true);
else // void __attribute__((constructor)) func() {}
tok->next()->link()->next()->isAttributeConstructor(true);
@ -9187,7 +9187,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() == ";" && tok->linkAt(-1)) // void func() __attribute__((destructor));
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // void func() __attribute__((destructor));
tok->previous()->link()->previous()->isAttributeDestructor(true);
else // void __attribute__((destructor)) func() {}
tok->next()->link()->next()->isAttributeDestructor(true);

View File

@ -93,6 +93,7 @@ private:
TEST_CASE(garbageCode52); // #6720
TEST_CASE(garbageCode53); // #6721
TEST_CASE(garbageCode54); // #6722
TEST_CASE(garbageCode55); // #6724
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -530,6 +531,10 @@ private:
ASSERT_THROW(checkCode("{ typedef long ((pf) p) (); }"), InternalError);
}
void garbageCode55() { // #6724
checkCode("() __attribute__((constructor)); { } { }");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"