[go: up one dir, main page]

Skip to content

Crash with experimental --add-braces=nested option

Trying the new experimental --add-braces=nested option in 3.11, which fixed the issue I previously reported in #27 (closed). And I've found a scenario where AStyle crashes.

void test(void)
{
    if (cond1)
    {
        printf("test");
    }
    else if (cond2)
    {
        printf("test");
    }
    else
    {
        printf("test");
    }
}

Command: astyle --style=allman --add-braces=nested test.c

The trigger seems to be the else if part. AStyle crashes when processing this code, and outputs code that won't compile.

Assertion failed!

Program: astyle.exe
File: ..\src\astyle_main.cpp, Line 663

Expression: formatter.getChecksumDiff() == 0

The output code is:

void test(void)
{
    if (cond1)
    {
        printf("test");
    }
    else
    {
        if (cond2)
        {
            printf("test");
        }
        else
        {
            printf("test");
        }
    }

A closing brace has been omitted.

Aside from the crash here, I would also like the ability to leave the else if parts combined, as it is in my input code.