Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,9 @@ void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f)
if (pos1 == std::string::npos)
continue;
if (!tree.empty() && line.substr(pos1) == "-<<<NULL>>>") {
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;
}
Expand Down
8 changes: 8 additions & 0 deletions test/testclangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ class TestClangImport : public TestFixture {
TEST_CASE(valueType2);

TEST_CASE(crash);
TEST_CASE(nullNodeInvalidLevel);
}

void nullNodeInvalidLevel() {
// a "<<<NULL>>>" line whose indentation maps to level 0 must not index tree[-1]
const char* clang = "`-FunctionDecl 0x1 <a.cpp:1:1, col:34> col:6 foo 'void ()'\n"
"`-<<<NULL>>>\n";
ASSERT_EQUALS("void foo ( ) ;", parse(clang));
}

std::string parse(const char clang[]) {
Expand Down