From 231b47d1841fda4983efa4c466073e13c5719a48 Mon Sep 17 00:00:00 2001 From: Gilmar Santos Jr Date: Mon, 29 Jun 2026 14:07:56 -0300 Subject: [PATCH 1/2] Fix #14877: heap-use-after-free in Tokenizer::simplifyUsing() --- lib/tokenize.cpp | 5 ++--- test/testsimplifyusing.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7379957804f..2d248f2cbd2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3015,7 +3015,6 @@ bool Tokenizer::simplifyUsing() Token::Match(tok->linkAt(2), "] ] = ::| %name%"))))) continue; - const std::string& name = tok->strAt(1); const Token *nameToken = tok->next(); std::string scope = currentScope->fullName; Token *usingStart = tok; @@ -3064,7 +3063,7 @@ bool Tokenizer::simplifyUsing() if (!hasName) { std::string newName; if (structEnd->strAt(2) == ";") - newName = name; + newName = nameToken->str(); else newName = "Unnamed" + std::to_string(mUnnamedCount++); TokenList::copyTokens(structEnd->next(), tok, start); @@ -3211,7 +3210,7 @@ bool Tokenizer::simplifyUsing() if (!isTypedefInfoAdded && Token::Match(tok1, "%name% (")) { isTypedefInfoAdded = true; TypedefInfo usingInfo; - usingInfo.name = name; + usingInfo.name = nameToken->str(); usingInfo.filename = list.file(nameToken); usingInfo.lineNumber = nameToken->linenr(); usingInfo.column = nameToken->column(); diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 7359613510f..0d09fa37b12 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -98,6 +98,7 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(simplifyUsing10335); TEST_CASE(simplifyUsing10720); TEST_CASE(simplifyUsing13873); // function declaration + TEST_CASE(simplifyUsing14877); TEST_CASE(scopeInfo1); TEST_CASE(scopeInfo2); @@ -1667,6 +1668,12 @@ class TestSimplifyUsing : public TestFixture { ASSERT_EQUALS("namespace NS1 { void * f ( ) ; }", tok(code3)); } + void simplifyUsing14877() { + const char code[] = "using C = struct C { C() {} };"; + const char expected[] = "struct C { C ( ) { } } ;"; + ASSERT_EQUALS(expected, tok(code)); + } + void scopeInfo1() { const char code[] = "struct A {\n" " enum class Mode { UNKNOWN, ENABLED, NONE, };\n" From ba19ea12fd38f138603622ba0ddd683fb97b5ffc Mon Sep 17 00:00:00 2001 From: Gilmar Santos Jr Date: Tue, 30 Jun 2026 09:22:43 -0300 Subject: [PATCH 2/2] AUTHORS: Add Gilmar Santos Jr [skip ci] (#8679) --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index b505b682708..19cbe734d2e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -156,6 +156,7 @@ Gerhard Zlabinger Gerik Rhoden Gianfranco Costamagna Gianluca Scacco +Gilmar Santos Jr Gleydson Soares Goncalo Mao-Cheia Goran Džaferi