#7816 Segmentation fault at Tokenizer::simplifyAttribute() for stand-alone void. Throw syntax error on incomplete code

This commit is contained in:
amai2012 2016-11-21 12:19:47 +01:00
parent 9043436e67
commit 933815ee54
2 changed files with 10 additions and 2 deletions

View File

@ -8445,9 +8445,12 @@ void Tokenizer::simplifyAttribute()
if (!tok->next()->link()->next()) if (!tok->next()->link()->next())
syntaxError(tok); syntaxError(tok);
if (tok->next()->link()->next()->str() == "void") // __attribute__((destructor)) void func() {} if (tok->next()->link()->next()->str() == "void") {
// __attribute__((destructor)) void func() {}
if (!tok->next()->link()->next()->next())
syntaxError(tok);
tok->next()->link()->next()->next()->isAttributeDestructor(true); tok->next()->link()->next()->next()->isAttributeDestructor(true);
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // 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); tok->previous()->link()->previous()->isAttributeDestructor(true);
else // void __attribute__((destructor)) func() {} else // void __attribute__((destructor)) func() {}
tok->next()->link()->next()->isAttributeDestructor(true); tok->next()->link()->next()->isAttributeDestructor(true);

View File

@ -217,6 +217,7 @@ private:
TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageCode183); // #7505 TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageCode184); // #7699 TEST_CASE(garbageCode184); // #7699
TEST_CASE(garbageCode185); // #7816
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
@ -1431,6 +1432,10 @@ private:
"}"); "}");
} }
void garbageCode185() { // #7816
checkCode("__attribute__((destructor)) void");
}
void syntaxErrorFirstToken() { void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858