/ Check-in [60fee957]
Login

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

Overview
Comment:Add assert() statements and eliminate needless variable assignments in order to get the clang scan-build utility to report zero problems against the SQLite core. Clang's static analysis did find one real problem - but it was in the command-line shell, not in the SQLite core.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 60fee9574b0125705787e33c16f116cf188c8323
User & Date: drh 2011-10-14 21:49:18
Context
2011-10-14
22:57
Fix a few minor and harmless clang warnings in FTS3 and RTREE. check-in: b3324f6c user: drh tags: trunk
21:49
Add assert() statements and eliminate needless variable assignments in order to get the clang scan-build utility to report zero problems against the SQLite core. Clang's static analysis did find one real problem - but it was in the command-line shell, not in the SQLite core. check-in: 60fee957 user: drh tags: trunk
2011-10-13
18:08
Change the makefile to delete both plain and ".exe" variants of build tools. Ticket [92bd6eaf04e117] check-in: 19536a38 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  4581   4581             c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
  4582   4582             sqlite3_free(pCellKey);
  4583   4583           }
  4584   4584         }
  4585   4585         if( c==0 ){
  4586   4586           if( pPage->intKey && !pPage->leaf ){
  4587   4587             lwr = idx;
  4588         -          upr = lwr - 1;
  4589   4588             break;
  4590   4589           }else{
  4591   4590             *pRes = 0;
  4592   4591             rc = SQLITE_OK;
  4593   4592             goto moveto_finish;
  4594   4593           }
  4595   4594         }
................................................................................
  4599   4598           upr = idx-1;
  4600   4599         }
  4601   4600         if( lwr>upr ){
  4602   4601           break;
  4603   4602         }
  4604   4603         pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
  4605   4604       }
  4606         -    assert( lwr==upr+1 );
         4605  +    assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
  4607   4606       assert( pPage->isInit );
  4608   4607       if( pPage->leaf ){
  4609   4608         chldPg = 0;
  4610   4609       }else if( lwr>=pPage->nCell ){
  4611   4610         chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
  4612   4611       }else{
  4613   4612         chldPg = get4byte(findCell(pPage, lwr));
................................................................................
  4864   4863         }else{
  4865   4864           rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
  4866   4865         }
  4867   4866         if( rc ){
  4868   4867           pTrunk = 0;
  4869   4868           goto end_allocate_page;
  4870   4869         }
         4870  +      assert( pTrunk!=0 );
         4871  +      assert( pTrunk->aData!=0 );
  4871   4872   
  4872   4873         k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
  4873   4874         if( k==0 && !searchList ){
  4874   4875           /* The trunk has no leaves and the list is not being searched. 
  4875   4876           ** So extract the trunk page itself and use it as the newly 
  4876   4877           ** allocated page */
  4877   4878           assert( pPrevTrunk==0 );
................................................................................
  6419   6420       k = 0;                             /* Current 'new' sibling page */
  6420   6421       for(i=0; i<nCell; i++){
  6421   6422         int isDivider = 0;
  6422   6423         while( i==iNextOld ){
  6423   6424           /* Cell i is the cell immediately following the last cell on old
  6424   6425           ** sibling page j. If the siblings are not leaf pages of an
  6425   6426           ** intkey b-tree, then cell i was a divider cell. */
         6427  +        assert( j+1 < ArraySize(apCopy) );
  6426   6428           pOld = apCopy[++j];
  6427   6429           iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
  6428   6430           if( pOld->nOverflow ){
  6429   6431             nOverflow = pOld->nOverflow;
  6430   6432             iOverflow = i + !leafData + pOld->aOvfl[0].idx;
  6431   6433           }
  6432   6434           isDivider = !leafData;  

Changes to src/build.c.

  2338   2338   ** the index already exists and must be cleared before being refilled and
  2339   2339   ** the root page number of the index is taken from pIndex->tnum.
  2340   2340   */
  2341   2341   static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
  2342   2342     Table *pTab = pIndex->pTable;  /* The table that is indexed */
  2343   2343     int iTab = pParse->nTab++;     /* Btree cursor used for pTab */
  2344   2344     int iIdx = pParse->nTab++;     /* Btree cursor used for pIndex */
  2345         -  int iSorter = iTab;            /* Cursor opened by OpenSorter (if in use) */
         2345  +  int iSorter;                   /* Cursor opened by OpenSorter (if in use) */
  2346   2346     int addr1;                     /* Address of top of loop */
  2347   2347     int addr2;                     /* Address to jump to for next iteration */
  2348   2348     int tnum;                      /* Root page of index */
  2349   2349     Vdbe *v;                       /* Generate code into this virtual machine */
  2350   2350     KeyInfo *pKey;                 /* KeyInfo for index */
         2351  +#ifdef SQLITE_OMIT_MERGE_SORT
  2351   2352     int regIdxKey;                 /* Registers containing the index key */
         2353  +#endif
  2352   2354     int regRecord;                 /* Register holding assemblied index record */
  2353   2355     sqlite3 *db = pParse->db;      /* The database connection */
  2354   2356     int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
  2355   2357   
  2356   2358   #ifndef SQLITE_OMIT_AUTHORIZATION
  2357   2359     if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
  2358   2360         db->aDb[iDb].zName ) ){
................................................................................
  2378   2380       sqlite3VdbeChangeP5(v, 1);
  2379   2381     }
  2380   2382   
  2381   2383   #ifndef SQLITE_OMIT_MERGE_SORT
  2382   2384     /* Open the sorter cursor if we are to use one. */
  2383   2385     iSorter = pParse->nTab++;
  2384   2386     sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
         2387  +#else
         2388  +  iSorter = iTab;
  2385   2389   #endif
  2386   2390   
  2387   2391     /* Open the table. Loop through all rows of the table, inserting index
  2388   2392     ** records into the sorter. */
  2389   2393     sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
  2390   2394     addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
  2391         -  addr2 = addr1 + 1;
  2392   2395     regRecord = sqlite3GetTempReg(pParse);
  2393         -  regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
  2394   2396   
  2395   2397   #ifndef SQLITE_OMIT_MERGE_SORT
         2398  +  sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
  2396   2399     sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
  2397   2400     sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
  2398   2401     sqlite3VdbeJumpHere(v, addr1);
  2399   2402     addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
  2400   2403     if( pIndex->onError!=OE_None ){
  2401   2404       int j2 = sqlite3VdbeCurrentAddr(v) + 3;
  2402   2405       sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
................................................................................
  2408   2411     }else{
  2409   2412       addr2 = sqlite3VdbeCurrentAddr(v);
  2410   2413     }
  2411   2414     sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
  2412   2415     sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
  2413   2416     sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  2414   2417   #else
         2418  +  regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
         2419  +  addr2 = addr1 + 1;
  2415   2420     if( pIndex->onError!=OE_None ){
  2416   2421       const int regRowid = regIdxKey + pIndex->nColumn;
  2417   2422       const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
  2418   2423       void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
  2419   2424   
  2420   2425       /* The registers accessed by the OP_IsUnique opcode were allocated
  2421   2426       ** using sqlite3GetTempRange() inside of the sqlite3GenerateIndexKey()
................................................................................
  2505   2510       /* Use the two-part index name to determine the database 
  2506   2511       ** to search for the table. 'Fix' the table name to this db
  2507   2512       ** before looking up the table.
  2508   2513       */
  2509   2514       assert( pName1 && pName2 );
  2510   2515       iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
  2511   2516       if( iDb<0 ) goto exit_create_index;
         2517  +    assert( pName && pName->z );
  2512   2518   
  2513   2519   #ifndef SQLITE_OMIT_TEMPDB
  2514   2520       /* If the index name was unqualified, check if the the table
  2515   2521       ** is a temp table. If so, set the database to 1. Do not do this
  2516   2522       ** if initialising a database schema.
  2517   2523       */
  2518   2524       if( !db->init.busy ){
................................................................................
  2532   2538       }
  2533   2539       pTab = sqlite3LocateTable(pParse, 0, pTblName->a[0].zName, 
  2534   2540           pTblName->a[0].zDatabase);
  2535   2541       if( !pTab || db->mallocFailed ) goto exit_create_index;
  2536   2542       assert( db->aDb[iDb].pSchema==pTab->pSchema );
  2537   2543     }else{
  2538   2544       assert( pName==0 );
         2545  +    assert( pStart==0 );
  2539   2546       pTab = pParse->pNewTable;
  2540   2547       if( !pTab ) goto exit_create_index;
  2541   2548       iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  2542   2549     }
  2543   2550     pDb = &db->aDb[iDb];
  2544   2551   
  2545   2552     assert( pTab!=0 );
................................................................................
  2574   2581     ** If pName==0 it means that we are
  2575   2582     ** dealing with a primary key or UNIQUE constraint.  We have to invent our
  2576   2583     ** own name.
  2577   2584     */
  2578   2585     if( pName ){
  2579   2586       zName = sqlite3NameFromToken(db, pName);
  2580   2587       if( zName==0 ) goto exit_create_index;
         2588  +    assert( pName->z!=0 );
  2581   2589       if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
  2582   2590         goto exit_create_index;
  2583   2591       }
  2584   2592       if( !db->init.busy ){
  2585   2593         if( sqlite3FindTable(db, zName, 0)!=0 ){
  2586   2594           sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
  2587   2595           goto exit_create_index;
................................................................................
  3429   3437     sqlite3VdbeAddOp2(v, OP_AutoCommit, 0, 0);
  3430   3438   }
  3431   3439   
  3432   3440   /*
  3433   3441   ** Commit a transaction
  3434   3442   */
  3435   3443   void sqlite3CommitTransaction(Parse *pParse){
  3436         -  sqlite3 *db;
  3437   3444     Vdbe *v;
  3438   3445   
  3439   3446     assert( pParse!=0 );
  3440         -  db = pParse->db;
  3441         -  assert( db!=0 );
  3442         -/*  if( db->aDb[0].pBt==0 ) return; */
         3447  +  assert( pParse->db!=0 );
  3443   3448     if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ){
  3444   3449       return;
  3445   3450     }
  3446   3451     v = sqlite3GetVdbe(pParse);
  3447   3452     if( v ){
  3448   3453       sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 0);
  3449   3454     }
  3450   3455   }
  3451   3456   
  3452   3457   /*
  3453   3458   ** Rollback a transaction
  3454   3459   */
  3455   3460   void sqlite3RollbackTransaction(Parse *pParse){
  3456         -  sqlite3 *db;
  3457   3461     Vdbe *v;
  3458   3462   
  3459   3463     assert( pParse!=0 );
  3460         -  db = pParse->db;
  3461         -  assert( db!=0 );
  3462         -/*  if( db->aDb[0].pBt==0 ) return; */
         3464  +  assert( pParse->db!=0 );
  3463   3465     if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ){
  3464   3466       return;
  3465   3467     }
  3466   3468     v = sqlite3GetVdbe(pParse);
  3467   3469     if( v ){
  3468   3470       sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 1);
  3469   3471     }

Changes to src/expr.c.

   399    399       if( pToken ){
   400    400         if( nExtra==0 ){
   401    401           pNew->flags |= EP_IntValue;
   402    402           pNew->u.iValue = iValue;
   403    403         }else{
   404    404           int c;
   405    405           pNew->u.zToken = (char*)&pNew[1];
   406         -        memcpy(pNew->u.zToken, pToken->z, pToken->n);
          406  +        assert( pToken->z!=0 || pToken->n==0 );
          407  +        if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
   407    408           pNew->u.zToken[pToken->n] = 0;
   408    409           if( dequote && nExtra>=3 
   409    410                && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
   410    411             sqlite3Dequote(pNew->u.zToken);
   411    412             if( c=='"' ) pNew->flags |= EP_DblQuoted;
   412    413           }
   413    414         }
................................................................................
  1438   1439     /* Check to see if an existing table or index can be used to
  1439   1440     ** satisfy the query.  This is preferable to generating a new 
  1440   1441     ** ephemeral table.
  1441   1442     */
  1442   1443     p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
  1443   1444     if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
  1444   1445       sqlite3 *db = pParse->db;              /* Database connection */
  1445         -    Expr *pExpr = p->pEList->a[0].pExpr;   /* Expression <column> */
  1446         -    int iCol = pExpr->iColumn;             /* Index of column <column> */
  1447   1446       Vdbe *v = sqlite3GetVdbe(pParse);      /* Virtual machine being coded */
  1448         -    Table *pTab = p->pSrc->a[0].pTab;      /* Table <table>. */
         1447  +    Table *pTab;                           /* Table <table>. */
         1448  +    Expr *pExpr;                           /* Expression <column> */
         1449  +    int iCol;                              /* Index of column <column> */
  1449   1450       int iDb;                               /* Database idx for pTab */
         1451  +
         1452  +    assert( p );                        /* Because of isCandidateForInOpt(p) */
         1453  +    assert( p->pEList!=0 );             /* Because of isCandidateForInOpt(p) */
         1454  +    assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
         1455  +    assert( p->pSrc!=0 );               /* Because of isCandidateForInOpt(p) */
         1456  +    pTab = p->pSrc->a[0].pTab;
         1457  +    pExpr = p->pEList->a[0].pExpr;
         1458  +    iCol = pExpr->iColumn;
  1450   1459      
  1451   1460       /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
  1452   1461       iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  1453   1462       sqlite3CodeVerifySchema(pParse, iDb);
  1454   1463       sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
  1455   1464   
  1456   1465       /* This function is only called from two places. In both cases the vdbe

Changes to src/fkey.c.

  1120   1120       sqlite3ExprDelete(db, pWhen);
  1121   1121       sqlite3ExprListDelete(db, pList);
  1122   1122       sqlite3SelectDelete(db, pSelect);
  1123   1123       if( db->mallocFailed==1 ){
  1124   1124         fkTriggerDelete(db, pTrigger);
  1125   1125         return 0;
  1126   1126       }
         1127  +    assert( pStep!=0 );
  1127   1128   
  1128   1129       switch( action ){
  1129   1130         case OE_Restrict:
  1130   1131           pStep->op = TK_SELECT; 
  1131   1132           break;
  1132   1133         case OE_Cascade: 
  1133   1134           if( !pChanges ){ 

Changes to src/main.c.

  2278   2278   opendb_out:
  2279   2279     sqlite3_free(zOpen);
  2280   2280     if( db ){
  2281   2281       assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
  2282   2282       sqlite3_mutex_leave(db->mutex);
  2283   2283     }
  2284   2284     rc = sqlite3_errcode(db);
         2285  +  assert( db!=0 || rc==SQLITE_NOMEM );
  2285   2286     if( rc==SQLITE_NOMEM ){
  2286   2287       sqlite3_close(db);
  2287   2288       db = 0;
  2288   2289     }else if( rc!=SQLITE_OK ){
  2289   2290       db->magic = SQLITE_MAGIC_SICK;
  2290   2291     }
  2291   2292     *ppDb = db;

Changes to src/os_unix.c.

  1359   1359     ** The reason a single byte cannot be used instead of the 'shared byte
  1360   1360     ** range' is that some versions of windows do not support read-locks. By
  1361   1361     ** locking a random byte from a range, concurrent SHARED locks may exist
  1362   1362     ** even if the locking primitive used is always a write-lock.
  1363   1363     */
  1364   1364     int rc = SQLITE_OK;
  1365   1365     unixFile *pFile = (unixFile*)id;
  1366         -  unixInodeInfo *pInode = pFile->pInode;
         1366  +  unixInodeInfo *pInode;
  1367   1367     struct flock lock;
  1368   1368     int tErrno = 0;
  1369   1369   
  1370   1370     assert( pFile );
  1371   1371     OSTRACE(("LOCK    %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
  1372   1372         azFileLock(eFileLock), azFileLock(pFile->eFileLock),
  1373         -      azFileLock(pInode->eFileLock), pInode->nShared , getpid()));
         1373  +      azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared , getpid()));
  1374   1374   
  1375   1375     /* If there is already a lock of this type or more restrictive on the
  1376   1376     ** unixFile, do nothing. Don't use the end_lock: exit path, as
  1377   1377     ** unixEnterMutex() hasn't been called yet.
  1378   1378     */
  1379   1379     if( pFile->eFileLock>=eFileLock ){
  1380   1380       OSTRACE(("LOCK    %d %s ok (already held) (unix)\n", pFile->h,
................................................................................
  1570   1570   ** remove the write lock on a region when a read lock is set.
  1571   1571   */
  1572   1572   static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
  1573   1573     unixFile *pFile = (unixFile*)id;
  1574   1574     unixInodeInfo *pInode;
  1575   1575     struct flock lock;
  1576   1576     int rc = SQLITE_OK;
  1577         -  int h;
  1578   1577   
  1579   1578     assert( pFile );
  1580   1579     OSTRACE(("UNLOCK  %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
  1581   1580         pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
  1582   1581         getpid()));
  1583   1582   
  1584   1583     assert( eFileLock<=SHARED_LOCK );
  1585   1584     if( pFile->eFileLock<=eFileLock ){
  1586   1585       return SQLITE_OK;
  1587   1586     }
  1588   1587     unixEnterMutex();
  1589         -  h = pFile->h;
  1590   1588     pInode = pFile->pInode;
  1591   1589     assert( pInode->nShared!=0 );
  1592   1590     if( pFile->eFileLock>SHARED_LOCK ){
  1593   1591       assert( pInode->eFileLock==pFile->eFileLock );
  1594         -    SimulateIOErrorBenign(1);
  1595         -    SimulateIOError( h=(-1) )
  1596         -    SimulateIOErrorBenign(0);
  1597   1592   
  1598   1593   #ifndef NDEBUG
  1599   1594       /* When reducing a lock such that other processes can start
  1600   1595       ** reading the database file again, make sure that the
  1601   1596       ** transaction counter was updated if any part of the database
  1602   1597       ** file changed.  If the transaction counter is not updated,
  1603   1598       ** other connections to the same file might not realize that
  1604   1599       ** the file has changed and hence might not know to flush their
  1605   1600       ** cache.  The use of a stale cache can lead to database corruption.
  1606   1601       */
  1607         -#if 0
  1608         -    assert( pFile->inNormalWrite==0
  1609         -         || pFile->dbUpdate==0
  1610         -         || pFile->transCntrChng==1 );
  1611         -#endif
  1612   1602       pFile->inNormalWrite = 0;
  1613   1603   #endif
  1614   1604   
  1615   1605       /* downgrading to a shared lock on NFS involves clearing the write lock
  1616   1606       ** before establishing the readlock - to avoid a race condition we downgrade
  1617   1607       ** the lock in 2 blocks, so that part of the range will be covered by a 
  1618   1608       ** write lock until the rest is covered by a read lock:
................................................................................
  1706   1696       ** the lock.
  1707   1697       */
  1708   1698       pInode->nShared--;
  1709   1699       if( pInode->nShared==0 ){
  1710   1700         lock.l_type = F_UNLCK;
  1711   1701         lock.l_whence = SEEK_SET;
  1712   1702         lock.l_start = lock.l_len = 0L;
  1713         -      SimulateIOErrorBenign(1);
  1714         -      SimulateIOError( h=(-1) )
  1715         -      SimulateIOErrorBenign(0);
  1716   1703         if( unixFileLock(pFile, &lock)==0 ){
  1717   1704           pInode->eFileLock = NO_LOCK;
  1718   1705         }else{
  1719   1706           rc = SQLITE_IOERR_UNLOCK;
  1720   1707   	pFile->lastErrno = errno;
  1721   1708           pInode->eFileLock = NO_LOCK;
  1722   1709           pFile->eFileLock = NO_LOCK;
................................................................................
  4543   4530     */
  4544   4531   #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
  4545   4532     assert( zFilename==0 || zFilename[0]=='/' 
  4546   4533       || pVfs->pAppData==(void*)&autolockIoFinder );
  4547   4534   #else
  4548   4535     assert( zFilename==0 || zFilename[0]=='/' );
  4549   4536   #endif
         4537  +
         4538  +  /* No locking occurs in temporary files */
         4539  +  assert( zFilename!=0 || noLock );
  4550   4540   
  4551   4541     OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
  4552   4542     pNew->h = h;
  4553   4543     pNew->zPath = zFilename;
  4554   4544     if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
  4555   4545       pNew->ctrlFlags = UNIXFILE_EXCL;
  4556   4546     }else{
................................................................................
  4645   4635   
  4646   4636     else if( pLockingStyle == &dotlockIoMethods ){
  4647   4637       /* Dotfile locking uses the file path so it needs to be included in
  4648   4638       ** the dotlockLockingContext 
  4649   4639       */
  4650   4640       char *zLockFile;
  4651   4641       int nFilename;
         4642  +    assert( zFilename!=0 );
  4652   4643       nFilename = (int)strlen(zFilename) + 6;
  4653   4644       zLockFile = (char *)sqlite3_malloc(nFilename);
  4654   4645       if( zLockFile==0 ){
  4655   4646         rc = SQLITE_NOMEM;
  4656   4647       }else{
  4657   4648         sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
  4658   4649       }

Changes to src/pager.c.

  2699   2699         if( needPagerReset ){
  2700   2700           pager_reset(pPager);
  2701   2701           needPagerReset = 0;
  2702   2702         }
  2703   2703         rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
  2704   2704         if( rc!=SQLITE_OK ){
  2705   2705           if( rc==SQLITE_DONE ){
  2706         -          rc = SQLITE_OK;
  2707   2706             pPager->journalOff = szJ;
  2708   2707             break;
  2709   2708           }else if( rc==SQLITE_IOERR_SHORT_READ ){
  2710   2709             /* If the journal has been truncated, simply stop reading and
  2711   2710             ** processing the journal. This might happen if the journal was
  2712   2711             ** not completely written and synced prior to a crash.  In that
  2713   2712             ** case, the database should have never been written in the
................................................................................
  2961   2960   ){
  2962   2961     int rc;                         /* Return code */
  2963   2962   #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
  2964   2963     PgHdr *p;                       /* For looping over pages */
  2965   2964   #endif
  2966   2965   
  2967   2966     assert( pPager->pWal );
         2967  +  assert( pList );
  2968   2968   #ifdef SQLITE_DEBUG
  2969   2969     /* Verify that the page list is in accending order */
  2970   2970     for(p=pList; p && p->pDirty; p=p->pDirty){
  2971   2971       assert( p->pgno < p->pDirty->pgno );
  2972   2972     }
  2973   2973   #endif
  2974   2974   

Changes to src/printf.c.

   193    193     int nsd;                   /* Number of significant digits returned */
   194    194     double rounder;            /* Used for rounding floating point values */
   195    195     etByte flag_dp;            /* True if decimal point should be shown */
   196    196     etByte flag_rtz;           /* True if trailing zeros should be removed */
   197    197   #endif
   198    198     char buf[etBUFSIZE];       /* Conversion buffer */
   199    199   
   200         -  length = 0;
   201    200     bufpt = 0;
   202    201     for(; (c=(*fmt))!=0; ++fmt){
   203    202       if( c!='%' ){
   204    203         int amt;
   205    204         bufpt = (char *)fmt;
   206    205         amt = 1;
   207    206         while( (c=(*++fmt))!='%' && c!=0 ) amt++;
................................................................................
   688    687   void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
   689    688     assert( z!=0 || N==0 );
   690    689     if( p->tooBig | p->mallocFailed ){
   691    690       testcase(p->tooBig);
   692    691       testcase(p->mallocFailed);
   693    692       return;
   694    693     }
          694  +  assert( p->zText!=0 || p->nChar==0 );
   695    695     if( N<0 ){
   696    696       N = sqlite3Strlen30(z);
   697    697     }
   698    698     if( N==0 || NEVER(z==0) ){
   699    699       return;
   700    700     }
   701    701     if( p->nChar+N >= p->nAlloc ){
................................................................................
   719    719         }
   720    720         if( p->useMalloc==1 ){
   721    721           zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
   722    722         }else{
   723    723           zNew = sqlite3_realloc(zOld, p->nAlloc);
   724    724         }
   725    725         if( zNew ){
   726         -        if( zOld==0 ) memcpy(zNew, p->zText, p->nChar);
          726  +        if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
   727    727           p->zText = zNew;
   728    728         }else{
   729    729           p->mallocFailed = 1;
   730    730           sqlite3StrAccumReset(p);
   731    731           return;
   732    732         }
   733    733       }
   734    734     }
          735  +  assert( p->zText );
   735    736     memcpy(&p->zText[p->nChar], z, N);
   736    737     p->nChar += N;
   737    738   }
   738    739   
   739    740   /*
   740    741   ** Finish off a string by making sure it is zero-terminated.
   741    742   ** Return a pointer to the resulting string.  Return a NULL

Changes to src/select.c.

  1268   1268                  || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 );
  1269   1269       if( (zName = pEList->a[i].zName)!=0 ){
  1270   1270         /* If the column contains an "AS <name>" phrase, use <name> as the name */
  1271   1271         zName = sqlite3DbStrDup(db, zName);
  1272   1272       }else{
  1273   1273         Expr *pColExpr = p;  /* The expression that is the result column name */
  1274   1274         Table *pTab;         /* Table associated with this expression */
  1275         -      while( pColExpr->op==TK_DOT ) pColExpr = pColExpr->pRight;
         1275  +      while( pColExpr->op==TK_DOT ){
         1276  +        pColExpr = pColExpr->pRight;
         1277  +        assert( pColExpr!=0 );
         1278  +      }
  1276   1279         if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
  1277   1280           /* For columns use the column name name */
  1278   1281           int iCol = pColExpr->iColumn;
  1279   1282           pTab = pColExpr->pTab;
  1280   1283           if( iCol<0 ) iCol = pTab->iPKey;
  1281   1284           zName = sqlite3MPrintf(db, "%s",
  1282   1285                    iCol>=0 ? pTab->aCol[iCol].zName : "rowid");

Changes to src/shell.c.

   334    334   ** The interface is like "readline" but no command-line editing
   335    335   ** is done.
   336    336   */
   337    337   static char *local_getline(char *zPrompt, FILE *in){
   338    338     char *zLine;
   339    339     int nLine;
   340    340     int n;
   341         -  int eol;
   342    341   
   343    342     if( zPrompt && *zPrompt ){
   344    343       printf("%s",zPrompt);
   345    344       fflush(stdout);
   346    345     }
   347    346     nLine = 100;
   348    347     zLine = malloc( nLine );
   349    348     if( zLine==0 ) return 0;
   350    349     n = 0;
   351         -  eol = 0;
   352         -  while( !eol ){
          350  +  while( 1 ){
   353    351       if( n+100>nLine ){
   354    352         nLine = nLine*2 + 100;
   355    353         zLine = realloc(zLine, nLine);
   356    354         if( zLine==0 ) return 0;
   357    355       }
   358    356       if( fgets(&zLine[n], nLine - n, in)==0 ){
   359    357         if( n==0 ){
   360    358           free(zLine);
   361    359           return 0;
   362    360         }
   363    361         zLine[n] = 0;
   364         -      eol = 1;
   365    362         break;
   366    363       }
   367    364       while( zLine[n] ){ n++; }
   368    365       if( n>0 && zLine[n-1]=='\n' ){
   369    366         n--;
   370    367         if( n>0 && zLine[n-1]=='\r' ) n--;
   371    368         zLine[n] = 0;
   372         -      eol = 1;
          369  +      break;
   373    370       }
   374    371     }
   375    372     zLine = realloc( zLine, n+1 );
   376    373     return zLine;
   377    374   }
   378    375   
   379    376   /*
................................................................................
  1093   1090     int (*xCallback)(void*,int,char**,char**,int*),   /* Callback function */
  1094   1091                                                 /* (not the same as sqlite3_exec) */
  1095   1092     struct callback_data *pArg,                 /* Pointer to struct callback_data */
  1096   1093     char **pzErrMsg                             /* Error msg written here */
  1097   1094   ){
  1098   1095     sqlite3_stmt *pStmt = NULL;     /* Statement to execute. */
  1099   1096     int rc = SQLITE_OK;             /* Return Code */
         1097  +  int rc2;
  1100   1098     const char *zLeftover;          /* Tail of unprocessed SQL */
  1101   1099   
  1102   1100     if( pzErrMsg ){
  1103   1101       *pzErrMsg = NULL;
  1104   1102     }
  1105   1103   
  1106   1104     while( zSql[0] && (SQLITE_OK == rc) ){
................................................................................
  1186   1184         if( pArg && pArg->statsOn ){
  1187   1185           display_stats(db, pArg, 0);
  1188   1186         }
  1189   1187   
  1190   1188         /* Finalize the statement just executed. If this fails, save a 
  1191   1189         ** copy of the error message. Otherwise, set zSql to point to the
  1192   1190         ** next statement to execute. */
  1193         -      rc = sqlite3_finalize(pStmt);
         1191  +      rc2 = sqlite3_finalize(pStmt);
         1192  +      if( rc!=SQLITE_NOMEM ) rc = rc2;
  1194   1193         if( rc==SQLITE_OK ){
  1195   1194           zSql = zLeftover;
  1196   1195           while( IsSpace(zSql[0]) ) zSql++;
  1197   1196         }else if( pzErrMsg ){
  1198   1197           *pzErrMsg = save_err_msg(db);
  1199   1198         }
  1200   1199   
................................................................................
  1758   1757         sqlite3_finalize(pStmt);
  1759   1758         return 1;
  1760   1759       }
  1761   1760       sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
  1762   1761       zCommit = "COMMIT";
  1763   1762       while( (zLine = local_getline(0, in))!=0 ){
  1764   1763         char *z;
  1765         -      i = 0;
  1766   1764         lineno++;
  1767   1765         azCol[0] = zLine;
  1768   1766         for(i=0, z=zLine; *z && *z!='\n' && *z!='\r'; z++){
  1769   1767           if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
  1770   1768             *z = 0;
  1771   1769             i++;
  1772   1770             if( i<nCol ){
................................................................................
  2233   2231       ** of the option name, or a numerical value. */
  2234   2232       n = strlen30(azArg[1]);
  2235   2233       for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
  2236   2234         if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
  2237   2235           if( testctrl<0 ){
  2238   2236             testctrl = aCtrl[i].ctrlCode;
  2239   2237           }else{
  2240         -          fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[i]);
         2238  +          fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
  2241   2239             testctrl = -1;
  2242   2240             break;
  2243   2241           }
  2244   2242         }
  2245   2243       }
  2246   2244       if( testctrl<0 ) testctrl = atoi(azArg[1]);
  2247   2245       if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
................................................................................
  2741   2739       /* Need to check for batch mode here to so we can avoid printing
  2742   2740       ** informational messages (like from process_sqliterc) before 
  2743   2741       ** we do the actual processing of arguments later in a second pass.
  2744   2742       */
  2745   2743       }else if( strcmp(argv[i],"-batch")==0 ){
  2746   2744         stdin_is_interactive = 0;
  2747   2745       }else if( strcmp(argv[i],"-heap")==0 ){
         2746  +#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
  2748   2747         int j, c;
  2749   2748         const char *zSize;
  2750   2749         sqlite3_int64 szHeap;
  2751   2750   
  2752   2751         zSize = argv[++i];
  2753   2752         szHeap = atoi(zSize);
  2754   2753         for(j=0; (c = zSize[j])!=0; j++){
  2755   2754           if( c=='M' ){ szHeap *= 1000000; break; }
  2756   2755           if( c=='K' ){ szHeap *= 1000; break; }
  2757   2756           if( c=='G' ){ szHeap *= 1000000000; break; }
  2758   2757         }
  2759   2758         if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
  2760         -#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
  2761   2759         sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
  2762   2760   #endif
  2763   2761   #ifdef SQLITE_ENABLE_VFSTRACE
  2764   2762       }else if( strcmp(argv[i],"-vfstrace")==0 ){
  2765   2763         extern int vfstrace_register(
  2766   2764            const char *zTraceName,
  2767   2765            const char *zOldVfsName,

Changes to src/tclsqlite.c.

   915    915     Tcl_DStringAppendElement(&str, zCode);
   916    916     Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : "");
   917    917     Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : "");
   918    918     Tcl_DStringAppendElement(&str, zArg3 ? zArg3 : "");
   919    919     Tcl_DStringAppendElement(&str, zArg4 ? zArg4 : "");
   920    920     rc = Tcl_GlobalEval(pDb->interp, Tcl_DStringValue(&str));
   921    921     Tcl_DStringFree(&str);
   922         -  zReply = Tcl_GetStringResult(pDb->interp);
          922  +  zReply = rc==TCL_OK ? Tcl_GetStringResult(pDb->interp) : "SQLITE_DENY";
   923    923     if( strcmp(zReply,"SQLITE_OK")==0 ){
   924    924       rc = SQLITE_OK;
   925    925     }else if( strcmp(zReply,"SQLITE_DENY")==0 ){
   926    926       rc = SQLITE_DENY;
   927    927     }else if( strcmp(zReply,"SQLITE_IGNORE")==0 ){
   928    928       rc = SQLITE_IGNORE;
   929    929     }else{
................................................................................
   964    964   **
   965    965   ** copied from shell.c from '.import' command
   966    966   */
   967    967   static char *local_getline(char *zPrompt, FILE *in){
   968    968     char *zLine;
   969    969     int nLine;
   970    970     int n;
   971         -  int eol;
   972    971   
   973    972     nLine = 100;
   974    973     zLine = malloc( nLine );
   975    974     if( zLine==0 ) return 0;
   976    975     n = 0;
   977         -  eol = 0;
   978         -  while( !eol ){
          976  +  while( 1 ){
   979    977       if( n+100>nLine ){
   980    978         nLine = nLine*2 + 100;
   981    979         zLine = realloc(zLine, nLine);
   982    980         if( zLine==0 ) return 0;
   983    981       }
   984    982       if( fgets(&zLine[n], nLine - n, in)==0 ){
   985    983         if( n==0 ){
   986    984           free(zLine);
   987    985           return 0;
   988    986         }
   989    987         zLine[n] = 0;
   990         -      eol = 1;
   991    988         break;
   992    989       }
   993    990       while( zLine[n] ){ n++; }
   994    991       if( n>0 && zLine[n-1]=='\n' ){
   995    992         n--;
   996    993         zLine[n] = 0;
   997         -      eol = 1;
          994  +      break;
   998    995       }
   999    996     }
  1000    997     zLine = realloc( zLine, n+1 );
  1001    998     return zLine;
  1002    999   }
  1003   1000   
  1004   1001   
................................................................................
  2117   2114         fclose(in);
  2118   2115         return TCL_ERROR;
  2119   2116       }
  2120   2117       (void)sqlite3_exec(pDb->db, "BEGIN", 0, 0, 0);
  2121   2118       zCommit = "COMMIT";
  2122   2119       while( (zLine = local_getline(0, in))!=0 ){
  2123   2120         char *z;
  2124         -      i = 0;
  2125   2121         lineno++;
  2126   2122         azCol[0] = zLine;
  2127   2123         for(i=0, z=zLine; *z; z++){
  2128   2124           if( *z==zSep[0] && strncmp(z, zSep, nSep)==0 ){
  2129   2125             *z = 0;
  2130   2126             i++;
  2131   2127             if( i<nCol ){
................................................................................
  2546   2542   
  2547   2543     /*
  2548   2544     **     $db rekey KEY
  2549   2545     **
  2550   2546     ** Change the encryption key on the currently open database.
  2551   2547     */
  2552   2548     case DB_REKEY: {
         2549  +#ifdef SQLITE_HAS_CODEC
  2553   2550       int nKey;
  2554   2551       void *pKey;
         2552  +#endif
  2555   2553       if( objc!=3 ){
  2556   2554         Tcl_WrongNumArgs(interp, 2, objv, "KEY");
  2557   2555         return TCL_ERROR;
  2558   2556       }
  2559         -    pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
  2560   2557   #ifdef SQLITE_HAS_CODEC
         2558  +    pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
  2561   2559       rc = sqlite3_rekey(pDb->db, pKey, nKey);
  2562   2560       if( rc ){
  2563   2561         Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0);
  2564   2562         rc = TCL_ERROR;
  2565   2563       }
  2566   2564   #endif
  2567   2565       break;
................................................................................
  2916   2914   ** connection is deleted when the DBNAME command is deleted.
  2917   2915   **
  2918   2916   ** The second argument is the name of the database file.
  2919   2917   **
  2920   2918   */
  2921   2919   static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
  2922   2920     SqliteDb *p;
  2923         -  void *pKey = 0;
  2924         -  int nKey = 0;
  2925   2921     const char *zArg;
  2926   2922     char *zErrMsg;
  2927   2923     int i;
  2928   2924     const char *zFile;
  2929   2925     const char *zVfs = 0;
  2930   2926     int flags;
  2931   2927     Tcl_DString translatedFilename;
         2928  +#ifdef SQLITE_HAS_CODEC
         2929  +  void *pKey = 0;
         2930  +  int nKey = 0;
         2931  +#endif
  2932   2932   
  2933   2933     /* In normal use, each TCL interpreter runs in a single thread.  So
  2934   2934     ** by default, we can turn of mutexing on SQLite database connections.
  2935   2935     ** However, for testing purposes it is useful to have mutexes turned
  2936   2936     ** on.  So, by default, mutexes default off.  But if compiled with
  2937   2937     ** SQLITE_TCL_DEFAULT_FULLMUTEX then mutexes default on.
  2938   2938     */
................................................................................
  2956   2956   #endif
  2957   2957         return TCL_OK;
  2958   2958       }
  2959   2959     }
  2960   2960     for(i=3; i+1<objc; i+=2){
  2961   2961       zArg = Tcl_GetString(objv[i]);
  2962   2962       if( strcmp(zArg,"-key")==0 ){
         2963  +#ifdef SQLITE_HAS_CODEC
  2963   2964         pKey = Tcl_GetByteArrayFromObj(objv[i+1], &nKey);
         2965  +#endif
  2964   2966       }else if( strcmp(zArg, "-vfs")==0 ){
  2965   2967         zVfs = Tcl_GetString(objv[i+1]);
  2966   2968       }else if( strcmp(zArg, "-readonly")==0 ){
  2967   2969         int b;
  2968   2970         if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR;
  2969   2971         if( b ){
  2970   2972           flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);

Changes to src/update.c.

   352    352           if( pIdx->onError==OE_Replace ){
   353    353             openAll = 1;
   354    354             break;
   355    355           }
   356    356         }
   357    357       }
   358    358       for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
          359  +      assert( aRegIdx );
   359    360         if( openAll || aRegIdx[i]>0 ){
   360    361           KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
   361    362           sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,
   362    363                          (char*)pKey, P4_KEYINFO_HANDOFF);
   363    364           assert( pParse->nTab>iCur+i+1 );
   364    365         }
   365    366       }
................................................................................
   525    526     ** all record selected by the WHERE clause have been updated.
   526    527     */
   527    528     sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
   528    529     sqlite3VdbeJumpHere(v, addr);
   529    530   
   530    531     /* Close all tables */
   531    532     for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
          533  +    assert( aRegIdx );
   532    534       if( openAll || aRegIdx[i]>0 ){
   533    535         sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0);
   534    536       }
   535    537     }
   536    538     sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
   537    539   
   538    540     /* Update the sqlite_sequence table by storing the content of the

Changes to src/vdbe.c.

  2174   2174       if( pC->nullRow ){
  2175   2175         payloadSize = 0;
  2176   2176       }else if( pC->cacheStatus==p->cacheCtr ){
  2177   2177         payloadSize = pC->payloadSize;
  2178   2178         zRec = (char*)pC->aRow;
  2179   2179       }else if( pC->isIndex ){
  2180   2180         assert( sqlite3BtreeCursorIsValid(pCrsr) );
  2181         -      rc = sqlite3BtreeKeySize(pCrsr, &payloadSize64);
         2181  +      VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64);
  2182   2182         assert( rc==SQLITE_OK );   /* True because of CursorMoveto() call above */
  2183   2183         /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
  2184   2184         ** payload size, so it is impossible for payloadSize64 to be
  2185   2185         ** larger than 32 bits. */
  2186   2186         assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
  2187   2187         payloadSize = (u32)payloadSize64;
  2188   2188       }else{
  2189   2189         assert( sqlite3BtreeCursorIsValid(pCrsr) );
  2190         -      rc = sqlite3BtreeDataSize(pCrsr, &payloadSize);
         2190  +      VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &payloadSize);
  2191   2191         assert( rc==SQLITE_OK );   /* DataSize() cannot fail */
  2192   2192       }
  2193   2193     }else if( ALWAYS(pC->pseudoTableReg>0) ){
  2194   2194       pReg = &aMem[pC->pseudoTableReg];
  2195   2195       assert( pReg->flags & MEM_Blob );
  2196   2196       assert( memIsValid(pReg) );
  2197   2197       payloadSize = pReg->n;
................................................................................
  4187   4187     */
  4188   4188     assert( pC->deferredMoveto==0 );
  4189   4189     rc = sqlite3VdbeCursorMoveto(pC);
  4190   4190     if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
  4191   4191   
  4192   4192     if( pC->isIndex ){
  4193   4193       assert( !pC->isTable );
  4194         -    rc = sqlite3BtreeKeySize(pCrsr, &n64);
         4194  +    VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
  4195   4195       assert( rc==SQLITE_OK );    /* True because of CursorMoveto() call above */
  4196   4196       if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
  4197   4197         goto too_big;
  4198   4198       }
  4199   4199       n = (u32)n64;
  4200   4200     }else{
  4201         -    rc = sqlite3BtreeDataSize(pCrsr, &n);
         4201  +    VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n);
  4202   4202       assert( rc==SQLITE_OK );    /* DataSize() cannot fail */
  4203   4203       if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
  4204   4204         goto too_big;
  4205   4205       }
  4206   4206     }
  4207   4207     if( sqlite3VdbeMemGrow(pOut, n, 0) ){
  4208   4208       goto no_mem;

Changes to src/vdbeaux.c.

   777    777   #ifndef NDEBUG
   778    778   /*
   779    779   ** Change the comment on the the most recently coded instruction.  Or
   780    780   ** insert a No-op and add the comment to that new instruction.  This
   781    781   ** makes the code easier to read during debugging.  None of this happens
   782    782   ** in a production build.
   783    783   */
   784         -void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
   785         -  va_list ap;
   786         -  if( !p ) return;
          784  +static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
   787    785     assert( p->nOp>0 || p->aOp==0 );
   788    786     assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
   789    787     if( p->nOp ){
   790         -    char **pz = &p->aOp[p->nOp-1].zComment;
          788  +    assert( p->aOp );
          789  +    sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
          790  +    p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
          791  +  }
          792  +}
          793  +void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
          794  +  va_list ap;
          795  +  if( p ){
   791    796       va_start(ap, zFormat);
   792         -    sqlite3DbFree(p->db, *pz);
   793         -    *pz = sqlite3VMPrintf(p->db, zFormat, ap);
          797  +    vdbeVComment(p, zFormat, ap);
   794    798       va_end(ap);
   795    799     }
   796    800   }
   797    801   void sqlite3VdbeNoopComment(Vdbe *p, const char *zFormat, ...){
   798    802     va_list ap;
   799         -  if( !p ) return;
   800         -  sqlite3VdbeAddOp0(p, OP_Noop);
   801         -  assert( p->nOp>0 || p->aOp==0 );
   802         -  assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
   803         -  if( p->nOp ){
   804         -    char **pz = &p->aOp[p->nOp-1].zComment;
          803  +  if( p ){
          804  +    sqlite3VdbeAddOp0(p, OP_Noop);
   805    805       va_start(ap, zFormat);
   806         -    sqlite3DbFree(p->db, *pz);
   807         -    *pz = sqlite3VMPrintf(p->db, zFormat, ap);
          806  +    vdbeVComment(p, zFormat, ap);
   808    807       va_end(ap);
   809    808     }
   810    809   }
   811    810   #endif  /* NDEBUG */
   812    811   
   813    812   /*
   814    813   ** Return the opcode for a given address.  If the address is -1, then
................................................................................
  3060   3059   
  3061   3060     /* Get the size of the index entry.  Only indices entries of less
  3062   3061     ** than 2GiB are support - anything large must be database corruption.
  3063   3062     ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
  3064   3063     ** this code can safely assume that nCellKey is 32-bits  
  3065   3064     */
  3066   3065     assert( sqlite3BtreeCursorIsValid(pCur) );
  3067         -  rc = sqlite3BtreeKeySize(pCur, &nCellKey);
         3066  +  VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
  3068   3067     assert( rc==SQLITE_OK );     /* pCur is always valid so KeySize cannot fail */
  3069   3068     assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
  3070   3069   
  3071   3070     /* Read in the complete content of the index entry */
  3072   3071     memset(&m, 0, sizeof(m));
  3073   3072     rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
  3074   3073     if( rc ){
................................................................................
  3135   3134   ){
  3136   3135     i64 nCellKey = 0;
  3137   3136     int rc;
  3138   3137     BtCursor *pCur = pC->pCursor;
  3139   3138     Mem m;
  3140   3139   
  3141   3140     assert( sqlite3BtreeCursorIsValid(pCur) );
  3142         -  rc = sqlite3BtreeKeySize(pCur, &nCellKey);
         3141  +  VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
  3143   3142     assert( rc==SQLITE_OK );    /* pCur is always valid so KeySize cannot fail */
  3144   3143     /* nCellKey will always be between 0 and 0xffffffff because of the say
  3145   3144     ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
  3146   3145     if( nCellKey<=0 || nCellKey>0x7fffffff ){
  3147   3146       *res = 0;
  3148   3147       return SQLITE_CORRUPT_BKPT;
  3149   3148     }

Changes to src/wal.c.

  2339   2339     /* If iRead is non-zero, then it is the log frame number that contains the
  2340   2340     ** required page. Read and return data from the log file.
  2341   2341     */
  2342   2342     if( iRead ){
  2343   2343       int sz;
  2344   2344       i64 iOffset;
  2345   2345       sz = pWal->hdr.szPage;
  2346         -    sz = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
         2346  +    sz = (sz&0xfe00) + ((sz&0x0001)<<16);
  2347   2347       testcase( sz<=32768 );
  2348   2348       testcase( sz>=65536 );
  2349   2349       iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
  2350   2350       *pInWal = 1;
  2351   2351       /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
  2352   2352       return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
  2353   2353     }

Changes to src/where.c.

  4892   4892         }
  4893   4893       }
  4894   4894       assert( bestJ>=0 );
  4895   4895       assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
  4896   4896       WHERETRACE(("*** Optimizer selects table %d for loop %d"
  4897   4897                   " with cost=%g and nRow=%g\n",
  4898   4898                   bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.plan.nRow));
  4899         -    if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
         4899  +    /* The ALWAYS() that follows was added to hush up clang scan-build */
         4900  +    if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 && ALWAYS(ppOrderBy) ){
  4900   4901         *ppOrderBy = 0;
  4901   4902       }
  4902   4903       if( (bestPlan.plan.wsFlags & WHERE_DISTINCT)!=0 ){
  4903   4904         assert( pWInfo->eDistinct==0 );
  4904   4905         pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
  4905   4906       }
  4906   4907       andFlags &= bestPlan.plan.wsFlags;