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

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