aboutsummaryrefslogtreecommitdiff
path: root/src/func.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2006-02-23 21:43:55 +0000
committerdrh <drh@noemail.net>2006-02-23 21:43:55 +0000
commit52fc849a3c623da3ff5f3a1499bb9fadd9b14f95 (patch)
tree464c6a0ae58304e182eb7655efe701ca3bcc9b1b /src/func.c
parentfcce93f62cafbec01f150d5b4ef7717121dd49f1 (diff)
downloadsqlite-52fc849a3c623da3ff5f3a1499bb9fadd9b14f95.tar.gz
sqlite-52fc849a3c623da3ff5f3a1499bb9fadd9b14f95.zip
Detect integer overflow in the abs() function. The random() function
now provides 64 bits of randomness instead of just 32. Fix bugs in testing logic of test4.c. (CVS 3108) FossilOrigin-Name: 942c509595a2a300e798e6b048ad7fc3bc54af43
Diffstat (limited to 'src/func.c')
-rw-r--r--src/func.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/func.c b/src/func.c
index 6d1195961..be3fc943e 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.122 2006/02/11 17:34:00 drh Exp $
+** $Id: func.c,v 1.123 2006/02/23 21:43:56 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -121,7 +121,13 @@ static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_INTEGER: {
i64 iVal = sqlite3_value_int64(argv[0]);
- if( iVal<0 ) iVal = iVal * -1;
+ if( iVal<0 ){
+ if( (iVal<<1)==0 ){
+ sqlite3_result_error(context, "integer overflow", -1);
+ return;
+ }
+ iVal = -iVal;
+ }
sqlite3_result_int64(context, iVal);
break;
}
@@ -131,7 +137,7 @@ static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
}
default: {
double rVal = sqlite3_value_double(argv[0]);
- if( rVal<0 ) rVal = rVal * -1.0;
+ if( rVal<0 ) rVal = -rVal;
sqlite3_result_double(context, rVal);
break;
}
@@ -258,9 +264,9 @@ static void randomFunc(
int argc,
sqlite3_value **argv
){
- int r;
+ sqlite_int64 r;
sqlite3Randomness(sizeof(r), &r);
- sqlite3_result_int(context, r);
+ sqlite3_result_int64(context, r);
}
/*