#6747 segmentation fault (invalid code) in Token::isAttributeConstructor
This commit is contained in:
parent
09f2cff519
commit
d86ac9e3ed
|
@ -9162,9 +9162,17 @@ void Tokenizer::simplifyAttribute()
|
||||||
while (Token::Match(tok, "__attribute__|__attribute (") && tok->next()->link() && tok->next()->link()->next()) {
|
while (Token::Match(tok, "__attribute__|__attribute (") && tok->next()->link() && tok->next()->link()->next()) {
|
||||||
if (Token::Match(tok->tokAt(2), "( constructor|__constructor__")) {
|
if (Token::Match(tok->tokAt(2), "( constructor|__constructor__")) {
|
||||||
// prototype for constructor is: void func(void);
|
// prototype for constructor is: void func(void);
|
||||||
if (tok->next()->link()->next()->str() == "void") // __attribute__((constructor)) void func() {}
|
if (!tok->next()->link()->next()) {
|
||||||
|
syntaxError(tok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tok->next()->link()->next()->str() == "void") { // __attribute__((constructor)) void func() {}
|
||||||
|
if (!tok->next()->link()->next()->next()) {
|
||||||
|
syntaxError(tok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
tok->next()->link()->next()->next()->isAttributeConstructor(true);
|
tok->next()->link()->next()->next()->isAttributeConstructor(true);
|
||||||
else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // 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);
|
tok->previous()->link()->previous()->isAttributeConstructor(true);
|
||||||
else // void __attribute__((constructor)) func() {}
|
else // void __attribute__((constructor)) func() {}
|
||||||
tok->next()->link()->next()->isAttributeConstructor(true);
|
tok->next()->link()->next()->isAttributeConstructor(true);
|
||||||
|
@ -9172,6 +9180,10 @@ void Tokenizer::simplifyAttribute()
|
||||||
|
|
||||||
else if (Token::Match(tok->tokAt(2), "( destructor|__destructor__")) {
|
else if (Token::Match(tok->tokAt(2), "( destructor|__destructor__")) {
|
||||||
// prototype for destructor is: void func(void);
|
// prototype for destructor is: void func(void);
|
||||||
|
if (!tok->next()->link()->next()) {
|
||||||
|
syntaxError(tok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (tok->next()->link()->next()->str() == "void") // __attribute__((destructor)) void func() {}
|
if (tok->next()->link()->next()->str() == "void") // __attribute__((destructor)) void func() {}
|
||||||
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));
|
||||||
|
|
|
@ -108,6 +108,7 @@ private:
|
||||||
TEST_CASE(garbageCode67);
|
TEST_CASE(garbageCode67);
|
||||||
TEST_CASE(garbageCode68);
|
TEST_CASE(garbageCode68);
|
||||||
TEST_CASE(garbageCode69);
|
TEST_CASE(garbageCode69);
|
||||||
|
TEST_CASE(garbageCode70);
|
||||||
|
|
||||||
TEST_CASE(garbageValueFlow);
|
TEST_CASE(garbageValueFlow);
|
||||||
TEST_CASE(garbageSymbolDatabase);
|
TEST_CASE(garbageSymbolDatabase);
|
||||||
|
@ -605,6 +606,10 @@ private:
|
||||||
ASSERT_THROW(checkCode("{ (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F*"), InternalError);
|
ASSERT_THROW(checkCode("{ (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F*"), InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void garbageCode70() { // #6747
|
||||||
|
ASSERT_THROW(checkCode("{ } __attribute__((constructor)) void"), InternalError);
|
||||||
|
}
|
||||||
|
|
||||||
void garbageValueFlow() {
|
void garbageValueFlow() {
|
||||||
// #6089
|
// #6089
|
||||||
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
||||||
|
|
Loading…
Reference in New Issue