1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-24 09:53:10 +03:00

Avoid overflowing the 48-bit mantissa of a floating point number when

summing large integers in the SUM() function.  Ticket #1664. (CVS 3061)

FossilOrigin-Name: a9169e879de5d5e4192d1681bc3e119fb83e739c
This commit is contained in:
drh
2006-02-09 13:38:19 +00:00
parent ff22e18b3c
commit fc6ad39cf8
4 changed files with 25 additions and 14 deletions

View 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);
}
/*