Skip to content

Commit 3976f9c

Browse files
committed
Fix #14876 Nullptr dereference in usingMatch()
1 parent 86f4c91 commit 3976f9c

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,9 @@ namespace {
27202720
return false;
27212721
}
27222722

2723+
if (!tok->tokAt(-1))
2724+
return false;
2725+
27232726
// skip other using with this name
27242727
if (tok1->strAt(-1) == "using") {
27252728
// fixme: this is wrong

test/testsimplifyusing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class TestSimplifyUsing : public TestFixture {
7777
TEST_CASE(simplifyUsing37);
7878
TEST_CASE(simplifyUsing38);
7979
TEST_CASE(simplifyUsing39);
80+
TEST_CASE(simplifyUsing40);
8081

8182
TEST_CASE(simplifyUsing8970);
8283
TEST_CASE(simplifyUsing8971);
@@ -939,6 +940,13 @@ class TestSimplifyUsing : public TestFixture {
939940
ASSERT_EQUALS("", errout_str());
940941
}
941942

943+
void simplifyUsing40() {
944+
const char code[] = "uint8_t f();\n" // #14876
945+
"using ::std::uint8_t;";
946+
const char expected[] = "uint8_t f ( ) ;";
947+
ASSERT_EQUALS(expected, tok(code));
948+
}
949+
942950
void simplifyUsing8970() {
943951
const char code[] = "using V = std::vector<int>;\n"
944952
"struct A {\n"

0 commit comments

Comments
 (0)