#6748 segmentation fault (invalid code) in Tokenizer::simplifyTypedef. Throw error from now (member-function) Tokenizer::processFunc

This commit is contained in:
amai2012 2015-06-03 08:59:38 +02:00
parent d86ac9e3ed
commit d36c84553f
3 changed files with 13 additions and 2 deletions

View File

@ -504,7 +504,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
* code that generated it deals in some way with functions, then this
* function will probably need to be extended to handle a new function
* related pattern */
static Token *processFunc(Token *tok2, bool inOperator)
Token *Tokenizer::processFunc(Token *tok2, bool inOperator) const
{
if (tok2->next() && tok2->next()->str() != ")" &&
tok2->next()->str() != ",") {
@ -551,7 +551,11 @@ static Token *processFunc(Token *tok2, bool inOperator)
// skip over typedef parameter
if (tok2->next() && tok2->next()->str() == "(") {
tok2 = tok2->next()->link();
if (!tok2->next())
{
syntaxError(tok2);
return nullptr;
}
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
}

View File

@ -814,6 +814,8 @@ private:
return const_cast<Token*>(startOfExecutableScope(const_cast<const Token *>(tok)));
}
Token *processFunc(Token *tok2, bool inOperator) const;
/** Set pod types */
void setPodTypes();

View File

@ -109,6 +109,7 @@ private:
TEST_CASE(garbageCode68);
TEST_CASE(garbageCode69);
TEST_CASE(garbageCode70);
TEST_CASE(garbageCode71);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -610,6 +611,10 @@ private:
ASSERT_THROW(checkCode("{ } __attribute__((constructor)) void"), InternalError);
}
void garbageCode71() { // #6748
ASSERT_THROW(checkCode("( ) { } typedef void noattr_t ( ) ; noattr_t __attribute__ ( )"), InternalError);
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"