/ Check-in [3cc14b76]
Login

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

Overview
Comment:Fix an array index bug in the default busy callback handler. Ticket #1198. (CVS 2447)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3cc14b7606681d04eb56003a0996322e3b3bdc73
User & Date: drh 2005-04-28 12:06:06
Context
2005-04-28
17:18
Enhancements to allow for extensions. (CVS 2448) check-in: 6863703a user: drh tags: trunk
12:06
Fix an array index bug in the default busy callback handler. Ticket #1198. (CVS 2447) check-in: 3cc14b76 user: drh tags: trunk
2005-04-22
02:38
Remove some vestigal code. Add the experimental sqlite3_transfer_bindings() API. (CVS 2446) check-in: 88b39436 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.285 2005/03/29 23:34:58 danielk1977 Exp $
           17  +** $Id: main.c,v 1.286 2005/04/28 12:06:06 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
   614    614   ** argument.
   615    615   */
   616    616   static int sqliteDefaultBusyCallback(
   617    617    void *Timeout,           /* Maximum amount of time to wait */
   618    618    int count                /* Number of times table has been busy */
   619    619   ){
   620    620   #if SQLITE_MIN_SLEEP_MS==1
   621         -  static const char delays[] =
   622         -     { 1, 2, 5, 10, 15, 20, 25, 25,  25,  50,  50,  50, 100};
   623         -  static const short int totals[] =
   624         -     { 0, 1, 3,  8, 18, 33, 53, 78, 103, 128, 178, 228, 287};
          621  +  static const u8 delays[] =
          622  +     { 1, 2, 5, 10, 15, 20, 25, 25,  25,  50,  50, 100 };
          623  +  static const u8 totals[] =
          624  +     { 0, 1, 3,  8, 18, 33, 53, 78, 103, 128, 178, 228 };
   625    625   # define NDELAY (sizeof(delays)/sizeof(delays[0]))
   626    626     ptr timeout = (ptr)Timeout;
   627    627     ptr delay, prior;
   628    628   
   629         -  if( count <= NDELAY ){
   630         -    delay = delays[count-1];
   631         -    prior = totals[count-1];
          629  +  assert( count>=0 );
          630  +  if( count < NDELAY ){
          631  +    delay = delays[count];
          632  +    prior = totals[count];
   632    633     }else{
   633    634       delay = delays[NDELAY-1];
   634    635       prior = totals[NDELAY-1] + delay*(count-NDELAY-1);
   635    636     }
   636    637     if( prior + delay > timeout ){
   637    638       delay = timeout - prior;
   638    639       if( delay<=0 ) return 0;
................................................................................
  1153   1154     return rc;
  1154   1155   }
  1155   1156   #endif /* SQLITE_OMIT_UTF16 */
  1156   1157   
  1157   1158   /*
  1158   1159   ** This routine does the work of opening a database on behalf of
  1159   1160   ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"  
  1160         -** is UTF-8 encoded. The fourth argument, "def_enc" is one of the TEXT_*
  1161         -** macros from sqliteInt.h. If we end up creating a new database file
  1162         -** (not opening an existing one), the text encoding of the database
  1163         -** will be set to this value.
         1161  +** is UTF-8 encoded.
  1164   1162   */
  1165   1163   static int openDatabase(
  1166   1164     const char *zFilename, /* Database filename UTF-8 encoded */
  1167   1165     sqlite3 **ppDb         /* OUT: Returned database handle */
  1168   1166   ){
  1169   1167     sqlite3 *db;
  1170   1168     int rc, i;