diff options
author | drh <drh@noemail.net> | 2009-04-02 14:05:21 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2009-04-02 14:05:21 +0000 |
commit | 3034e3d3649c71770a11de94d38412d4abd4ef98 (patch) | |
tree | 3d35dcc854c6fbc6f03749ff9e2f2c2a3e5c7051 | |
parent | d27135ad82788344d832ffae8aad3f0aabc8939f (diff) | |
download | sqlite-3034e3d3649c71770a11de94d38412d4abd4ef98.tar.gz sqlite-3034e3d3649c71770a11de94d38412d4abd4ef98.zip |
Change the way that the random() SQL function prevents the maximum
negative integer so that it is testable. (CVS 6436)
FossilOrigin-Name: 995f2b9b1031fadc85e179701536b9dd4153654b
-rw-r--r-- | manifest | 12 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/func.c | 15 |
3 files changed, 19 insertions, 10 deletions
@@ -1,5 +1,5 @@ -C Use\sALWAYS\sand\sNEVER\smacros\son\sunchangeable\sconditions\swithin\sfunc.c.\s(CVS\s6435) -D 2009-04-02T13:36:37 +C Change\sthe\sway\sthat\sthe\srandom()\sSQL\sfunction\sprevents\sthe\smaximum\nnegative\sinteger\sso\sthat\sit\sis\stestable.\s(CVS\s6436) +D 2009-04-02T14:05:22 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -113,7 +113,7 @@ F src/date.c e6263ed8950642f593cb1a2cc8a73dd726cc7888 F src/delete.c eb1066b2f35489fee46ad765d2b66386fc7d8adf F src/expr.c 14853cd56107292de6af664a24c6255111a4257d F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff -F src/func.c 25edae19b56f7355ce7f25490ce61877b499633f +F src/func.c 99ae90d46154952e08282fcdfe72d08e9601e174 F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c F src/hash.c 5824e6ff7ba78cd34c8d6cd724367713583e5b55 F src/hash.h 28f38ebb1006a5beedcb013bcdfe31befe7437ae @@ -714,7 +714,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 868a487f5fd7c795e04a08de36a85ba1e06bc8c6 -R 80e3c0460455c327fb300729860153c0 +P eb65e64e7ed5edbe506365971d4d81ea037098d3 +R 8df4d225606e2ef05ef65f87475b71e8 U drh -Z 3dc25af9134f67a49baddf7ad8bedd6e +Z 5cdbeb238444c4b2ca5bad90a2a75082 diff --git a/manifest.uuid b/manifest.uuid index 88ef3ec34..8035b6202 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eb65e64e7ed5edbe506365971d4d81ea037098d3
\ No newline at end of file +995f2b9b1031fadc85e179701536b9dd4153654b
\ No newline at end of file diff --git a/src/func.c b/src/func.c index 537d35be1..6cb8d5aa9 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.229 2009/04/02 13:36:37 drh Exp $ +** $Id: func.c,v 1.230 2009/04/02 14:05:22 drh Exp $ */ #include "sqliteInt.h" #include <stdlib.h> @@ -362,8 +362,17 @@ static void randomFunc( sqlite_int64 r; UNUSED_PARAMETER2(NotUsed, NotUsed2); sqlite3_randomness(sizeof(r), &r); - if( (r<<1)==0 ) r = 0; /* Prevent 0x8000.... as the result so that we */ - /* can always do abs() of the result */ + if( r<0 ){ + /* We need to prevent a random number of 0x8000000000000000 + ** (or -9223372036854775808) since when you do abs() of that + ** number of you get the same value back again. To do this + ** in a way that is testable, mask the sign bit off of negative + ** values, resulting in a positive value. Then take the + ** 2s complement of that positive value. The end result can + ** therefore be no less than -9223372036854775807. + */ + r = -(r ^ (((sqlite3_int64)1)<<63)); + } sqlite3_result_int64(context, r); } |