]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Avoid overflowing the 48-bit mantissa of a floating point number when
authordrh <drh@noemail.net>
Thu, 9 Feb 2006 13:38:19 +0000 (13:38 +0000)
committerdrh <drh@noemail.net>
Thu, 9 Feb 2006 13:38:19 +0000 (13:38 +0000)
summing large integers in the SUM() function.  Ticket #1664. (CVS 3061)

FossilOrigin-Name: a9169e879de5d5e4192d1681bc3e119fb83e739c

manifest
manifest.uuid
src/func.c
test/func.test

index e27cd29889da0edad1e8eed994accad5c2e77eb5..384e4c869d5a62cf212566c4dd8bc37aec76f019 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correctly\shandle\sCOLLATE\sclauses\sin\stables\sbeing\smodified\sby\san\nALTER\sTABLE\sADD\sCOLUMN\scommand.\s\sTicket\s#1665.\s(CVS\s3060)
-D 2006-02-09T02:56:03
+C Avoid\soverflowing\sthe\s48-bit\smantissa\sof\sa\sfloating\spoint\snumber\swhen\nsumming\slarge\sintegers\sin\sthe\sSUM()\sfunction.\s\sTicket\s#1664.\s(CVS\s3061)
+D 2006-02-09T13:38:20
 F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b
 F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -43,7 +43,7 @@ F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e
 F src/delete.c 56ab34c3a384caa5d5ea06f5739944957e2e4213
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
 F src/expr.c 1149c3380bfce27703f5e9bec7dfb8e51baaf9d9
-F src/func.c 96b26601c092b7b43a13e440e3f988b32a385f6a
+F src/func.c b21d89f5a11634847c9ab3ead42e75586db538b2
 F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c 7e931b7f06afbcefcbbaab175c02eff8268db33f
@@ -163,7 +163,7 @@ F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030
 F test/expr.test 4e65cade931e14a0194eee41e33707e7af5f397a
 F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
 F test/format4.test 9f31d41d4f926cab97b2ebe6be00a6ab12dece87
-F test/func.test 337888172c054c2de1aa3bacad6115522943dc2c
+F test/func.test ef312ca92480e5bfa699c30643e4174247db686d
 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a
 F test/in.test 40feeebc7e38576255051aad428322be1545e0f1
 F test/index.test c478459611ded74745fee57f99f424da8a5f5fbd
@@ -350,7 +350,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 8b3068aca7b28d2b6c326f632bb9fe9b4940792d
-R 47553fd44adabe1f2b524acd7a9ad936
+P baef2f66be164910881278ea527d2be75ac2e944
+R 447165c89df570db65d416c0baa9b959
 U drh
-Z 958b2cb828e348f813795762ac6399a1
+Z 308693939eb8035424937f098052bb3a
index f425086e033bc444c1c2da7b54d8b17a17cf4233..2a1f6fe2ce72cf9355033bc10e1157e2e27238e9 100644 (file)
@@ -1 +1 @@
-baef2f66be164910881278ea527d2be75ac2e944
\ No newline at end of file
+a9169e879de5d5e4192d1681bc3e119fb83e739c
\ No newline at end of file
index 35caa6dcff5c9a65e4d1192b0ed8bba4dbf69860..35b1ce9a0cd99e045d9269b58563345e58c57012 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.117 2006/01/17 13:21:40 danielk1977 Exp $
+** $Id: func.c,v 1.118 2006/02/09 13:38:20 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -817,8 +817,8 @@ static void test_error(
 */
 typedef struct SumCtx SumCtx;
 struct SumCtx {
-  double sum;     /* Sum of terms */
-  int cnt;        /* Number of elements summed */
+  LONGDOUBLE_TYPE sum;    /* Sum of terms */
+  u32 cnt;                /* Number of elements summed */
   u8 seenFloat;   /* True if there has been any floating point value */
 };
 
@@ -886,7 +886,7 @@ struct StdDevCtx {
 */
 typedef struct CountCtx CountCtx;
 struct CountCtx {
-  int n;
+  i64 n;
 };
 
 /*
@@ -902,7 +902,7 @@ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
 static void countFinalize(sqlite3_context *context){
   CountCtx *p;
   p = sqlite3_aggregate_context(context, 0);
-  sqlite3_result_int(context, p ? p->n : 0);
+  sqlite3_result_int64(context, p ? p->n : 0);
 }
 
 /*
index 4af372c3979d98492bfc961bac64a036ba110b2e..cf4b7383a86f16c85fb784ee39adc356f3190b09 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing built-in functions.
 #
-# $Id: func.test,v 1.44 2006/01/20 15:45:37 drh Exp $
+# $Id: func.test,v 1.45 2006/02/09 13:38:21 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -538,4 +538,15 @@ do_test func-18.6 {
   }
 } {123}
 
+# Ticket #1664: 64-bit overflow in sum()
+#
+do_test func-18.10 {
+  execsql {
+    CREATE TABLE t6(x INTEGER);
+    INSERT INTO t6 VALUES(1);
+    INSERT INTO t6 VALUES(1<<62);
+    SELECT sum(x) - ((1<<62)+1) from t6;
+  }
+} 0
+
 finish_test