ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
535 stars 39 forks source link

Account for both forms of if statement in disambiguator #129

Closed ludanpr closed 10 months ago

ludanpr commented 10 months ago

I think a more bare bones case of the issue reported in #125 is

int main(void)
{
    if (0) {
        T(T);
    }
}

After marking the ambiguity, when reparsing the if statement, elseStmt_ is nullptr and is passed on to visitMaybeAmbiguousStatement, causing a null pointer dereference.

https://github.com/ltcmelo/psychec/blob/eabdcce6a57d9531acd7d7ebd1d43cbe918a73d0/C/reparser/Disambiguator.cpp#L385

https://github.com/ltcmelo/psychec/blob/eabdcce6a57d9531acd7d7ebd1d43cbe918a73d0/C/reparser/Disambiguator.cpp#L91

Simplistically, the PR proposes to account for both forms of if statements

ltcmelo commented 10 months ago

Thanks for the PR @ludanpr !