/ Check-in [dfb146ef]
Login

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

Overview
Comment:Simplifications to btree.c to help facilitate coverage testing. (CVS 6884)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dfb146ef003bae8ff216baf68cc43d7eb7855c68
User & Date: drh 2009-07-12 02:32:22
Context
2009-07-13
07:30
Remove a case from BtreeMovetoUnpacked() that is unreachable as of (6881). (CVS 6885) check-in: 39ce2097 user: danielk1977 tags: trunk
2009-07-12
02:32
Simplifications to btree.c to help facilitate coverage testing. (CVS 6884) check-in: dfb146ef user: drh tags: trunk
02:31
When an OOM fault occurs while moving a page for autovacuum in an in-memory database, be sure to undo the page move prior to returning the error, to avoid corrupting the in-memory database file. (CVS 6883) check-in: d0964b93 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.681 2009/07/11 18:26:29 drh Exp $
           12  +** $Id: btree.c,v 1.682 2009/07/12 02:32:22 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
  3602   3602   ** parameter is 0, this is a read operation (data copied into
  3603   3603   ** buffer pBuf). If it is non-zero, a write (data copied from
  3604   3604   ** buffer pBuf).
  3605   3605   **
  3606   3606   ** A total of "amt" bytes are read or written beginning at "offset".
  3607   3607   ** Data is read to or from the buffer pBuf.
  3608   3608   **
  3609         -** This routine does not make a distinction between key and data.
  3610         -** It just reads or writes bytes from the payload area.  Data might 
  3611         -** appear on the main page or be scattered out on multiple overflow 
  3612         -** pages.
         3609  +** The content being read or written might appear on the main page
         3610  +** or be scattered out on multiple overflow pages.
  3613   3611   **
  3614   3612   ** If the BtCursor.isIncrblobHandle flag is set, and the current
  3615   3613   ** cursor entry uses one or more overflow pages, this function
  3616   3614   ** allocates space for and lazily popluates the overflow page-list 
  3617   3615   ** cache array (BtCursor.aOverflow). Subsequent calls use this
  3618   3616   ** cache to make seeking to the supplied offset more efficient.
  3619   3617   **
................................................................................
  3645   3643     assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
  3646   3644     assert( cursorHoldsMutex(pCur) );
  3647   3645   
  3648   3646     getCellInfo(pCur);
  3649   3647     aPayload = pCur->info.pCell + pCur->info.nHeader;
  3650   3648     nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey);
  3651   3649   
  3652         -  if( offset+amt > nKey+pCur->info.nData 
         3650  +  if( NEVER(offset+amt > nKey+pCur->info.nData) 
  3653   3651      || &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
  3654   3652     ){
  3655   3653       /* Trying to read or write past the end of the data is an error */
  3656   3654       return SQLITE_CORRUPT_BKPT;
  3657   3655     }
  3658   3656   
  3659   3657     /* Check if data must be read/written to/from the btree page itself. */
................................................................................
  3683   3681       ** page number of the first overflow page is stored in aOverflow[0],
  3684   3682       ** etc. A value of 0 in the aOverflow[] array means "not yet known"
  3685   3683       ** (the cache is lazily populated).
  3686   3684       */
  3687   3685       if( pCur->isIncrblobHandle && !pCur->aOverflow ){
  3688   3686         int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
  3689   3687         pCur->aOverflow = (Pgno *)sqlite3MallocZero(sizeof(Pgno)*nOvfl);
  3690         -      if( nOvfl && !pCur->aOverflow ){
         3688  +      /* nOvfl is always positive.  If it were zero, fetchPayload would have
         3689  +      ** been used instead of this routine. */
         3690  +      if( ALWAYS(nOvfl) && !pCur->aOverflow ){
  3691   3691           rc = SQLITE_NOMEM;
  3692   3692         }
  3693   3693       }
  3694   3694   
  3695   3695       /* If the overflow page-list cache has been allocated and the
  3696   3696       ** entry for the first required overflow page is valid, skip
  3697   3697       ** directly to it.