Skip to content

Commit

Permalink
Fix #12586 Crash in getReallocFuncInfo() with namespace alias (#6230)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 4, 2024
1 parent 4503fbf commit 3e22ef1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10605,6 +10605,8 @@ void Tokenizer::simplifyNamespaceAliases()
}

if (tok2->strAt(1) == "::" && !alreadyHasNamespace(tokNameStart, tokNameEnd, tok2)) {
if (Token::simpleMatch(tok2->tokAt(-1), "::") && tokNameStart->str() == "::")
tok2->deletePrevious();
tok2->str(tokNameStart->str());
Token * tok3 = tokNameStart;
while (tok3 != tokNameEnd) {
Expand Down
13 changes: 13 additions & 0 deletions test/testsimplifytokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class TestSimplifyTokens : public TestFixture {
TEST_CASE(simplifyNestedNamespace);
TEST_CASE(simplifyNamespaceAliases1);
TEST_CASE(simplifyNamespaceAliases2); // ticket #10281
TEST_CASE(simplifyNamespaceAliases3);

TEST_CASE(simplifyKnownVariables2);
TEST_CASE(simplifyKnownVariables3);
Expand Down Expand Up @@ -1502,6 +1503,18 @@ class TestSimplifyTokens : public TestFixture {
"}"));
}

void simplifyNamespaceAliases3() {
ASSERT_EQUALS("namespace N { namespace O { int g ( ) ; } } " // #12586
"void f ( ) { "
"int s ; s = 3 * :: N :: O :: g ( ) ; "
"}",
tok("namespace N { namespace O { int g(); } }\n"
"namespace _n = ::N::O;\n"
"void f() {\n"
" int s = 3 * ::_n::g();\n"
"}\n"));
}

#define simplifyKnownVariables(code) simplifyKnownVariables_(code, __FILE__, __LINE__)
std::string simplifyKnownVariables_(const char code[], const char* file, int line) {
Tokenizer tokenizer(settings0, this);
Expand Down

0 comments on commit 3e22ef1

Please sign in to comment.