/ Check-in [e15f4706]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix some broken asserts in btree.c and vdbeaux.c that may fail following an OOM error.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | threads
Files: files | file ages | folders
SHA1: e15f47064bef431c0afd8bf93eb4e160c23ad562
User & Date: dan 2014-05-02 17:12:41
Context
2014-05-02
18:05
Merge orderby-planning with this branch. check-in: d9549de3 user: dan tags: threads
17:12
Fix some broken asserts in btree.c and vdbeaux.c that may fail following an OOM error. check-in: e15f4706 user: dan tags: threads
16:03
Remove a faulty assert() from vdbesort.c. check-in: d95d68aa user: dan tags: threads
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4731   4731               goto moveto_finish;
  4732   4732             }
  4733   4733             c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
  4734   4734             sqlite3_free(pCellKey);
  4735   4735           }
  4736   4736           assert( 
  4737   4737               (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
  4738         -         && (pIdxKey->errCode!=SQLITE_NOMEM || !pCur->pBtree->db->mallocFailed)
         4738  +         && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
  4739   4739           );
  4740   4740           if( c<0 ){
  4741   4741             lwr = idx+1;
  4742   4742           }else if( c>0 ){
  4743   4743             upr = idx-1;
  4744   4744           }else{
  4745   4745             assert( c==0 );

Changes to src/vdbeaux.c.

  3589   3589     ** the following assert().  If the assert() fails, it indicates a
  3590   3590     ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).  */
  3591   3591     assert( mem1.zMalloc==0 );
  3592   3592   
  3593   3593     /* rc==0 here means that one or both of the keys ran out of fields and
  3594   3594     ** all the fields up to that point were equal. Return the the default_rc
  3595   3595     ** value.  */
  3596         -  assert( CORRUPT_DB 
         3596  +  assert( CORRUPT_DB || pKeyInfo->db==0
  3597   3597          || pPKey2->default_rc==vdbeRecordCompareDebug(nKey1, pKey1, pPKey2) 
         3598  +       || pKeyInfo->db->mallocFailed
  3598   3599     );
  3599   3600     return pPKey2->default_rc;
  3600   3601   }
  3601   3602   
  3602   3603   /*
  3603   3604   ** This function is an optimized version of sqlite3VdbeRecordCompare() 
  3604   3605   ** that (a) the first field of pPKey2 is an integer, and (b) the 
................................................................................
  3688   3689       res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
  3689   3690     }else{
  3690   3691       /* The first fields of the two keys are equal and there are no trailing
  3691   3692       ** fields. Return pPKey2->default_rc in this case. */
  3692   3693       res = pPKey2->default_rc;
  3693   3694     }
  3694   3695   
  3695         -  assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
         3696  +  assert( pPKey2->pKeyInfo->db==0
         3697  +       || (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
  3696   3698          || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
  3697   3699          || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
  3698         -       || CORRUPT_DB
         3700  +       || CORRUPT_DB || pPKey2->pKeyInfo->db->mallocFailed
  3699   3701     );
  3700   3702     return res;
  3701   3703   }
  3702   3704   
  3703   3705   /*
  3704   3706   ** This function is an optimized version of sqlite3VdbeRecordCompare() 
  3705   3707   ** that (a) the first field of pPKey2 is a string, that (b) the first field
................................................................................
  3752   3754       }else if( res>0 ){
  3753   3755         res = pPKey2->r2;
  3754   3756       }else{
  3755   3757         res = pPKey2->r1;
  3756   3758       }
  3757   3759     }
  3758   3760   
  3759         -  assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
         3761  +  assert( pPKey2->pKeyInfo->db==0 
         3762  +       || (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
  3760   3763          || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
  3761   3764          || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
  3762         -       || CORRUPT_DB
         3765  +       || CORRUPT_DB || pPKey2->pKeyInfo->db->mallocFailed
  3763   3766     );
  3764   3767     return res;
  3765   3768   }
  3766   3769   
  3767   3770   /*
  3768   3771   ** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
  3769   3772   ** suitable for comparing serialized records to the unpacked record passed

Changes to test/malloc.test.

   897    897     execsql {
   898    898       SELECT * FROM t1 ORDER BY 1 COLLATE utf16bin;
   899    899     }
   900    900   } -test {
   901    901     faultsim_test_result {0 {abcde fghij klmno pqrst uvwxy}} 
   902    902     faultsim_integrity_check
   903    903   }
          904  +
          905  +reset_db
          906  +add_test_utf16bin_collate db
          907  +set big [string repeat x 200]
          908  +do_execsql_test 41.1 {
          909  +  DROP TABLE IF EXISTS t1;
          910  +  CREATE TABLE t1(a COLLATE utf16bin);
          911  +  INSERT INTO t1 VALUES('fghij' || $::big);
          912  +  INSERT INTO t1 VALUES('pqrst' || $::big);
          913  +  INSERT INTO t1 VALUES('abcde' || $::big);
          914  +  INSERT INTO t1 VALUES('uvwxy' || $::big);
          915  +  INSERT INTO t1 VALUES('klmno' || $::big);
          916  +  CREATE INDEX i1 ON t1(a);
          917  +}
          918  +do_faultsim_test 41.2 -faults oom* -body {
          919  +  execsql { SELECT * FROM t1 WHERE a = ('abcde' || $::big)}
          920  +} -test {
          921  +  faultsim_test_result [list 0 "abcde$::big"]
          922  +  faultsim_integrity_check
          923  +}
   904    924   
   905    925   # Ensure that no file descriptors were leaked.
   906    926   do_test malloc-99.X {
   907    927     catch {db close}
   908    928     set sqlite_open_file_count
   909    929   } {0}
   910    930   
   911    931   puts open-file-count=$sqlite_open_file_count
   912    932   finish_test