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
This commit is contained in:
drh 2012-12-10 22:19:14 +00:00
parent b136e902ad
commit be707b396a
3 changed files with 12 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C Modify\sreleasetest.tcl\sso\sthat\sit\sruns\sthe\s"checksymbols"\stest\son\sa\sbuild\swithout\sSQLITE_DEBUG\sdefined.\sIf\sSQLITE_DEBUG\sis\sdefined,\sthe\ssqlite3WhereTrace\svariable\scauses\sthe\stest\sto\sfail.
D 2012-12-10T10:22:48.067
C When\san\sarithmetic\soperation\swith\stwo\sinteger\soperands\smust\sgive\sa\s\nfloating-point\sanswer\sdue\sto\soverflow,\smake\ssure\sthe\sanswer\sis\snot\nrounded\sback\sto\sinteger\sby\saffinity.
D 2012-12-10T22:19:14.915
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 690d441a758cbffd13e814dc2724a721a6ebd400
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -237,7 +237,7 @@ F src/update.c 28d2d098b43a2c70dae399896ea8a02f622410ef
F src/utf.c 8d819e2e5104a430fc2005f018db14347c95a38f
F src/util.c 0af2e515dc0dabacec931bca39525f6c3f1c5455
F src/vacuum.c 2727bdd08847fcb6b2d2da6d14f018910e8645d3
F src/vdbe.c fb1d2b75d3674cbad68a8c810f0bd27e977369c4
F src/vdbe.c f51eb3207594703d24e91335cb16906e894b48aa
F src/vdbe.h b52887278cb173e66188da84dfab216bea61119d
F src/vdbeInt.h 79abf9b31be406d35ca77d6999cb2d42aaf91e78
F src/vdbeapi.c 4c2418161cf45392ba76a7ca92f9a5f06b96f89c
@ -1025,7 +1025,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P ee662c039d67f118008485d95603c5a43fcac75f
R 99976229de7a1d73e2300bb3e2610e17
U dan
Z 60b80bb1966596bbdb0785b6ee10792d
P 75e545a9e2614fae7db86ecfb84e41ecbe4097ba
R 181353fe376d2fba8949034c976d8829
U drh
Z d04d8a3f1a11b6d0d53258b48058f73d

View File

@ -1 +1 @@
75e545a9e2614fae7db86ecfb84e41ecbe4097ba
bd7aeeb691fee69dd6a562138a7aba8e8e192272

View File

@ -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