You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/08/14 03:54:23 UTC

svn commit: r1372704 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/

Author: prestonc
Date: Tue Aug 14 01:54:22 2012
New Revision: 1372704

URL: http://svn.apache.org/viewvc?rev=1372704&view=rev
Log:
Read string in as a negative number so the max negative value will be allowed.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToByteOperation.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntOperation.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntegerOperation.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToShortOperation.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToByteOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToByteOperation.java?rev=1372704&r1=1372703&r2=1372704&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToByteOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToByteOperation.java Tue Aug 14 01:54:22 2012
@@ -79,29 +79,30 @@ public class CastToByteOperation extends
         long value = 0;
         int c = 0;
         boolean negative = false;
+        long limit = -Byte.MAX_VALUE;
 
         // Check the first character.
         c = charIterator.next();
         if (c == Character.valueOf('-') && negativeAllowed) {
             negative = true;
             c = charIterator.next();
+            limit = Byte.MIN_VALUE;
         }
 
         // Read the numeric value.
         do {
             if (Character.isDigit(c)) {
-                value = value * 10 + Character.getNumericValue(c);
+                if (value < limit + Character.getNumericValue(c)) {
+                    throw new SystemException(ErrorCode.FORG0001);
+                }
+                value = value * 10 - Character.getNumericValue(c);
             } else {
                 throw new SystemException(ErrorCode.FORG0001);
             }
         } while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
 
-        if (value > Byte.MAX_VALUE || value < Byte.MIN_VALUE) {
-            throw new SystemException(ErrorCode.FORG0001);
-        }
-
         dOut.write(returnTag);
-        dOut.write((byte) (negative ? -value : value));
+        dOut.write((byte) (negative ? value : -value));
     }
 
     @Override

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java?rev=1372704&r1=1372703&r2=1372704&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDoubleOperation.java Tue Aug 14 01:54:22 2012
@@ -73,12 +73,14 @@ public class CastToDoubleOperation exten
         int c = ICharacterIterator.EOS_CHAR;
         int c2 = ICharacterIterator.EOS_CHAR;
         int c3 = ICharacterIterator.EOS_CHAR;
+        long limit = -Long.MAX_VALUE;
 
         // Check sign.
         c = charIterator.next();
         if (c == Character.valueOf('-')) {
             negativeValue = true;
             c = charIterator.next();
+            limit = Long.MIN_VALUE;
         }
         // Check the special cases.
         if (c == Character.valueOf('I') || c == Character.valueOf('N')) {
@@ -97,10 +99,10 @@ public class CastToDoubleOperation exten
             // Read in the number.
             do {
                 if (Character.isDigit(c)) {
-                    if (value > Long.MAX_VALUE / 10) {
+                    if (value < limit / 10 + Character.getNumericValue(c)) {
                         throw new SystemException(ErrorCode.FOCA0006);
                     }
-                    value = value * 10 + Character.getNumericValue(c);
+                    value = value * 10 - Character.getNumericValue(c);
                     if (pastDecimal) {
                         decimalPlace--;
                     }
@@ -131,10 +133,10 @@ public class CastToDoubleOperation exten
                         throw new SystemException(ErrorCode.FORG0001);
                     }
                 } while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
-                decimalPlace += (negativeOffset ? -moveOffset : moveOffset);
-                if (decimalPlace > 324 || decimalPlace < -324) {
+                if (moveOffset > 324 || moveOffset < -324) {
                     throw new SystemException(ErrorCode.FOCA0006);
                 }
+                decimalPlace += (negativeOffset ? -moveOffset : moveOffset);
             }
 
             /*
@@ -205,7 +207,7 @@ public class CastToDoubleOperation exten
         }
 
         dOut.write(ValueTag.XS_DOUBLE_TAG);
-        dOut.writeDouble((negativeValue ? -valueDouble : valueDouble));
+        dOut.writeDouble((negativeValue ? valueDouble : -valueDouble));
     }
 
     @Override

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java?rev=1372704&r1=1372703&r2=1372704&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToFloatOperation.java Tue Aug 14 01:54:22 2012
@@ -98,7 +98,7 @@ public class CastToFloatOperation extend
             // Read in the number.
             do {
                 if (Character.isDigit(c)) {
-                    value = value * 10 + Character.getNumericValue(c);
+                    value = value * 10 - Character.getNumericValue(c);
                     if (pastDecimal) {
                         decimalPlace--;
                     }
@@ -149,7 +149,7 @@ public class CastToFloatOperation extend
                 } else if (decimalPlace <= 30) {
                     valueFloat *= powersOf10from20to30[decimalPlace];
                 } else if (decimalPlace <= 38) {
-                    valueFloat *= powersOf10from20to30[30];
+                    valueFloat *= powersOf10from20to30[10];
                     valueFloat *= powersOf10upTo10[decimalPlace - 30];
                 }
             } else {
@@ -161,17 +161,17 @@ public class CastToFloatOperation extend
                 } else if (decimalPlace >= -30) {
                     valueFloat /= powersOf10from20to30[-decimalPlace];
                 } else if (decimalPlace >= -40) {
-                    valueFloat /= powersOf10from20to30[30];
+                    valueFloat /= powersOf10from20to30[10];
                     valueFloat /= powersOf10upTo10[-decimalPlace - 30];
                 } else if (decimalPlace >= -45) {
-                    valueFloat /= powersOf10from20to30[20];
+                    valueFloat /= powersOf10from20to30[0];
                     valueFloat /= powersOf10from20to30[-decimalPlace - 20];
                 }
             }
         }
 
         dOut.write(ValueTag.XS_FLOAT_TAG);
-        dOut.writeFloat((negativeValue ? -valueFloat : valueFloat));
+        dOut.writeFloat((negativeValue ? valueFloat : -valueFloat));
     }
 
     @Override

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntOperation.java?rev=1372704&r1=1372703&r2=1372704&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntOperation.java Tue Aug 14 01:54:22 2012
@@ -79,29 +79,30 @@ public class CastToIntOperation extends 
         long value = 0;
         int c = 0;
         boolean negative = false;
+        long limit = -Integer.MAX_VALUE;
 
         // Check the first character.
         c = charIterator.next();
         if (c == Character.valueOf('-') && negativeAllowed) {
             negative = true;
             c = charIterator.next();
+            limit = Integer.MIN_VALUE;
         }
 
         // Read the numeric value.
         do {
             if (Character.isDigit(c)) {
-                value = value * 10 + Character.getNumericValue(c);
+                if (value < limit + Character.getNumericValue(c)) {
+                    throw new SystemException(ErrorCode.FORG0001);
+                }
+                value = value * 10 - Character.getNumericValue(c);
             } else {
                 throw new SystemException(ErrorCode.FORG0001);
             }
         } while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
 
-        if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
-            throw new SystemException(ErrorCode.FORG0001);
-        }
-
         dOut.write(returnTag);
-        dOut.writeInt((int) (negative ? -value : value));
+        dOut.writeInt((int) (negative ? value : -value));
     }
 
     @Override

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntegerOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntegerOperation.java?rev=1372704&r1=1372703&r2=1372704&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntegerOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToIntegerOperation.java Tue Aug 14 01:54:22 2012
@@ -80,12 +80,14 @@ public class CastToIntegerOperation exte
         long value = 0;
         int c = 0;
         boolean negative = false;
+        long limit = -Long.MAX_VALUE;
 
         // Check the first character.
         c = charIterator.next();
         if (c == Character.valueOf('-') && negativeAllowed) {
             negative = true;
             c = charIterator.next();
+            limit = Long.MIN_VALUE;
         } else if (negativeRequired) {
             throw new SystemException(ErrorCode.FORG0001);
         }
@@ -93,17 +95,17 @@ public class CastToIntegerOperation exte
         // Read the numeric value.
         do {
             if (Character.isDigit(c)) {
-                if (value > ((Long.MAX_VALUE - Character.getNumericValue(c)) / 10)) {
-                    throw new SystemException(ErrorCode.FOCA0001);
+                if (value < limit + Character.getNumericValue(c)) {
+                    throw new SystemException(ErrorCode.FORG0001);
                 }
-                value = value * 10 + Character.getNumericValue(c);
+                value = value * 10 - Character.getNumericValue(c);
             } else {
                 throw new SystemException(ErrorCode.FORG0001);
             }
         } while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
 
         dOut.write(returnTag);
-        dOut.writeLong((negative ? -value : value));
+        dOut.writeLong((negative ? value : -value));
     }
 
     @Override

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToShortOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToShortOperation.java?rev=1372704&r1=1372703&r2=1372704&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToShortOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToShortOperation.java Tue Aug 14 01:54:22 2012
@@ -79,29 +79,30 @@ public class CastToShortOperation extend
         long value = 0;
         int c = 0;
         boolean negative = false;
+        long limit = -Short.MAX_VALUE;
 
         // Check the first character.
         c = charIterator.next();
         if (c == Character.valueOf('-') && negativeAllowed) {
             negative = true;
             c = charIterator.next();
+            limit = Short.MIN_VALUE;
         }
-
+        
         // Read the numeric value.
         do {
             if (Character.isDigit(c)) {
-                value = value * 10 + Character.getNumericValue(c);
+                if (value < limit + Character.getNumericValue(c)) {
+                    throw new SystemException(ErrorCode.FORG0001);
+                }
+                value = value * 10 - Character.getNumericValue(c);
             } else {
                 throw new SystemException(ErrorCode.FORG0001);
             }
         } while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
 
-        if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) {
-            throw new SystemException(ErrorCode.FORG0001);
-        }
-
         dOut.write(returnTag);
-        dOut.writeShort((short) (negative ? -value : value));
+        dOut.writeShort((short) (negative ? value : -value));
     }
 
     @Override