/ Changes On Branch pcache1-zero-page
Login

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

Changes In Branch pcache1-zero-page Excluding Merge-Ins

This is equivalent to a diff from 2842bc60 to b0810ac1

2016-12-30
14:15
Avoid passing NULL pointers to memcmp() or memcpy(), even when the "number-of-bytes" argument is passed 0. (check-in: 56ff72ab user: dan tags: trunk)
13:55
Clarify the expectations for the behavior of the xFetch method on the sqlite3_pcache_methods object for the case when the key is zero. (Closed-Leaf check-in: b0810ac1 user: drh tags: pcache1-zero-page)
13:40
Improved detection of zero page numbers in the page cache. (check-in: 5550e815 user: drh tags: pcache1-zero-page)
12:10
Fix a harmless compiler warning in fuzzcheck.c (check-in: 2842bc60 user: drh tags: trunk)
12:06
Disable the pagerAcquireMapPage() routine if memory-mapped I/O is disabled. This fixes a harmless compiler warning on OpenBSD. (check-in: 3e25ba6e user: drh tags: trunk)

Changes to src/pager.c.

  5372   5372     assert( pPager->eState>=PAGER_READER );
  5373   5373     assert( assert_pager_state(pPager) );
  5374   5374     assert( pPager->hasHeldSharedLock==1 );
  5375   5375   
  5376   5376     pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
  5377   5377     if( pBase==0 ){
  5378   5378       pPg = 0;
  5379         -    rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
         5379  +    if( pgno==0 ){
         5380  +      rc = SQLITE_CORRUPT_BKPT;
         5381  +    }else{
         5382  +      rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
         5383  +    }
  5380   5384       if( rc!=SQLITE_OK ) goto pager_acquire_err;
  5381   5385       if( pBase==0 ){
  5382   5386         rc = SQLITE_NOMEM_BKPT;
  5383   5387         goto pager_acquire_err;
  5384   5388       }
  5385   5389     }
  5386   5390     pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
................................................................................
  5396   5400       pPager->aStat[PAGER_STAT_HIT]++;
  5397   5401       return SQLITE_OK;
  5398   5402   
  5399   5403     }else{
  5400   5404       /* The pager cache has created a new page. Its content needs to 
  5401   5405       ** be initialized. But first some error checks:
  5402   5406       **
  5403         -    ** (1) Minimum page number is 1
  5404         -    ** (2) The maximum page number is 2^31
  5405         -    ** (3) Never try to fetch the locking page
         5407  +    ** (1) The maximum page number is 2^31
         5408  +    ** (2) Never try to fetch the locking page
  5406   5409       */
  5407         -    if( pgno==0 || pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
         5410  +    assert( pgno>0 );
         5411  +    if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
  5408   5412         rc = SQLITE_CORRUPT_BKPT;
  5409   5413         goto pager_acquire_err;
  5410   5414       }
  5411   5415   
  5412   5416       pPg->pPager = pPager;
  5413   5417   
  5414   5418       assert( !isOpen(pPager->fd) || !MEMDB );

Changes to src/pcache1.c.

   993    993     ** subsequent steps to try to create the page. */
   994    994     if( pPage ){
   995    995       if( !pPage->isPinned ){
   996    996         return pcache1PinPage(pPage);
   997    997       }else{
   998    998         return pPage;
   999    999       }
  1000         -  }else if( createFlag ){
         1000  +  }else if( createFlag && iKey ){
  1001   1001       /* Steps 3, 4, and 5 implemented by this subroutine */
  1002   1002       return pcache1FetchStage2(pCache, iKey, createFlag);
  1003   1003     }else{
  1004   1004       return 0;
  1005   1005     }
  1006   1006   }
  1007   1007   #if PCACHE1_MIGHT_USE_GROUP_MUTEX

Changes to src/sqlite.h.in.

  7211   7211   ** The pBuf element of the returned sqlite3_pcache_page object will be a
  7212   7212   ** pointer to a buffer of szPage bytes used to store the content of a 
  7213   7213   ** single database page.  The pExtra element of sqlite3_pcache_page will be
  7214   7214   ** a pointer to the szExtra bytes of extra storage that SQLite has requested
  7215   7215   ** for each entry in the page cache.
  7216   7216   **
  7217   7217   ** The page to be fetched is determined by the key. ^The minimum key value
  7218         -** is 1.  After it has been retrieved using xFetch, the page is considered
         7218  +** is 1.  The xFetch() method must return NULL if passed a key of 0.
         7219  +** After it has been retrieved using xFetch, the page is considered
  7219   7220   ** to be "pinned".
  7220   7221   **
  7221   7222   ** If the requested page is already in the page cache, then the page cache
  7222   7223   ** implementation must return a pointer to the page buffer with its content
  7223   7224   ** intact.  If the requested page is not already in the cache, then the
  7224   7225   ** cache implementation should use the value of the createFlag
  7225   7226   ** parameter to help it determined what action to take:
  7226   7227   **
  7227   7228   ** <table border=1 width=85% align=center>
  7228   7229   ** <tr><th> createFlag <th> Behavior when page is not already in cache
  7229   7230   ** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
  7230         -** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  7231         -**                 Otherwise return NULL.
         7231  +** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so
         7232  +**                 and the key is not zero.  Otherwise return NULL.
  7232   7233   ** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
  7233         -**                 NULL if allocating a new page is effectively impossible.
         7234  +**                 NULL if the key is zero or if allocating a new page is 
         7235  +**                 effectively impossible.
  7234   7236   ** </table>
  7235   7237   **
  7236   7238   ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
  7237   7239   ** will only use a createFlag of 2 after a prior call with a createFlag of 1
  7238   7240   ** failed.)^  In between the to xFetch() calls, SQLite may
  7239   7241   ** attempt to unpin one or more cache pages by spilling the content of
  7240   7242   ** pinned pages to disk and synching the operating system disk cache.