aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2012-12-10 22:19:14 +0000
committerdrh <drh@noemail.net>2012-12-10 22:19:14 +0000
commitbe707b396a9c43480c32b6f455f02f9b2c8e6a03 (patch)
treeb573e3b990a8cd1c8872a1d790d55b66876b442d /src
parentb136e902adae1379d9a1d7e50be7f7334f42f893 (diff)
downloadsqlite-be707b396a9c43480c32b6f455f02f9b2c8e6a03.tar.gz
sqlite-be707b396a9c43480c32b6f455f02f9b2c8e6a03.zip
When an arithmetic operation with two integer operands must give a
floating-point answer due to overflow, make sure the answer is not rounded back to integer by affinity. FossilOrigin-Name: bd7aeeb691fee69dd6a562138a7aba8e8e192272
Diffstat (limited to 'src')
-rw-r--r--src/vdbe.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/vdbe.c b/src/vdbe.c
index ab54fe470..a2ab31e87 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -1270,6 +1270,7 @@ case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
+ char bIntint; /* Started out as two integer operands */
int flags; /* Combined MEM_* flags from both inputs */
i64 iA; /* Integer value of left operand */
i64 iB; /* Integer value of right operand */
@@ -1286,6 +1287,7 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
iA = pIn1->u.i;
iB = pIn2->u.i;
+ bIntint = 1;
switch( pOp->opcode ){
case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
@@ -1306,6 +1308,7 @@ case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
pOut->u.i = iB;
MemSetTypeFlag(pOut, MEM_Int);
}else{
+ bIntint = 0;
fp_math:
rA = sqlite3VdbeRealValue(pIn1);
rB = sqlite3VdbeRealValue(pIn2);
@@ -1337,7 +1340,7 @@ fp_math:
}
pOut->r = rB;
MemSetTypeFlag(pOut, MEM_Real);
- if( (flags & MEM_Real)==0 ){
+ if( (flags & MEM_Real)==0 && !bIntint ){
sqlite3VdbeIntegerAffinity(pOut);
}
#endif