Commit b657b0fb authored by Skylot's avatar Skylot

core: fix 'if' processing in 'do/while' loop

parent 4935ae6d
......@@ -199,9 +199,11 @@ public class RegionMaker {
BlockNode thenBlock = condInfo.getThenBlock();
out = (thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock);
loopStart.remove(AType.LOOP);
loop.getEnd().add(AFlag.SKIP);
stack.addExit(loop.getEnd());
loopRegion.setBody(makeRegion(loopStart, stack));
loopStart.addAttr(AType.LOOP, loop);
loop.getEnd().remove(AFlag.SKIP);
} else {
out = condInfo.getElseBlock();
if (outerRegion != null
......
package jadx.tests.internal.loops;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestLoopConditionInvoke extends InternalJadxTest {
public static class TestCls {
private static final char STOP_CHAR = 0;
private int pos;
private boolean test(char lastChar) {
int startPos = pos;
char ch;
while ((ch = next()) != STOP_CHAR) {
if (ch == lastChar) {
return true;
}
}
pos = startPos;
return false;
}
private char next() {
return 0;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("do {"));
assertThat(code, containsOne("if (ch == '\\u0000') {"));
assertThat(code, containsOne("this.pos = startPos;"));
assertThat(code, containsOne("return false;"));
assertThat(code, containsOne("} while (ch != lastChar);"));
assertThat(code, containsOne("return true;"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment