Partial fix for #11638 Library::getFunctionName: SIGSEGV (#4920)

* Partial fix for #11638 Library::getFunctionName: SIGSEGV

* Fix test

* simpleMatch()
This commit is contained in:
chrchr-github 2023-03-30 07:25:26 +02:00 committed by GitHub
parent 28ed9d30e0
commit 89ec148199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -8044,6 +8044,8 @@ void Tokenizer::findGarbageCode() const
if (!isCPP() || mSettings->standards.cpp < Standards::CPP20 || !Token::Match(tok->previous(), "%name% : %num% ="))
syntaxError(tok, tok->next()->str() + " " + tok->strAt(2));
}
else if (Token::simpleMatch(tok, ") return") && !Token::Match(tok->link()->previous(), "if|while|for ("))
syntaxError(tok);
if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {

View File

@ -6782,6 +6782,8 @@ private:
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : { };"), InternalError, "syntax error: Unexpected token '{'");
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'");
ASSERT_THROW_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), InternalError, "syntax error");
}