mirror of
https://github.com/revanced/smali.git
synced 2025-05-07 01:44:32 +02:00
Fix bug #709
This commit is contained in:
parent
3cccf68502
commit
b044a00353
@ -220,13 +220,13 @@ public class Preconditions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <L extends List<? extends Number>> L checkArrayPayloadElements(int elementWidth, L elements) {
|
public static <L extends List<? extends Number>> L checkArrayPayloadElements(int elementWidth, L elements) {
|
||||||
// mask of all bits that do not fit into an 'elementWidth'-bit number
|
// mask of all bits that do not fit into an 'elementWidth'-byte number
|
||||||
long bitmask = -1L << elementWidth;
|
long bitmask = -1L << (elementWidth * 8);
|
||||||
|
|
||||||
for (Number element : elements) {
|
for (Number element : elements) {
|
||||||
if ((element.longValue() & bitmask) != 0) {
|
if ((element.longValue() & bitmask) != 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format("Number %d must fit into a %d-bit number", element.longValue(), elementWidth));
|
String.format("Number %d must fit into a %d-byte number", element.longValue(), elementWidth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
dexlib2/src/test/java/org/jf/util/PreconditionsTest.java
Normal file
23
dexlib2/src/test/java/org/jf/util/PreconditionsTest.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package org.jf.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.jf.dexlib2.Opcode;
|
||||||
|
import org.jf.dexlib2.iface.instruction.formats.ArrayPayload;
|
||||||
|
import org.jf.dexlib2.util.Preconditions;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PreconditionsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkArrayPayloadElements() {
|
||||||
|
int intSize = 4;
|
||||||
|
int bigNumber = 16843071;
|
||||||
|
List<Number> numbers = new ArrayList<>();
|
||||||
|
numbers.add(bigNumber);
|
||||||
|
|
||||||
|
// Shouldn't throw any exceptions, payload is correct.
|
||||||
|
Preconditions.checkArrayPayloadElements(intSize, numbers);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user