From 4fb0899a2d4500a20e5a9345ec6f4a1d0e124d99 Mon Sep 17 00:00:00 2001 From: nussaiba shaikh Date: Tue, 29 Sep 2026 15:15:17 +0530 Subject: [PATCH] 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[]) {