Skip to content

Structurer incorrectly converts branches to header to continue inside do while loops #1356

Description

@toxamin

Original code:

#include <stdio.h>
int gg() {
    return 0;
}

int main(void) {
    int smth = gg();
    int nah = gg();
    int bozo = gg();

    while (1) {
        printf("hi\n");

        if (smth) {
            printf("a\n");
            if (!nah) {
                printf("heh\n");
            } else {
                continue; // this skips over the if (bozo) break check
            }
        }

        printf("aye!!\n");

        if (bozo) { // trick the decompiler into thinking this is a do-while
            break;
        }
    }

    return 0;
}

Decompiled code:

word32 fn00401000()
{
    return 0x00;
}


word32 fn00401011()
{
    word32 eax_10 = fn00401000();
    word32 eax_16 = fn00401000();
    word32 eax_22 = fn00401000();
    do
    {
        printf(&g_b402000);
        if (eax_10 != 0x00)
        {
            printf(&g_b402004);
            if (eax_16 != 0x00)
                continue; // this hits the do while check (WRONG BEHAVIOR)
            printf(&g_b402007);
        }
        printf(&g_b40200C);
    } while (eax_22 == 0x00);
    return 0x00;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions