/ Check-in [0c710c1b]
Login

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

Overview
Comment:Add comments and assert() statements to show that the return value from sqlite3BtreeKeySize() and sqlite3BtreeData() usually do not matter. Ticket #3968. Also remove a NEVER() macro that can sometimes be true - discovered while testing the previous change. (CVS 6893)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0c710c1be537127511d95b5b261c7bf26e1bc952
User & Date: drh 2009-07-14 18:35:45
Context
2009-07-15
11:26
Added the SQLITE_TESTCTRL_RESERVE option to sqlite3_test_control(). Simplifications to btree.c to facilitate structural coverage testing. (CVS 6894) check-in: cfbeda1b user: drh tags: trunk
2009-07-14
18:35
Add comments and assert() statements to show that the return value from sqlite3BtreeKeySize() and sqlite3BtreeData() usually do not matter. Ticket #3968. Also remove a NEVER() macro that can sometimes be true - discovered while testing the previous change. (CVS 6893) check-in: 0c710c1b user: drh tags: trunk
17:48
Simplifications to the PRAGMA integrity_check logic. Remove unreachable code. (CVS 6892) check-in: 17749fa5 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.871 2009/07/14 02:33:02 drh Exp $
           46  +** $Id: vdbe.c,v 1.872 2009/07/14 18:35:45 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "vdbeInt.h"
    50     50   
    51     51   /*
    52     52   ** The following global variable is incremented every time a cursor
    53     53   ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes.  The test
................................................................................
  2051   2051       if( rc ) goto abort_due_to_error;
  2052   2052       if( pC->nullRow ){
  2053   2053         payloadSize = 0;
  2054   2054       }else if( pC->cacheStatus==p->cacheCtr ){
  2055   2055         payloadSize = pC->payloadSize;
  2056   2056         zRec = (char*)pC->aRow;
  2057   2057       }else if( pC->isIndex ){
  2058         -      sqlite3BtreeKeySize(pCrsr, &payloadSize64);
         2058  +      rc = sqlite3BtreeKeySize(pCrsr, &payloadSize64);
         2059  +      assert( rc==SQLITE_OK );   /* True because of CursorMoveto() call above */
  2059   2060         /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
  2060   2061         ** payload size, so it is impossible for payloadSize64 to be
  2061   2062         ** larger than 32 bits. */
  2062   2063         assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
  2063   2064         payloadSize = (u32)payloadSize64;
  2064   2065       }else{
  2065         -      sqlite3BtreeDataSize(pCrsr, &payloadSize);
         2066  +      rc = sqlite3BtreeDataSize(pCrsr, &payloadSize);
         2067  +      assert( rc==SQLITE_OK );   /* True because of CursorMoveto() call above */
  2066   2068       }
  2067   2069     }else if( pC->pseudoTable ){
  2068   2070       /* The record is the sole entry of a pseudo-table */
  2069   2071       payloadSize = pC->nData;
  2070   2072       zRec = pC->pData;
  2071   2073       pC->cacheStatus = CACHE_STALE;
  2072   2074       assert( payloadSize==0 || zRec!=0 );
................................................................................
  3587   3589           rc = sqlite3BtreeLast(pC->pCursor, &res);
  3588   3590           if( rc!=SQLITE_OK ){
  3589   3591             goto abort_due_to_error;
  3590   3592           }
  3591   3593           if( res ){
  3592   3594             v = 1;
  3593   3595           }else{
  3594         -          sqlite3BtreeKeySize(pC->pCursor, &v);
         3596  +          rc = sqlite3BtreeKeySize(pC->pCursor, &v);
         3597  +          assert( rc==SQLITE_OK );   /* Cannot fail following BtreeLast() */
  3595   3598             if( v==MAX_ROWID ){
  3596   3599               pC->useRandomRowid = 1;
  3597   3600             }else{
  3598   3601               v++;
  3599   3602             }
  3600   3603           }
  3601   3604         }
................................................................................
  3884   3887     */
  3885   3888     assert( pC->deferredMoveto==0 );
  3886   3889     rc = sqlite3VdbeCursorMoveto(pC);
  3887   3890     if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
  3888   3891   
  3889   3892     if( pC->isIndex ){
  3890   3893       assert( !pC->isTable );
  3891         -    sqlite3BtreeKeySize(pCrsr, &n64);
         3894  +    rc = sqlite3BtreeKeySize(pCrsr, &n64);
         3895  +    assert( rc==SQLITE_OK );    /* True because of CursorMoveto() call above */
  3892   3896       if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
  3893   3897         goto too_big;
  3894   3898       }
  3895   3899       n = (u32)n64;
  3896   3900     }else{
  3897         -    sqlite3BtreeDataSize(pCrsr, &n);
         3901  +    rc = sqlite3BtreeDataSize(pCrsr, &n);
         3902  +    assert( rc==SQLITE_OK );    /* True because of CursorMoveto() call above */
  3898   3903       if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
  3899   3904         goto too_big;
  3900   3905       }
  3901   3906     }
  3902   3907     if( sqlite3VdbeMemGrow(pOut, n, 0) ){
  3903   3908       goto no_mem;
  3904   3909     }
................................................................................
  3954   3959     }else{
  3955   3960       assert( pC->pCursor!=0 );
  3956   3961       rc = sqlite3VdbeCursorMoveto(pC);
  3957   3962       if( rc ) goto abort_due_to_error;
  3958   3963       if( pC->rowidIsValid ){
  3959   3964         v = pC->lastRowid;
  3960   3965       }else{
  3961         -      sqlite3BtreeKeySize(pC->pCursor, &v);
         3966  +      rc = sqlite3BtreeKeySize(pC->pCursor, &v);
         3967  +      assert( rc==SQLITE_OK );  /* Always so because of CursorMoveto() above */
  3962   3968       }
  3963   3969     }
  3964   3970     pOut->u.i = v;
  3965   3971     MemSetTypeFlag(pOut, MEM_Int);
  3966   3972     break;
  3967   3973   }
  3968   3974   

Changes to src/vdbeaux.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used for creating, destroying, and populating
    13     13   ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)  Prior
    14     14   ** to version 2.8.7, all this code was combined into the vdbe.c source file.
    15     15   ** But that file was getting too big so this subroutines were split out.
    16     16   **
    17         -** $Id: vdbeaux.c,v 1.473 2009/07/14 14:15:27 drh Exp $
           17  +** $Id: vdbeaux.c,v 1.474 2009/07/14 18:35:46 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "vdbeInt.h"
    21     21   
    22     22   
    23     23   
    24     24   /*
................................................................................
  2589   2589     u32 typeRowid;    /* Serial type of the rowid */
  2590   2590     u32 lenRowid;     /* Size of the rowid */
  2591   2591     Mem m, v;
  2592   2592   
  2593   2593     /* Get the size of the index entry.  Only indices entries of less
  2594   2594     ** than 2GiB are support - anything large must be database corruption.
  2595   2595     ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
  2596         -  ** this code can safely assume that nCellKey is 32-bits  */
  2597         -  sqlite3BtreeKeySize(pCur, &nCellKey);
         2596  +  ** this code can safely assume that nCellKey is 32-bits  
         2597  +  */
         2598  +  rc = sqlite3BtreeKeySize(pCur, &nCellKey);
         2599  +  assert( rc==SQLITE_OK );     /* pCur is always valid so KeySize cannot fail */
  2598   2600     assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
  2599   2601   
  2600   2602     /* Read in the complete content of the index entry */
  2601   2603     m.flags = 0;
  2602   2604     m.db = db;
  2603   2605     m.zMalloc = 0;
  2604   2606     rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
................................................................................
  2665   2667     int *res                    /* Write the comparison result here */
  2666   2668   ){
  2667   2669     i64 nCellKey = 0;
  2668   2670     int rc;
  2669   2671     BtCursor *pCur = pC->pCursor;
  2670   2672     Mem m;
  2671   2673   
  2672         -  sqlite3BtreeKeySize(pCur, &nCellKey);
         2674  +  rc = sqlite3BtreeKeySize(pCur, &nCellKey);
         2675  +  assert( rc==SQLITE_OK );    /* pCur is always valid so KeySize cannot fail */
  2673   2676     /* nCellKey will always be between 0 and 0xffffffff because of the say
  2674   2677     ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
  2675         -  if( NEVER(nCellKey<=0) || nCellKey>0x7fffffff ){
         2678  +  if( nCellKey<=0 || nCellKey>0x7fffffff ){
  2676   2679       *res = 0;
  2677   2680       return SQLITE_CORRUPT;
  2678   2681     }
  2679   2682     m.db = 0;
  2680   2683     m.flags = 0;
  2681   2684     m.zMalloc = 0;
  2682   2685     rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m);