Blame SOURCES/sqlite-3.7.17-real-cast.patch

bfaf7a
diff -ur sqlite-src.old/src/util.c sqlite-src-3071700/src/util.c
bfaf7a
--- sqlite-src.old/src/util.c	2013-11-28 09:57:32.167493980 +0100
bfaf7a
+++ sqlite-src-3071700/src/util.c	2013-11-28 09:59:01.877811972 +0100
bfaf7a
@@ -511,7 +511,7 @@
bfaf7a
     u = u*10 + c - '0';
bfaf7a
   }
bfaf7a
   if( u>LARGEST_INT64 ){
bfaf7a
-    *pNum = SMALLEST_INT64;
bfaf7a
+    *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
bfaf7a
   }else if( neg ){
bfaf7a
     *pNum = -(i64)u;
bfaf7a
   }else{
bfaf7a
@@ -542,7 +542,6 @@
bfaf7a
       /* zNum is exactly 9223372036854775808.  Fits if negative.  The
bfaf7a
       ** special case 2 overflow if positive */
bfaf7a
       assert( u-1==LARGEST_INT64 );
bfaf7a
-      assert( (*pNum)==SMALLEST_INT64 );
bfaf7a
       return neg ? 0 : 2;
bfaf7a
     }
bfaf7a
   }
bfaf7a
diff -ur sqlite-src.old/src/vdbe.c sqlite-src-3071700/src/vdbe.c
bfaf7a
--- sqlite-src.old/src/vdbe.c	2013-11-28 09:57:32.162493963 +0100
bfaf7a
+++ sqlite-src-3071700/src/vdbe.c	2013-11-28 10:04:01.533814781 +0100
bfaf7a
@@ -3465,7 +3465,9 @@
bfaf7a
         ** point number. */
bfaf7a
         assert( (pIn3->flags & MEM_Real)!=0 );
bfaf7a
 
bfaf7a
-        if( iKey==SMALLEST_INT64 && (pIn3->r<(double)iKey || pIn3->r>0) ){
bfaf7a
+        if( (iKey==SMALLEST_INT64 && pIn3->r<(double)iKey)
bfaf7a
+         || (iKey==LARGEST_INT64 && pIn3->r>(double)iKey)
bfaf7a
+        ){
bfaf7a
           /* The P3 value is too large in magnitude to be expressed as an
bfaf7a
           ** integer. */
bfaf7a
           res = 1;
bfaf7a
diff -ur sqlite-src.old/src/vdbemem.c sqlite-src-3071700/src/vdbemem.c
bfaf7a
--- sqlite-src.old/src/vdbemem.c	2013-11-28 09:57:32.162493963 +0100
bfaf7a
+++ sqlite-src-3071700/src/vdbemem.c	2013-11-28 10:00:14.877065531 +0100
bfaf7a
@@ -303,15 +303,8 @@
bfaf7a
 
bfaf7a
 /*
bfaf7a
 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
bfaf7a
-** If the double is too large, return 0x8000000000000000.
bfaf7a
-**
bfaf7a
-** Most systems appear to do this simply by assigning
bfaf7a
-** variables and without the extra range tests.  But
bfaf7a
-** there are reports that windows throws an expection
bfaf7a
-** if the floating point value is out of range. (See ticket #2880.)
bfaf7a
-** Because we do not completely understand the problem, we will
bfaf7a
-** take the conservative approach and always do range tests
bfaf7a
-** before attempting the conversion.
bfaf7a
+** If the double is out of range of a 64-bit signed integer then
bfaf7a
+** return the closest available 64-bit signed integer.
bfaf7a
 */
bfaf7a
 static i64 doubleToInt64(double r){
bfaf7a
 #ifdef SQLITE_OMIT_FLOATING_POINT
bfaf7a
@@ -328,14 +321,10 @@
bfaf7a
   static const i64 maxInt = LARGEST_INT64;
bfaf7a
   static const i64 minInt = SMALLEST_INT64;
bfaf7a
 
bfaf7a
-  if( r<(double)minInt ){
bfaf7a
-    return minInt;
bfaf7a
-  }else if( r>(double)maxInt ){
bfaf7a
-    /* minInt is correct here - not maxInt.  It turns out that assigning
bfaf7a
-    ** a very large positive number to an integer results in a very large
bfaf7a
-    ** negative integer.  This makes no sense, but it is what x86 hardware
bfaf7a
-    ** does so for compatibility we will do the same in software. */
bfaf7a
+  if( r<=(double)minInt ){
bfaf7a
     return minInt;
bfaf7a
+  }else if( r>=(double)maxInt ){
bfaf7a
+    return maxInt;
bfaf7a
   }else{
bfaf7a
     return (i64)r;
bfaf7a
   }
bfaf7a
@@ -417,17 +406,11 @@
bfaf7a
   **
bfaf7a
   ** The second and third terms in the following conditional enforces
bfaf7a
   ** the second condition under the assumption that addition overflow causes
bfaf7a
-  ** values to wrap around.  On x86 hardware, the third term is always
bfaf7a
-  ** true and could be omitted.  But we leave it in because other
bfaf7a
-  ** architectures might behave differently.
bfaf7a
+  ** values to wrap around.
bfaf7a
   */
bfaf7a
   if( pMem->r==(double)pMem->u.i
bfaf7a
    && pMem->u.i>SMALLEST_INT64
bfaf7a
-#if defined(__i486__) || defined(__x86_64__)
bfaf7a
-   && ALWAYS(pMem->u.i
bfaf7a
-#else
bfaf7a
    && pMem->u.i
bfaf7a
-#endif
bfaf7a
   ){
bfaf7a
     pMem->flags |= MEM_Int;
bfaf7a
   }
bfaf7a
diff -ur sqlite-src.old/test/autoinc.test sqlite-src-3071700/test/autoinc.test
bfaf7a
--- sqlite-src.old/test/autoinc.test	2013-11-28 09:57:32.145493901 +0100
bfaf7a
+++ sqlite-src-3071700/test/autoinc.test	2013-11-28 10:00:25.973101898 +0100
bfaf7a
@@ -216,7 +216,7 @@
bfaf7a
 } {t1 1238}
bfaf7a
 do_test autoinc-2.28 {
bfaf7a
   execsql {
bfaf7a
-    UPDATE sqlite_sequence SET seq='12345678901234567890'
bfaf7a
+    UPDATE sqlite_sequence SET seq='-12345678901234567890'
bfaf7a
       WHERE name='t1';
bfaf7a
     INSERT INTO t1 VALUES(NULL,6);
bfaf7a
     SELECT * FROM t1;
bfaf7a
diff -ur sqlite-src.old/test/e_expr.test sqlite-src-3071700/test/e_expr.test
bfaf7a
--- sqlite-src.old/test/e_expr.test	2013-11-28 09:57:32.130493848 +0100
bfaf7a
+++ sqlite-src-3071700/test/e_expr.test	2013-11-28 10:00:32.053121919 +0100
bfaf7a
@@ -1606,14 +1606,14 @@
bfaf7a
 # an INTEGER then the result of the cast is the largest negative
bfaf7a
 # integer: -9223372036854775808.
bfaf7a
 #
bfaf7a
-do_expr_test e_expr-31.2.1 { CAST(2e+50 AS INT) } integer -9223372036854775808
bfaf7a
+do_expr_test e_expr-31.2.1 { CAST(2e+50 AS INT) } integer 9223372036854775807
bfaf7a
 do_expr_test e_expr-31.2.2 { CAST(-2e+50 AS INT) } integer -9223372036854775808
bfaf7a
 do_expr_test e_expr-31.2.3 { 
bfaf7a
   CAST(-9223372036854775809.0 AS INT)
bfaf7a
 } integer -9223372036854775808
bfaf7a
 do_expr_test e_expr-31.2.4 { 
bfaf7a
   CAST(9223372036854775809.0 AS INT)
bfaf7a
-} integer -9223372036854775808
bfaf7a
+} integer 9223372036854775807
bfaf7a
 
bfaf7a
 
bfaf7a
 # EVIDENCE-OF: R-09295-61337 Casting a TEXT or BLOB value into NUMERIC