1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-24 09:53:10 +03:00

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
This commit is contained in:
drh
2006-02-23 21:43:55 +00:00
parent fcce93f62c
commit 52fc849a3c
5 changed files with 38 additions and 18 deletions

View File

@@ -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);
}
/*