xoofx / CppAst.NET

CppAst is a .NET library providing a C/C++ parser for header files powered by Clang/libclang with access to the full AST, comments and macros
BSD 2-Clause "Simplified" License
501 stars 66 forks source link

Infinite loop occurs when parentheses are included in a comment #17

Closed mugisoba closed 4 years ago

mugisoba commented 4 years ago

I found an infinite loop on v0.7.0.

// [infinite loop)
void x() {}

If comments contain parentheses, this loop cannot be escaped because parenCount has never become zero.

// CppModelBuilder.cs Line 2133
var parenCount = 1;
for (var lastBegin = begin; parenCount != 0; lastBegin = begin)
{
    if (TokenIsBefore(begin, "("))
        --parenCount;
    else if (TokenIsBefore(begin, ")"))
        ++parenCount;

    begin = GetPrevLocation(begin, 1);  // GetPrevLocation() returns CXSourceLocation.Null
}
xoofx commented 4 years ago

@wackoisgod was worried about a few parts in the PR about that, should have raised my concerns! 😅 Could you have a look?

wackoisgod commented 4 years ago

I shall take a look! and will add a test

wackoisgod commented 4 years ago

Should be resolved in PR #18

mugisoba commented 4 years ago

It works perfectly 🎉 Thank you very much 👍