From dc2d94de56ae83b7a986de97caba7f64fcdade30 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 27 Jul 2003 17:16:06 +0000 Subject: [PATCH] In the VDBE, when an integer value will not fit into a 32-bit int, store it in a double instead. Ticket #408. (CVS 1064) FossilOrigin-Name: 7514c3db165e8cc5c696b2b345844949a0e45a61 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 17 +++++++++-------- test/misc2.test | 39 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 8a0e37f6e0..c5eb43e194 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s2.8.5\s(CVS\s1063) -D 2003-07-22T13:20:28 +C In\sthe\sVDBE,\swhen\san\sinteger\svalue\swill\snot\sfit\sinto\sa\s32-bit\sint,\sstore\sit\nin\sa\sdouble\sinstead.\s\sTicket\s#408.\s(CVS\s1064) +D 2003-07-27T17:16:07 F Makefile.in 9ad23ed4ca97f9670c4496432e3fbd4b3760ebde F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -59,7 +59,7 @@ F src/trigger.c 6ff205aaac4869e402d9902e528e1d22a85de14c F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397 F src/util.c 566c7780170dd11fb1ad5de3ba81f0dfea7cccf0 F src/vacuum.c 0820984615786c9ccdaad8032a792309b354a8eb -F src/vdbe.c b5feda6d6fd818dc4541323b0f61bf03e1c89b91 +F src/vdbe.c 779fa3b15148161282a71241ff9733a54a8b0648 F src/vdbe.h d853ed6cc4727fa9e8ace6187c55afcf817041dd F src/where.c 83b2a2d26d5c3bea33457a83e541bb1dcf7b1248 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242 @@ -97,7 +97,7 @@ F test/memdb.test cd4580f466f34c42354612a375c5adb90447e4c4 F test/memleak.test a18e6810cae96d2f6f5136920267adbefc8e1e90 F test/minmax.test 6d9b6d6ee34f42e2a58dffece1f76d35f446b3af F test/misc1.test c7dc2f2bd702d8283e885a64ec0714be26cfb051 -F test/misc2.test 36410e371d3924f7373988935219bda5a52cea4e +F test/misc2.test d8a0b59399a53fd27e74a8fac2a22d5271b9bded F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0 F test/null.test 5c2b57307e4b6178aae825eb65ddbee01e76b0fd @@ -168,7 +168,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 -P 510761cf505222c68ce3404aad94e1cc28b703ed -R 3cdebdbdf77168c78500a77d55386f84 +P 95fba440e79c066c0d6f6205a3d7dcb6c870b1c9 +R e9b4de6f6867968162bbbf4cd0e0f4a9 U drh -Z 5c66706afb60592fa14ef3a74a39762b +Z 3a09a33ae6ae46b79a22e81ad9d2a3ad diff --git a/manifest.uuid b/manifest.uuid index 0f91dfa1ab..507a98e290 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95fba440e79c066c0d6f6205a3d7dcb6c870b1c9 \ No newline at end of file +7514c3db165e8cc5c696b2b345844949a0e45a61 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 4c230d0190..d6739dddb4 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -36,7 +36,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.234 2003/07/22 09:24:45 danielk1977 Exp $ +** $Id: vdbe.c,v 1.235 2003/07/27 17:16:07 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -997,8 +997,10 @@ static void hardRelease(Vdbe *p, int i){ } /* -** Return TRUE if zNum is an integer and write -** the value of the integer into *pNum. +** Return TRUE if zNum is a 32-bit signed integer and write +** the value of the integer into *pNum. If zNum is not an integer +** or is an integer that is too large to be expressed with just 32 +** bits, then return false. ** ** Under Linux (RedHat 7.2) this routine is much faster than atoi() ** for converting strings into integers. @@ -1006,6 +1008,7 @@ static void hardRelease(Vdbe *p, int i){ static int toInt(const char *zNum, int *pNum){ int v = 0; int neg; + int i, c; if( *zNum=='-' ){ neg = 1; zNum++; @@ -1015,13 +1018,11 @@ static int toInt(const char *zNum, int *pNum){ }else{ neg = 0; } - if( *zNum==0 ) return 0; - while( isdigit(*zNum) ){ - v = v*10 + *zNum - '0'; - zNum++; + for(i=0; (c=zNum[i])>='0' && c<='9'; i++){ + v = v*10 + c - '0'; } *pNum = neg ? -v : v; - return *zNum==0; + return c==0 && i>0 && (i<10 || (i==10 && memcmp(zNum,"2147483647",10)<=0)); } /* diff --git a/test/misc2.test b/test/misc2.test index 2fc7b171d1..cb2b53d86f 100644 --- a/test/misc2.test +++ b/test/misc2.test @@ -13,7 +13,7 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc2.test,v 1.4 2003/07/09 16:34:56 drh Exp $ +# $Id: misc2.test,v 1.5 2003/07/27 17:16:08 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -61,3 +61,40 @@ do_test misc2-3.1 { SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10 } } {1 {ambiguous column name: a}} + +# Make sure 32-bit integer overflow is handled properly in queries. +# ticket #408 +# +do_test misc2-4.1 { + execsql { + INSERT INTO t1 VALUES(4000000000,'a','b'); + SELECT a FROM t1 WHERE a>1; + } +} {4000000000} +do_test misc2-4.2 { + execsql { + INSERT INTO t1 VALUES(2147483648,'b2','c2'); + INSERT INTO t1 VALUES(2147483647,'b3','c3'); + SELECT a FROM t1 WHERE a>2147483647; + } +} {4000000000 2147483648} +do_test misc2-4.3 { + execsql { + SELECT a FROM t1 WHERE a<2147483648; + } +} {1 2147483647} +do_test misc2-4.4 { + execsql { + SELECT a FROM t1 WHERE a<=2147483648; + } +} {1 2147483648 2147483647} +do_test misc2-4.5 { + execsql { + SELECT a FROM t1 WHERE a<10000000000; + } +} {1 4000000000 2147483648 2147483647} +do_test misc2-4.6 { + execsql { + SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1; + } +} {1 2147483647 2147483648 4000000000}