#6761 segmentation fault (invalid code) in Tokenizer::simplifyTypedef. Fix crash.

This commit is contained in:
Alexander Mai 2015-06-07 13:35:51 +02:00
parent 75b0430ba5
commit c18461b173
2 changed files with 11 additions and 1 deletions

View File

@ -1537,6 +1537,10 @@ void Tokenizer::simplifyTypedef()
break; break;
} }
if (!tok) {
syntaxError(nullptr);
return;
}
if (tok->str() == ";") if (tok->str() == ";")
done = true; done = true;
else if (tok->str() == ",") { else if (tok->str() == ",") {

View File

@ -120,6 +120,7 @@ private:
TEST_CASE(garbageCode79); TEST_CASE(garbageCode79);
TEST_CASE(garbageCode80); TEST_CASE(garbageCode80);
TEST_CASE(garbageCode81); TEST_CASE(garbageCode81);
TEST_CASE(garbageCode82);
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
@ -569,8 +570,9 @@ private:
ASSERT_THROW(checkCode("{ } if () try { } catch (...) B::~B { }"), InternalError); ASSERT_THROW(checkCode("{ } if () try { } catch (...) B::~B { }"), InternalError);
} }
void garbageCode58() { // #6732 void garbageCode58() { // #6732, #6762
//ASSERT_THROW(checkCode("{ }> {= ~A()^{} }P { }"), InternalError); //ASSERT_THROW(checkCode("{ }> {= ~A()^{} }P { }"), InternalError);
//ASSERT_THROW(checkCode("{= ~A()^{} }P { } { }> is"), InternalError);
} }
void garbageCode59() { // #6735 void garbageCode59() { // #6735
@ -665,6 +667,10 @@ private:
ASSERT_THROW(checkCode("{ } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const"), InternalError); ASSERT_THROW(checkCode("{ } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const"), InternalError);
} }
void garbageCode82() { // #6761
ASSERT_THROW(checkCode("p(\"Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t)"), 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"