* Taking care of incorrect template syntax (missing close)

Forward the incorrectness via throw, as there is no direct access to the
syntaxError method, without converting the function to a member function
This commit is contained in:
Hinterwaeldlers 2017-08-15 22:40:55 +02:00 committed by Daniel Marjamäki
parent 03b75b54ca
commit 705e5e3468
2 changed files with 18 additions and 2 deletions

View File

@ -2341,7 +2341,11 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
}
} else if (!c && ((TemplateSimplifier::templateParameters(tok2) > 0) ||
Token::simpleMatch(tok2, "< >") /* Ticket #4764 */)) {
tok2 = tok2->findClosingBracket();
const Token * tok3 = tok2->findClosingBracket();
if (tok3 == nullptr) { /* Ticket #8151 */
throw tok2;
}
tok2 = tok3;
if (tok2->str() != ">")
break;
singleNameCount = 1;
@ -2694,7 +2698,12 @@ void Tokenizer::setVarIdPass1()
if (!isC() && Token::simpleMatch(tok2, "const new"))
continue;
bool decl = setVarIdParseDeclaration(&tok2, variableId, scopeStack.top().isExecutable, isCPP(), isC());
bool decl;
try { /* Ticket #8151 */
decl = setVarIdParseDeclaration(&tok2, variableId, scopeStack.top().isExecutable, isCPP(), isC());
} catch (const Token * errTok) {
syntaxError(errTok);
}
if (decl) {
const Token* prev2 = tok2->previous();
if (Token::Match(prev2, "%type% [;[=,)]") && tok2->previous()->str() != "const")

View File

@ -216,6 +216,7 @@ private:
TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageCode184); // #7699
TEST_CASE(garbageCode185); // #6011
TEST_CASE(garbageCode186); // #8151
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -1419,6 +1420,12 @@ private:
"}\n");
}
// #8151 - segfault due to incorrect template syntax
void garbageCode186() {
ASSERT_THROW(checkCode("A<B<><>C"), InternalError);
}
void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858