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

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