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));
}
Comment on lines +145 to 150

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment.

The fix looks correct. I verified that nullNodeInvalidLevel fails on main (built with -D_GLIBCXX_ASSERTIONS: Assertion '__n < this->size()' failed on tree[level - 1]) and that TestClangImport passes with this PR.

Nit: the test function is defined between run() and the parse() helper. All the other test functions come after the helpers, and the description says it goes "next to the existing crash() case". Maybe move it to just after crash() at the end of the class?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the status of ClangImport? As far as I see, it has been abandonded for years and is probably unusable. We might want to ditch it instead of wasting time on probably AI-generated "fixes".


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