Skip to content

Commit 89ec148

Browse files
Partial fix for #11638 Library::getFunctionName: SIGSEGV (#4920)
* Partial fix for #11638 Library::getFunctionName: SIGSEGV * Fix test * simpleMatch()
1 parent 28ed9d3 commit 89ec148

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8044,6 +8044,8 @@ void Tokenizer::findGarbageCode() const
80448044
if (!isCPP() || mSettings->standards.cpp < Standards::CPP20 || !Token::Match(tok->previous(), "%name% : %num% ="))
80458045
syntaxError(tok, tok->next()->str() + " " + tok->strAt(2));
80468046
}
8047+
else if (Token::simpleMatch(tok, ") return") && !Token::Match(tok->link()->previous(), "if|while|for ("))
8048+
syntaxError(tok);
80478049

80488050
if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
80498051
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {

test/testtokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6782,6 +6782,8 @@ class TestTokenizer : public TestFixture {
67826782

67836783
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : { };"), InternalError, "syntax error: Unexpected token '{'");
67846784
ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'");
6785+
6786+
ASSERT_THROW_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), InternalError, "syntax error");
67856787
}
67866788

67876789

0 commit comments

Comments
 (0)