7357 segmentation fault in TokenList::insertTokens

This commit is contained in:
Alexander Mai 2016-01-26 19:12:57 +01:00
parent 462b98afbc
commit 1dac1664be
2 changed files with 11 additions and 3 deletions

View File

@ -5597,6 +5597,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
const Token *varTok = type0->tokAt((int)typelen);
while (Token::Match(varTok, "*|&|const"))
varTok = varTok->next();
if (!varTok)
syntaxError(tok2); // invalid code
list.insertTokens(eq, varTok, 2);
eq->str(";");

View File

@ -220,6 +220,7 @@ private:
TEST_CASE(garbageCode169); // #6731
TEST_CASE(garbageCode170);
TEST_CASE(garbageCode171);
TEST_CASE(garbageCode172);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -228,10 +229,10 @@ private:
std::string checkCode(const char code[], bool cpp = true) {
// double the tests - run each example as C as well as C++
const char* filename = cpp ? "test.cpp" : "test.c";
const char* alternatefilename = cpp ? "test.c" : "test.cpp";
const char* const filename = cpp ? "test.cpp" : "test.c";
const char* const alternatefilename = cpp ? "test.c" : "test.cpp";
// run alternate check first. It should only ensure stability
// run alternate check first. It should only ensure stability - so we catch exceptions here.
try {
checkCodeInternal(code, alternatefilename);
} catch (InternalError&) {
@ -1448,6 +1449,11 @@ private:
ASSERT_THROW(checkCode("(){case()?():}:", false), InternalError);
}
void garbageCode172() {
// #7357
ASSERT_THROW(checkCode("p<e T=l[<]<>>,"), InternalError);
}
};
REGISTER_TEST(TestGarbage)