diff options
author | Eric Bruneton <ebruneton@free.fr> | 2024-05-11 16:06:13 +0200 |
---|---|---|
committer | Eric Bruneton <ebruneton@free.fr> | 2024-05-11 16:09:44 +0200 |
commit | 8f40ea6b9df7fc2e0853523729357ff017ae21b1 (patch) | |
tree | 0ba395e7c8778085d3102f67067ae29dc8efd38b | |
parent | 9f8177e37e5df14a2c8bbe098dd037189c08affc (diff) | |
download | ow2-asm-upstream-master.tar.gz |
Fix issue #318015.upstream-master
3 files changed, 38 insertions, 2 deletions
diff --git a/asm-util/src/main/java/org/objectweb/asm/util/CheckFrameAnalyzer.java b/asm-util/src/main/java/org/objectweb/asm/util/CheckFrameAnalyzer.java index c693df93..b58398c2 100644 --- a/asm-util/src/main/java/org/objectweb/asm/util/CheckFrameAnalyzer.java +++ b/asm-util/src/main/java/org/objectweb/asm/util/CheckFrameAnalyzer.java @@ -123,7 +123,7 @@ class CheckFrameAnalyzer<V extends Value> extends Analyzer<V> { } Frame<V>[] frames = getFrames(); - Frame<V> currentFrame = frames[0]; + Frame<V> currentFrame = newFrame(frames[0]); expandFrames(owner, method, currentFrame); for (int insnIndex = 0; insnIndex < insnList.size(); ++insnIndex) { Frame<V> oldFrame = frames[insnIndex]; diff --git a/asm-util/src/test/java/org/objectweb/asm/util/CheckFrameAnalyzerTest.java b/asm-util/src/test/java/org/objectweb/asm/util/CheckFrameAnalyzerTest.java index 154ea29c..bc8aa0db 100644 --- a/asm-util/src/test/java/org/objectweb/asm/util/CheckFrameAnalyzerTest.java +++ b/asm-util/src/test/java/org/objectweb/asm/util/CheckFrameAnalyzerTest.java @@ -27,6 +27,7 @@ // THE POSSIBILITY OF SUCH DAMAGE. package org.objectweb.asm.util; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -64,6 +65,22 @@ class CheckFrameAnalyzerTest extends AsmTest { private final Label label0 = new Label(); @Test + void testAnalyze_validBytecode() { + MethodNode methodNode = + new MethodNodeBuilder("(Ljava/lang/Object;)V", 1, 2) + .aload(0) + .astore(1) + .iconst_0() + .istore(0) + .vreturn() + .build(); + + Executable analyze = () -> newAnalyzer().analyze(CLASS_NAME, methodNode); + + assertDoesNotThrow(analyze); + } + + @Test void testAnalyze_invalidJsr() { MethodNode methodNode = new MethodNodeBuilder().jsr(label0).label(label0).vreturn().build(); diff --git a/asm-util/src/test/java/org/objectweb/asm/util/MethodNodeBuilder.java b/asm-util/src/test/java/org/objectweb/asm/util/MethodNodeBuilder.java index 33c369e3..1d2b6eec 100644 --- a/asm-util/src/test/java/org/objectweb/asm/util/MethodNodeBuilder.java +++ b/asm-util/src/test/java/org/objectweb/asm/util/MethodNodeBuilder.java @@ -47,7 +47,11 @@ final class MethodNodeBuilder { } MethodNodeBuilder(final int maxStack, final int maxLocals) { - methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "m", "()V", null, null); + this("()V", maxStack, maxLocals); + } + + MethodNodeBuilder(final String descriptor, final int maxStack, final int maxLocals) { + methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "m", descriptor, null, null); methodNode.maxStack = maxStack; methodNode.maxLocals = maxLocals; methodNode.visitCode(); @@ -63,6 +67,21 @@ final class MethodNodeBuilder { return this; } + MethodNodeBuilder istore(final int variable) { + methodNode.visitVarInsn(Opcodes.ISTORE, variable); + return this; + } + + MethodNodeBuilder aload(final int variable) { + methodNode.visitVarInsn(Opcodes.ALOAD, variable); + return this; + } + + MethodNodeBuilder astore(final int variable) { + methodNode.visitVarInsn(Opcodes.ASTORE, variable); + return this; + } + MethodNodeBuilder vreturn() { methodNode.visitInsn(Opcodes.RETURN); return this; |