Fixed hang on garbage code (#6824)

This commit is contained in:
PKEuS 2015-07-20 22:33:32 +02:00
parent 749bb34deb
commit c987a99ac8
2 changed files with 6 additions and 1 deletions

View File

@ -4500,7 +4500,7 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
tokAfterCondition=tokCondition->link();
else
tokAfterCondition=nullptr;
if (!tokAfterCondition) {
if (!tokAfterCondition || tokAfterCondition->strAt(1) == "]") {
// Bad condition
syntaxError(tok);
return nullptr;

View File

@ -142,6 +142,7 @@ private:
TEST_CASE(garbageCode100);
TEST_CASE(garbageCode101); // #6835
TEST_CASE(garbageCode102); // #6846
TEST_CASE(garbageCode103); // #6824
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -804,6 +805,10 @@ private:
checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }");
}
void garbageCode103() { // #6824
ASSERT_THROW(checkCode("a f(r) int * r; { { int s[2]; [f(s); if () ] } }"), InternalError);
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"