Skip to content

Commit

Permalink
fix: correct fix for all use places of incompatible primitives (#1688)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 2, 2022
1 parent 603f305 commit 711419a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -913,25 +913,20 @@ private boolean processIncompatiblePrimitives(MethodNode mth, SSAVar var) {
}

boolean fixed = false;
for (ITypeBound bound : typeInfo.getBounds()) {
if (bound.getBound() == BoundEnum.USE
&& fixBooleanUsage(mth, bound)) {
for (RegisterArg arg : new ArrayList<>(var.getUseList())) {
if (fixBooleanUsage(mth, arg)) {
fixed = true;
}
}
return fixed;
}

private boolean fixBooleanUsage(MethodNode mth, ITypeBound bound) {
ArgType boundType = bound.getType();
private boolean fixBooleanUsage(MethodNode mth, RegisterArg boundArg) {
ArgType boundType = boundArg.getInitType();
if (boundType == ArgType.BOOLEAN
|| (boundType.isTypeKnown() && !boundType.isPrimitive())) {
return false;
}
RegisterArg boundArg = bound.getArg();
if (boundArg == null) {
return false;
}
InsnNode insn = boundArg.getParentInsn();
if (insn == null || insn.getType() == InsnType.IF) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;

@SuppressWarnings("CommentedOutCode")
public class TestBooleanToInt extends SmaliTest {

// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package jadx.tests.integration.conditions;

import org.junit.jupiter.api.Test;

import jadx.tests.api.SmaliTest;

import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;

@SuppressWarnings("CommentedOutCode")
public class TestBooleanToInt2 extends SmaliTest {

// @formatter:off
/*
public static class TestCls {
public void test() {
boolean v = getValue();
use1(Integer.valueOf(v));
use2(v);
}
private boolean getValue() {
return false;
}
private void use1(Integer v) {
}
private void use2(int v) {
}
}
*/
// @formatter:on
@Test
public void test() {
assertThat(getClassNodeFromSmali())
.code()
.containsOne("use1(Integer.valueOf(value ? 1 : 0));")
.containsOne("use2(value ? 1 : 0);");
}
}
29 changes: 29 additions & 0 deletions jadx-core/src/test/smali/conditions/TestBooleanToInt2.smali
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.class public Lconditions/TestBooleanToInt2;
.super Ljava/lang/Object;

.method public test()V
.registers 3
invoke-direct {p0}, Lconditions/TestBooleanToInt2;->getValue()Z
move-result v0
invoke-static {v0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
move-result-object v1
invoke-direct {p0, v1}, Lconditions/TestBooleanToInt2;->use1(Ljava/lang/Integer;)V
invoke-direct {p0, v0}, Lconditions/TestBooleanToInt2;->use2(I)V
return-void
.end method

.method private getValue()Z
.registers 2
const/4 v0, 0x0
return v0
.end method

.method private use1(Ljava/lang/Integer;)V
.registers 2
return-void
.end method

.method private use2(I)V
.registers 2
return-void
.end method

0 comments on commit 711419a

Please sign in to comment.