Fix #6718 and #6719 (crashes on garbage code).

Local fixes avoiding access to NULL-token.  Also minor correction to
TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates()
This commit is contained in:
amai2012 2015-05-29 18:34:00 +02:00
parent 098391ee32
commit e41beb4f8d
4 changed files with 16 additions and 5 deletions

View File

@ -819,7 +819,7 @@ void CheckClass::initializationListUsage()
const Variable* var = tok->variable(); const Variable* var = tok->variable();
if (var && var->scope() == owner && !var->isStatic()) { if (var && var->scope() == owner && !var->isStatic()) {
bool allowed = true; bool allowed = true;
for (const Token* tok2 = tok->tokAt(2); tok2->str() != ";"; tok2 = tok2->next()) { for (const Token* tok2 = tok->tokAt(2); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
if (tok2->varId()) { if (tok2->varId()) {
const Variable* var2 = tok2->variable(); const Variable* var2 = tok2->variable();
if (var2 && var2->scope() == owner && if (var2 && var2->scope() == owner &&

View File

@ -128,7 +128,6 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke
tok = tok->link(); tok = tok->link();
if (!tok) if (!tok)
return true; return true;
} }
// skip executing scopes.. // skip executing scopes..
const Token *start = Tokenizer::startOfExecutableScope(tok); const Token *start = Tokenizer::startOfExecutableScope(tok);
@ -212,8 +211,8 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke
} }
} }
if (level > 0) { if (level > 0) {
// syntaxError(tok); errorToken=tok;
return tok; return true;
} }
} }
} }

View File

@ -7520,6 +7520,8 @@ void Tokenizer::simplifyEnum()
break; break;
if (Token::Match(temp, "class|struct")) if (Token::Match(temp, "class|struct"))
temp = temp->next(); temp = temp->next();
if (!temp)
break;
if (!Token::Match(temp, "[{:]") && if (!Token::Match(temp, "[{:]") &&
(!temp->isName() || !Token::Match(temp->next(), "[{:;]"))) (!temp->isName() || !Token::Match(temp->next(), "[{:;]")))
continue; continue;
@ -7529,7 +7531,7 @@ void Tokenizer::simplifyEnum()
Token *typeTokenEnd = nullptr; Token *typeTokenEnd = nullptr;
// check for C++11 enum class // check for C++11 enum class
bool enumClass = isCPP() && Token::Match(tok->next(), "class|struct"); const bool enumClass = isCPP() && Token::Match(tok->next(), "class|struct");
if (enumClass) if (enumClass)
tok->deleteNext(); tok->deleteNext();

View File

@ -88,6 +88,8 @@ private:
TEST_CASE(garbageCode47); // #6706 TEST_CASE(garbageCode47); // #6706
TEST_CASE(garbageCode48); // #6712 TEST_CASE(garbageCode48); // #6712
TEST_CASE(garbageCode49); // #6715 TEST_CASE(garbageCode49); // #6715
TEST_CASE(garbageCode50); // #6718
TEST_CASE(garbageCode51); // #6719
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
@ -505,6 +507,14 @@ private:
ASSERT_THROW(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), InternalError); ASSERT_THROW(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), InternalError);
} }
void garbageCode50() { // #6718
checkCode(" enum struct");
}
void garbageCode51() { // #6719
checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }");
}
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"