/ Check-in [5d2e7ea0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sure the random() function always returns a value that can be passed to abs(). (CVS 3109)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5d2e7ea01989fc9ba2c79d192760bc29f8cab463
User & Date: drh 2006-02-23 21:51:13
Context
2006-02-24
02:53
Remove unused parameters on internal APIs. Suppress warnings from CodeWarrior. (CVS 3110) check-in: 4b22e4b8 user: drh tags: trunk
2006-02-23
21:51
Make sure the random() function always returns a value that can be passed to abs(). (CVS 3109) check-in: 5d2e7ea0 user: drh tags: trunk
21:43
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) check-in: 942c5095 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/func.c.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
262
263
264
265
266
267
268


269
270
271
272
273
274
275
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.123 2006/02/23 21:43:56 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/* #include <math.h> */
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"
................................................................................
static void randomFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  sqlite_int64 r;
  sqlite3Randomness(sizeof(r), &r);


  sqlite3_result_int64(context, r);
}

/*
** Implementation of the last_insert_rowid() SQL function.  The return
** value is the same as the sqlite3_last_insert_rowid() API function.
*/







|







 







>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.124 2006/02/23 21:51:13 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/* #include <math.h> */
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"
................................................................................
static void randomFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  sqlite_int64 r;
  sqlite3Randomness(sizeof(r), &r);
  if( (r<<1)==0 ) r = 0;  /* Prevent 0x8000.... as the result so that we */
                          /* can always do abs() of the result */
  sqlite3_result_int64(context, r);
}

/*
** Implementation of the last_insert_rowid() SQL function.  The return
** value is the same as the sqlite3_last_insert_rowid() API function.
*/