From 4fb0899a2d4500a20e5a9345ec6f4a1d0e124d99 Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Tue, 29 Sep 2026 15:15:17 +0530 Subject: [PATCH 1/2] fix oob tree index in parseClangAstDump on stray NULL node --- lib/clangimport.cpp | 4 +++- test/testclangimport.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 98c0e700d83..e6fdbc3bb0d 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -1639,7 +1639,9 @@ void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f) if (pos1 == std::string::npos) continue; if (!tree.empty() && line.substr(pos1) == "-<<>>") { - const int level = (pos1 - 1) / 2; + const size_t level = (pos1 - 1) / 2; + if (level == 0 || level > tree.size()) + continue; tree[level - 1]->children.push_back(nullptr); continue; } diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 6a39b563982..26c73e5f7a2 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -139,6 +139,14 @@ class TestClangImport : public TestFixture { TEST_CASE(valueType2); TEST_CASE(crash); + TEST_CASE(nullNodeInvalidLevel); + } + + void nullNodeInvalidLevel() { + // a "<<>>" line whose indentation maps to level 0 must not index tree[-1] + const char* clang = "`-FunctionDecl 0x1 col:6 foo 'void ()'\n" + "`-<<>>\n"; + ASSERT_EQUALS("void foo ( ) ;", parse(clang)); } std::string parse(const char clang[]) { From 2b2efb01bf100c65756913c2ed02faed4354de0c Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Fri, 2 Oct 2026 18:56:21 +0530 Subject: [PATCH 2/2] testclangimport: move nullNodeInvalidLevel after crash() Signed-off-by: nussaiba shaikh --- test/testclangimport.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 26c73e5f7a2..5da5ed70b68 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -142,13 +142,6 @@ class TestClangImport : public TestFixture { TEST_CASE(nullNodeInvalidLevel); } - void nullNodeInvalidLevel() { - // a "<<>>" line whose indentation maps to level 0 must not index tree[-1] - const char* clang = "`-FunctionDecl 0x1 col:6 foo 'void ()'\n" - "`-<<>>\n"; - ASSERT_EQUALS("void foo ( ) ;", parse(clang)); - } - std::string parse(const char clang[]) { const Settings settings = settingsBuilder().clang().build(); TokenList tokenlist{settings, Standards::Language::CPP}; @@ -1380,6 +1373,13 @@ class TestClangImport : public TestFixture { " `-CompoundStmt 0x5603791b5700 \n"; (void)parse(clang); // don't crash } + + void nullNodeInvalidLevel() { + // a "<<>>" line whose indentation maps to level 0 must not index tree[-1] + const char* clang = "`-FunctionDecl 0x1 col:6 foo 'void ()'\n" + "`-<<>>\n"; + ASSERT_EQUALS("void foo ( ) ;", parse(clang)); + } }; REGISTER_TEST(TestClangImport)