#6733 segmentation fault (invalid code) in Tokenizer::simplifyAddBracesPair

Avoid access to NULL-token by throwing an InternalError
This commit is contained in:
amai2012 2015-06-01 13:27:32 +02:00
parent 6857dbe864
commit b81e82d462
2 changed files with 9 additions and 1 deletions

View File

@ -4503,7 +4503,10 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
tokAfterCondition->previous()->insertToken("{");
Token * tokOpenBrace = tokAfterCondition->previous();
Token * tokEnd = tokAfterCondition->linkAt(1)->linkAt(2)->linkAt(1);
if (!tokEnd) {
syntaxError(tokAfterCondition);
return nullptr;
}
tokEnd->insertToken("}");
Token * tokCloseBrace = tokEnd->next();

View File

@ -95,6 +95,7 @@ private:
TEST_CASE(garbageCode54); // #6722
TEST_CASE(garbageCode55); // #6724
TEST_CASE(garbageCode56); // #6713
TEST_CASE(garbageCode57); // #6733
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -540,6 +541,10 @@ private:
checkCode("void foo() { int a = 0; int b = ???; }");
}
void garbageCode57() { // #6731
ASSERT_THROW(checkCode("{ } if () try { } catch (...) B::~B { }"), InternalError);
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"