commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1696777 - in /commons/proper/bcel/trunk/src: changes/ main/java/org/apache/commons/bcel6/generic/
Date Thu, 20 Aug 2015 12:19:42 GMT
Author: sebb
Date: Thu Aug 20 12:19:42 2015
New Revision: 1696777

URL: http://svn.apache.org/r1696777
Log:
BCEL-249 Check for max Short seems wrong

Modified:
    commons/proper/bcel/trunk/src/changes/changes.xml
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/BranchInstruction.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/GOTO.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/JSR.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java

Modified: commons/proper/bcel/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1696777&r1=1696776&r2=1696777&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml Thu Aug 20 12:19:42 2015
@@ -63,6 +63,7 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="6.0" date="TBA" description="Major release with Java 7 and 8 support">
+      <action issue="BCEL-249" type="fix">Check for max Short seems wrong</action>
       <action issue="BCEL-127" type="update">Document that Instruction Factory returns
singleton instances</action>
       <action issue="BCEL-198" type="update">better support for clone/copy methods</action>
       <action issue="BCEL-242" type="remove">Remove Serializable</action>

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/BranchInstruction.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/BranchInstruction.java?rev=1696777&r1=1696776&r2=1696777&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/BranchInstruction.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/BranchInstruction.java
Thu Aug 20 12:19:42 2015
@@ -63,7 +63,7 @@ public abstract class BranchInstruction
     public void dump( DataOutputStream out ) throws IOException {
         out.writeByte(opcode);
         index = getTargetOffset();
-        if (Math.abs(index) >= 32767) {
+        if (!isValidShort(index)) {
             throw new ClassGenException("Branch target offset too large for short: " + index);
         }
         out.writeShort(index); // May be negative, i.e., point backwards

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/GOTO.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/GOTO.java?rev=1696777&r1=1696776&r2=1696777&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/GOTO.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/GOTO.java Thu
Aug 20 12:19:42 2015
@@ -69,7 +69,7 @@ public class GOTO extends GotoInstructio
     protected int updatePosition( int offset, int max_offset ) {
         int i = getTargetOffset(); // Depending on old position value
         setGetPosition(getPosition() + offset); // Position may be shifted by preceding expansions
-        if (Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
+        if (Math.abs(i) >= (Short.MAX_VALUE - max_offset)) { // to large for short (estimate)
             opcode = org.apache.commons.bcel6.Constants.GOTO_W;
             short old_length = length;
             length = 5;

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java?rev=1696777&r1=1696776&r2=1696777&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
Thu Aug 20 12:19:42 2015
@@ -543,4 +543,24 @@ public abstract class Instruction implem
     public int hashCode() {
         return opcode;
     }
+
+    /**
+     * Check if the value can fit in a byte (signed)
+     * @param value the value to check
+     * @return true if the value is in range
+     * @since 6.0
+     */
+    public static boolean isValidByte(int value) {
+        return value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE;
+    }
+
+    /**
+     * Check if the value can fit in a short (signed)
+     * @param value the value to check
+     * @return true if the value is in range
+     * @since 6.0
+     */
+    public static boolean isValidShort(int value) {
+        return value >= Short.MIN_VALUE && value <= Short.MAX_VALUE;
+    }
 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/JSR.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/JSR.java?rev=1696777&r1=1696776&r2=1696777&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/JSR.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/JSR.java Thu
Aug 20 12:19:42 2015
@@ -61,7 +61,7 @@ public class JSR extends JsrInstruction
     protected int updatePosition( int offset, int max_offset ) {
         int i = getTargetOffset(); // Depending on old position value
         setGetPosition(getPosition() + offset); // Position may be shifted by preceding expansions
-        if (Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
+        if (Math.abs(i) >= (Short.MAX_VALUE - max_offset)) { // to large for short (estimate)
             opcode = org.apache.commons.bcel6.Constants.JSR_W;
             short old_length = length;
             length = 5;

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java?rev=1696777&r1=1696776&r2=1696777&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java Thu
Aug 20 12:19:42 2015
@@ -39,9 +39,9 @@ public final class PUSH implements Compo
     public PUSH(ConstantPoolGen cp, int value) {
         if ((value >= -1) && (value <= 5)) {
             instruction = InstructionConstants.getInstruction(Constants.ICONST_0 + value);
-        } else if ((value >= -128) && (value <= 127)) {
+        } else if (Instruction.isValidByte(value)) {
             instruction = new BIPUSH((byte) value);
-        } else if ((value >= -32768) && (value <= 32767)) {
+        } else if (Instruction.isValidShort(value)) {
             instruction = new SIPUSH((short) value);
         } else {
             instruction = new LDC(cp.addInteger(value));



Mime
View raw message