/ Check-in [14a715c5]
Login

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

Overview
Comment:Fix an assert() failure that may follow an OOM error.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 14a715c5639b2bc69b129485ca32e96366dab4c4
User & Date: dan 2009-08-19 16:34:31
Context
2009-08-19
17:17
Change the way an Expr that has been converted to TK_REGISTER stores its original opcode. The previous method, overloading Expr.iColumn, did not work in all cases. check-in: 71ea9d0e user: dan tags: trunk
16:34
Fix an assert() failure that may follow an OOM error. check-in: 14a715c5 user: dan tags: trunk
16:21
Merge 29cafcfdcc and a6f39181a7. check-in: 740a93e8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

   104    104   */
   105    105   static void analyzeOneTable(
   106    106     Parse *pParse,   /* Parser context */
   107    107     Table *pTab,     /* Table whose indices are to be analyzed */
   108    108     int iStatCur,    /* Index of VdbeCursor that writes the sqlite_stat1 table */
   109    109     int iMem         /* Available memory locations begin here */
   110    110   ){
          111  +  sqlite3 *db = pParse->db;    /* Database handle */
   111    112     Index *pIdx;                 /* An index to being analyzed */
   112    113     int iIdxCur;                 /* Cursor open on index being analyzed */
   113    114     Vdbe *v;                     /* The virtual machine being built up */
   114    115     int i;                       /* Loop counter */
   115    116     int topOfLoop;               /* The top of the loop */
   116    117     int endOfLoop;               /* The end of the loop */
   117    118     int addr;                    /* The address of an instruction */
................................................................................
   131    132   #endif
   132    133   
   133    134     v = sqlite3GetVdbe(pParse);
   134    135     if( v==0 || NEVER(pTab==0) || pTab->pIndex==0 ){
   135    136       /* Do no analysis for tables that have no indices */
   136    137       return;
   137    138     }
   138         -  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
   139         -  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
          139  +  assert( sqlite3BtreeHoldsAllMutexes(db) );
          140  +  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   140    141     assert( iDb>=0 );
   141    142   #ifndef SQLITE_OMIT_AUTHORIZATION
   142    143     if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
   143         -      pParse->db->aDb[iDb].zName ) ){
          144  +      db->aDb[iDb].zName ) ){
   144    145       return;
   145    146     }
   146    147   #endif
   147    148   
   148    149     /* Establish a read-lock on the table at the shared-cache level. */
   149    150     sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
   150    151   
................................................................................
   154    155       KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
   155    156   
   156    157       if( iMem+1+(nCol*2)>pParse->nMem ){
   157    158         pParse->nMem = iMem+1+(nCol*2);
   158    159       }
   159    160   
   160    161       /* Open a cursor to the index to be analyzed. */
   161         -    assert( iDb==sqlite3SchemaToIndex(pParse->db, pIdx->pSchema) );
          162  +    assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
   162    163       sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb,
   163    164           (char *)pKey, P4_KEYINFO_HANDOFF);
   164    165       VdbeComment((v, "%s", pIdx->zName));
   165    166   
   166    167       /* Populate the registers containing the table and index names. */
   167    168       if( pTab->pIndex==pIdx ){
   168    169         sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
................................................................................
   255    256           sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
   256    257         }
   257    258   #endif
   258    259   
   259    260         sqlite3VdbeAddOp3(v, OP_Ne, regCol, 0, iMem+nCol+i+1);
   260    261         /**** TODO:  add collating sequence *****/
   261    262         sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
          263  +    }
          264  +    if( db->mallocFailed ){
          265  +      /* If a malloc failure has occurred, then the result of the expression 
          266  +      ** passed as the second argument to the call to sqlite3VdbeJumpHere() 
          267  +      ** below may be negative. Which causes an assert() to fail (or an
          268  +      ** out-of-bounds write if SQLITE_DEBUG is not defined).  */
          269  +      return;
   262    270       }
   263    271       sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
   264    272       for(i=0; i<nCol; i++){
   265    273         sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-(nCol*2));
   266    274         sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
   267    275         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
   268    276       }