leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
2k stars 258 forks source link

CFR may generate uninitialized variables for loop guard expressions #314

Open AIRTEspresso opened 2 years ago

AIRTEspresso commented 2 years ago

CFR version

CFR version: 0.152

Compiler

Java openJDK, version: 11.0.13

Description

Here is another case that CFR may generate invalid Java code. When decompiling the loop structure shown in the example, CFR used a weird and uninitialized 'float f2', instead of 'f' in the loop guard expression. The total case is available at error example and I hope it can be helpful.

Example

The source code:

class Test {
    double dFld;
    {
        float f = 1.18F;
        while(-- f > 0)dFld = f;
    }
}

The code decompiled by CFR:

class Test {
    double dFld;
    Test() {
        float f = 1.18f;
        while (true) {
            float f2;
            f -= 1.0f;
            if (!(f2 > 0.0f)) break;
            this.dFld = f;
        }
    }
}