/ Check-in [4cd20ca6]
Login

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

Overview
Comment:Merge latest trunk changes into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | reuse-schema
Files: files | file ages | folders
SHA3-256: 4cd20ca6776ef1c2f041fe6d30f84a3cf5f8a634eb34db2dce3217ee781d5848
User & Date: dan 2019-03-20 16:03:02
Wiki:reuse-schema
Context
2019-03-20
19:17
Fix an error message. check-in: a70fdaa3 user: dan tags: reuse-schema
16:03
Merge latest trunk changes into this branch. check-in: 4cd20ca6 user: dan tags: reuse-schema
12:08
Fix harmless compiler warnings from MSVC. check-in: f0f02d46 user: drh tags: trunk
2019-03-04
07:25
Merge latest trunk changes into this branch. check-in: 97a9604d user: dan tags: reuse-schema
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added LICENSE.md.

            1  +The author disclaims copyright to this source code.  In place of
            2  +a legal notice, here is a blessing:
            3  +
            4  +  *   May you do good and not evil.
            5  +  *   May you find forgiveness for yourself and forgive others.
            6  +  *   May you share freely, never taking more than you give.

Changes to Makefile.in.

  1147   1147   
  1148   1148   fts3_write.lo:	$(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)
  1149   1149   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_write.c
  1150   1150   
  1151   1151   rtree.lo:	$(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
  1152   1152   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
  1153   1153   
  1154         -sqlite3session.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
         1154  +userauth.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
  1155   1155   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c
  1156   1156   
  1157         -userauth.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
         1157  +sqlite3session.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
  1158   1158   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/session/sqlite3session.c
  1159   1159   
  1160   1160   json1.lo:	$(TOP)/ext/misc/json1.c
  1161   1161   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
  1162   1162   
  1163   1163   stmt.lo:	$(TOP)/ext/misc/stmt.c
  1164   1164   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c

Changes to README.md.

     1      1   <h1 align="center">SQLite Source Repository</h1>
     2      2   
     3      3   This repository contains the complete source code for the 
     4      4   [SQLite database engine](https://sqlite.org/).  Some test scripts 
     5      5   are also included.  However, many other test scripts
     6      6   and most of the documentation are managed separately.
     7      7   
     8         -SQLite [does not use Git](https://sqlite.org/whynotgit.html).
     9         -If you are reading this on GitHub, then you are looking at an
    10         -unofficial mirror. See <https://sqlite.org/src> for the official
    11         -repository.
    12         -
    13         -## Obtaining The Code
            8  +## Version Control
    14      9   
    15     10   SQLite sources are managed using the
    16     11   [Fossil](https://www.fossil-scm.org/), a distributed version control system
    17         -that was specifically designed to support SQLite development.
           12  +that was specifically designed and written to support SQLite development.
           13  +The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
           14  +
           15  +If you are reading this on GitHub or some other Git repository or service,
           16  +then you are looking at a mirror.  The names of check-ins and
           17  +other artifacts in a Git mirror are different from the official
           18  +names for those objects.  The offical names for check-ins are
           19  +found in a footer on the check-in comment for authorized mirrors.
           20  +The official check-in name can also be seen in the `manifest.uuid` file
           21  +in the root of the tree.  Always use the official name, not  the
           22  +Git-name, when communicating about an SQLite check-in.
           23  +
           24  +If you pulled your SQLite source code from a secondary source and want to
           25  +verify its integrity, there are hints on how to do that in the
           26  +[Verifying Code Authenticity](#vauth) section below.
           27  +
           28  +## Obtaining The Code
           29  +
    18     30   If you do not want to use Fossil, you can download tarballs or ZIP
    19     31   archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
    20     32   
    21     33     *  Lastest trunk check-in as
    22     34        [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz),
    23     35        [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip), or
    24     36        [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar).
................................................................................
   290    302   
   291    303     *  **ext/misc/json1.c** - This file implements the various JSON functions
   292    304        that are build into SQLite.
   293    305   
   294    306   There are many other source files.  Each has a succinct header comment that
   295    307   describes its purpose and role within the larger system.
   296    308   
          309  +<a name="vauth"></a>
          310  +## Verifying Code Authenticity
          311  +
          312  +If you obtained an SQLite source tree from a secondary source, such as a
          313  +GitHub mirror, and you want to verify that it has not been altered, there
          314  +are a couple of ways to do that.
          315  +
          316  +If you have an official release version of SQLite, and you are using the
          317  +`sqlite3.c` amalgamation, then SHA3-256 hashes for the amalgamation are
          318  +available in the [change log](https://www.sqlite.org/changes.html) on
          319  +the official website.  After building the `sqlite3.c` file, you can check
          320  +that is authentic by comparing the hash.  This does not ensure that the
          321  +test scripts are unaltered, but it does validate the deliverable part of
          322  +the code and only involves computing and comparing a single hash.
          323  +
          324  +For versions other than an official release, or if you are building the
          325  +`sqlite3.c` amalgamation using non-standard build options, the verification
          326  +process is a little more involved.  The `manifest` file at the root directory
          327  +of the source tree ([example](https://sqlite.org/src/artifact/bd49a8271d650fa8))
          328  +contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for 
          329  +older files) for every source file in the repository.  You can write a script
          330  +to extracts hashes from `manifest` and verifies the hashes against the 
          331  +corresponding files in the source tree.  The SHA3-256 hash of the `manifest`
          332  +file itself is the official name of the version of the source tree that you
          333  +have.  The `manifest.uuid` file should contain the SHA3-256 hash of the
          334  +`manifest` file.  If all of the above hash comparisons are correct, then
          335  +you can be confident that your source tree is authentic and unadulterated.
   297    336   
   298    337   ## Contacts
   299    338   
   300    339   The main SQLite webpage is [http://www.sqlite.org/](http://www.sqlite.org/)
   301    340   with geographically distributed backups at
   302    341   [http://www2.sqlite.org/](http://www2.sqlite.org) and
   303    342   [http://www3.sqlite.org/](http://www3.sqlite.org).

Changes to ext/fts3/fts3.c.

  1869   1869       if( !isFirstTerm ){
  1870   1870         zCsr += fts3GetVarint32(zCsr, &nPrefix);
  1871   1871       }
  1872   1872       isFirstTerm = 0;
  1873   1873       zCsr += fts3GetVarint32(zCsr, &nSuffix);
  1874   1874       
  1875   1875       assert( nPrefix>=0 && nSuffix>=0 );
  1876         -    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
         1876  +    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
  1877   1877         rc = FTS_CORRUPT_VTAB;
  1878   1878         goto finish_scan;
  1879   1879       }
  1880   1880       if( (i64)nPrefix+nSuffix>nAlloc ){
  1881   1881         char *zNew;
  1882   1882         nAlloc = ((i64)nPrefix+nSuffix) * 2;
  1883   1883         zNew = (char *)sqlite3_realloc64(zBuffer, nAlloc);

Changes to ext/fts3/fts3_term.c.

    94     94   
    95     95     rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
    96     96     if( rc!=SQLITE_OK ) return rc;
    97     97   
    98     98     nByte = sizeof(Fts3termTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
    99     99     p = (Fts3termTable *)sqlite3_malloc64(nByte);
   100    100     if( !p ) return SQLITE_NOMEM;
   101         -  memset(p, 0, nByte);
          101  +  memset(p, 0, (size_t)nByte);
   102    102   
   103    103     p->pFts3Tab = (Fts3Table *)&p[1];
   104    104     p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
   105    105     p->pFts3Tab->zName = &p->pFts3Tab->zDb[nDb+1];
   106    106     p->pFts3Tab->db = db;
   107    107     p->pFts3Tab->nIndex = iIndex+1;
   108    108     p->iIndex = iIndex;

Changes to ext/fts3/unicode/mkunicode.tcl.

   734    734       void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
   735    735         int i = 0;
   736    736         int iTbl = 0;
   737    737         while( i<128 ){
   738    738           int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
   739    739           int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   740    740           for(; i<128 && i<n; i++){
   741         -          aAscii[i] = bToken;
          741  +          aAscii[i] = (u8)bToken;
   742    742           }
   743    743           iTbl++;
   744    744         }
   745    745       }
   746    746     }]
   747    747   }
   748    748   

Changes to ext/fts5/fts5Int.h.

   579    579   /*
   580    580   ** Empty (but do not delete) a hash table.
   581    581   */
   582    582   void sqlite3Fts5HashClear(Fts5Hash*);
   583    583   
   584    584   int sqlite3Fts5HashQuery(
   585    585     Fts5Hash*,                      /* Hash table to query */
          586  +  int nPre,
   586    587     const char *pTerm, int nTerm,   /* Query term */
   587         -  const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
          588  +  void **ppObj,                   /* OUT: Pointer to doclist for pTerm */
   588    589     int *pnDoclist                  /* OUT: Size of doclist in bytes */
   589    590   );
   590    591   
   591    592   int sqlite3Fts5HashScanInit(
   592    593     Fts5Hash*,                      /* Hash table to query */
   593    594     const char *pTerm, int nTerm    /* Query prefix */
   594    595   );

Changes to ext/fts5/fts5_aux.c.

   349    349     }
   350    350   
   351    351     *pnScore = nScore;
   352    352     if( piPos ){
   353    353       sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
   354    354       if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
   355    355       if( iAdj<0 ) iAdj = 0;
   356         -    *piPos = iAdj;
          356  +    *piPos = (int)iAdj;
   357    357     }
   358    358   
   359    359     return rc;
   360    360   }
   361    361   
   362    362   /*
   363    363   ** Return the value in pVal interpreted as utf-8 text. Except, if pVal 
................................................................................
   577    577       /* Allocate the Fts5Bm25Data object */
   578    578       nPhrase = pApi->xPhraseCount(pFts);
   579    579       nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
   580    580       p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
   581    581       if( p==0 ){
   582    582         rc = SQLITE_NOMEM;
   583    583       }else{
   584         -      memset(p, 0, nByte);
          584  +      memset(p, 0, (size_t)nByte);
   585    585         p->nPhrase = nPhrase;
   586    586         p->aIDF = (double*)&p[1];
   587    587         p->aFreq = &p->aIDF[nPhrase];
   588    588       }
   589    589   
   590    590       /* Calculate the average document length for this FTS5 table */
   591    591       if( rc==SQLITE_OK ) rc = pApi->xRowCount(pFts, &nRow);

Changes to ext/fts5/fts5_buffer.c.

    23     23         nNew = nNew * 2;
    24     24       }
    25     25       pNew = sqlite3_realloc64(pBuf->p, nNew);
    26     26       if( pNew==0 ){
    27     27         *pRc = SQLITE_NOMEM;
    28     28         return 1;
    29     29       }else{
    30         -      pBuf->nSpace = nNew;
           30  +      pBuf->nSpace = (int)nNew;
    31     31         pBuf->p = pNew;
    32     32       }
    33     33     }
    34     34     return 0;
    35     35   }
    36     36   
    37     37   
................................................................................
   247    247   void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte){
   248    248     void *pRet = 0;
   249    249     if( *pRc==SQLITE_OK ){
   250    250       pRet = sqlite3_malloc64(nByte);
   251    251       if( pRet==0 ){
   252    252         if( nByte>0 ) *pRc = SQLITE_NOMEM;
   253    253       }else{
   254         -      memset(pRet, 0, nByte);
          254  +      memset(pRet, 0, (size_t)nByte);
   255    255       }
   256    256     }
   257    257     return pRet;
   258    258   }
   259    259   
   260    260   /*
   261    261   ** Return a nul-terminated copy of the string indicated by pIn. If nIn

Changes to ext/fts5/fts5_config.c.

   321    321             }
   322    322           }
   323    323           if( p==0 ){
   324    324             *pzErr = sqlite3_mprintf("parse error in tokenize directive");
   325    325             rc = SQLITE_ERROR;
   326    326           }else{
   327    327             rc = sqlite3Fts5GetTokenizer(pGlobal, 
   328         -              (const char**)azArg, nArg, &pConfig->pTok, &pConfig->pTokApi,
          328  +              (const char**)azArg, (int)nArg, &pConfig->pTok, &pConfig->pTokApi,
   329    329                 pzErr
   330    330             );
   331    331           }
   332    332         }
   333    333       }
   334    334   
   335    335       sqlite3_free(azArg);
................................................................................
   431    431     assert( *pRc==SQLITE_OK );
   432    432     *pbQuoted = 0;
   433    433     *pzOut = 0;
   434    434   
   435    435     if( zOut==0 ){
   436    436       *pRc = SQLITE_NOMEM;
   437    437     }else{
   438         -    memcpy(zOut, zIn, nIn+1);
          438  +    memcpy(zOut, zIn, (size_t)(nIn+1));
   439    439       if( fts5_isopenquote(zOut[0]) ){
   440    440         int ii = fts5Dequote(zOut);
   441    441         zRet = &zIn[ii];
   442    442         *pbQuoted = 1;
   443    443       }else{
   444    444         zRet = fts5ConfigSkipBareword(zIn);
   445    445         if( zRet ){

Changes to ext/fts5/fts5_expr.c.

  1483   1483       if( pNear==0 ){
  1484   1484         sqlite3_int64 nByte;
  1485   1485         nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
  1486   1486         pRet = sqlite3_malloc64(nByte);
  1487   1487         if( pRet==0 ){
  1488   1488           pParse->rc = SQLITE_NOMEM;
  1489   1489         }else{
  1490         -        memset(pRet, 0, nByte);
         1490  +        memset(pRet, 0, (size_t)nByte);
  1491   1491         }
  1492   1492       }else if( (pNear->nPhrase % SZALLOC)==0 ){
  1493   1493         int nNew = pNear->nPhrase + SZALLOC;
  1494   1494         sqlite3_int64 nByte;
  1495   1495   
  1496   1496         nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
  1497   1497         pRet = (Fts5ExprNearset*)sqlite3_realloc64(pNear, nByte);
................................................................................
  1559   1559     if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
  1560   1560       Fts5ExprTerm *pSyn;
  1561   1561       sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
  1562   1562       pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
  1563   1563       if( pSyn==0 ){
  1564   1564         rc = SQLITE_NOMEM;
  1565   1565       }else{
  1566         -      memset(pSyn, 0, nByte);
         1566  +      memset(pSyn, 0, (size_t)nByte);
  1567   1567         pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
  1568   1568         memcpy(pSyn->zTerm, pToken, nToken);
  1569   1569         pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
  1570   1570         pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
  1571   1571       }
  1572   1572     }else{
  1573   1573       Fts5ExprTerm *pTerm;
................................................................................
  1719   1719       Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
  1720   1720       if( pColsetOrig ){
  1721   1721         sqlite3_int64 nByte;
  1722   1722         Fts5Colset *pColset;
  1723   1723         nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
  1724   1724         pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
  1725   1725         if( pColset ){ 
  1726         -        memcpy(pColset, pColsetOrig, nByte);
         1726  +        memcpy(pColset, pColsetOrig, (size_t)nByte);
  1727   1727         }
  1728   1728         pNew->pRoot->pNear->pColset = pColset;
  1729   1729       }
  1730   1730     }
  1731   1731   
  1732   1732     if( pOrig->nTerm ){
  1733   1733       int i;                          /* Used to iterate through phrase terms */
................................................................................
  1936   1936   */
  1937   1937   static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
  1938   1938     Fts5Colset *pRet;
  1939   1939     if( pOrig ){
  1940   1940       sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
  1941   1941       pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
  1942   1942       if( pRet ){ 
  1943         -      memcpy(pRet, pOrig, nByte);
         1943  +      memcpy(pRet, pOrig, (size_t)nByte);
  1944   1944       }
  1945   1945     }else{
  1946   1946       pRet = 0;
  1947   1947     }
  1948   1948     return pRet;
  1949   1949   }
  1950   1950   

Changes to ext/fts5/fts5_hash.c.

    99     99       nByte = sizeof(Fts5HashEntry*) * pNew->nSlot;
   100    100       pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc64(nByte);
   101    101       if( pNew->aSlot==0 ){
   102    102         sqlite3_free(pNew);
   103    103         *ppNew = 0;
   104    104         rc = SQLITE_NOMEM;
   105    105       }else{
   106         -      memset(pNew->aSlot, 0, nByte);
          106  +      memset(pNew->aSlot, 0, (size_t)nByte);
   107    107       }
   108    108     }
   109    109     return rc;
   110    110   }
   111    111   
   112    112   /*
   113    113   ** Free a hash table object.
................................................................................
   183    183   
   184    184     sqlite3_free(apOld);
   185    185     pHash->nSlot = nNew;
   186    186     pHash->aSlot = apNew;
   187    187     return SQLITE_OK;
   188    188   }
   189    189   
   190         -static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
          190  +static int fts5HashAddPoslistSize(
          191  +  Fts5Hash *pHash, 
          192  +  Fts5HashEntry *p,
          193  +  Fts5HashEntry *p2
          194  +){
          195  +  int nRet = 0;
   191    196     if( p->iSzPoslist ){
   192         -    u8 *pPtr = (u8*)p;
          197  +    u8 *pPtr = p2 ? (u8*)p2 : (u8*)p;
          198  +    int nData = p->nData;
   193    199       if( pHash->eDetail==FTS5_DETAIL_NONE ){
   194         -      assert( p->nData==p->iSzPoslist );
          200  +      assert( nData==p->iSzPoslist );
   195    201         if( p->bDel ){
   196         -        pPtr[p->nData++] = 0x00;
          202  +        pPtr[nData++] = 0x00;
   197    203           if( p->bContent ){
   198         -          pPtr[p->nData++] = 0x00;
          204  +          pPtr[nData++] = 0x00;
   199    205           }
   200    206         }
   201    207       }else{
   202         -      int nSz = (p->nData - p->iSzPoslist - 1);       /* Size in bytes */
          208  +      int nSz = (nData - p->iSzPoslist - 1);       /* Size in bytes */
   203    209         int nPos = nSz*2 + p->bDel;                     /* Value of nPos field */
   204    210   
   205    211         assert( p->bDel==0 || p->bDel==1 );
   206    212         if( nPos<=127 ){
   207    213           pPtr[p->iSzPoslist] = (u8)nPos;
   208    214         }else{
   209    215           int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
   210    216           memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
   211    217           sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
   212         -        p->nData += (nByte-1);
          218  +        nData += (nByte-1);
   213    219         }
   214    220       }
   215    221   
   216         -    p->iSzPoslist = 0;
   217         -    p->bDel = 0;
   218         -    p->bContent = 0;
          222  +    nRet = nData - p->nData;
          223  +    if( p2==0 ){
          224  +      p->iSzPoslist = 0;
          225  +      p->bDel = 0;
          226  +      p->bContent = 0;
          227  +      p->nData = nData;
          228  +    }
   219    229     }
          230  +  return nRet;
   220    231   }
   221    232   
   222    233   /*
   223    234   ** Add an entry to the in-memory hash table. The key is the concatenation
   224    235   ** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
   225    236   **
   226    237   **     (bByte || pToken) -> (iRowid,iCol,iPos)
................................................................................
   269    280         iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
   270    281       }
   271    282   
   272    283       /* Allocate new Fts5HashEntry and add it to the hash table. */
   273    284       p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
   274    285       if( !p ) return SQLITE_NOMEM;
   275    286       memset(p, 0, sizeof(Fts5HashEntry));
   276         -    p->nAlloc = nByte;
          287  +    p->nAlloc = (int)nByte;
   277    288       zKey = fts5EntryKey(p);
   278    289       zKey[0] = bByte;
   279    290       memcpy(&zKey[1], pToken, nToken);
   280    291       assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
   281    292       p->nKey = nToken;
   282    293       zKey[nToken+1] = '\0';
   283    294       p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
................................................................................
   324    335     assert( (p->nAlloc - p->nData) >= (9 + 4 + 1 + 3 + 5) );
   325    336   
   326    337     pPtr = (u8*)p;
   327    338   
   328    339     /* If this is a new rowid, append the 4-byte size field for the previous
   329    340     ** entry, and the new rowid for this entry.  */
   330    341     if( iRowid!=p->iRowid ){
   331         -    fts5HashAddPoslistSize(pHash, p);
          342  +    fts5HashAddPoslistSize(pHash, p, 0);
   332    343       p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
   333    344       p->iRowid = iRowid;
   334    345       bNew = 1;
   335    346       p->iSzPoslist = p->nData;
   336    347       if( pHash->eDetail!=FTS5_DETAIL_NONE ){
   337    348         p->nData += 1;
   338    349         p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
................................................................................
   441    452     ap = sqlite3_malloc64(sizeof(Fts5HashEntry*) * nMergeSlot);
   442    453     if( !ap ) return SQLITE_NOMEM;
   443    454     memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
   444    455   
   445    456     for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
   446    457       Fts5HashEntry *pIter;
   447    458       for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
   448         -      if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
          459  +      if( pTerm==0 
          460  +       || (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
          461  +      ){
   449    462           Fts5HashEntry *pEntry = pIter;
   450    463           pEntry->pScanNext = 0;
   451    464           for(i=0; ap[i]; i++){
   452    465             pEntry = fts5HashEntryMerge(pEntry, ap[i]);
   453    466             ap[i] = 0;
   454    467           }
   455    468           ap[i] = pEntry;
................................................................................
   469    482   }
   470    483   
   471    484   /*
   472    485   ** Query the hash table for a doclist associated with term pTerm/nTerm.
   473    486   */
   474    487   int sqlite3Fts5HashQuery(
   475    488     Fts5Hash *pHash,                /* Hash table to query */
          489  +  int nPre,
   476    490     const char *pTerm, int nTerm,   /* Query term */
   477         -  const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
          491  +  void **ppOut,                   /* OUT: Pointer to new object */
   478    492     int *pnDoclist                  /* OUT: Size of doclist in bytes */
   479    493   ){
   480    494     unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
   481    495     char *zKey = 0;
   482    496     Fts5HashEntry *p;
   483    497   
   484    498     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
   485    499       zKey = fts5EntryKey(p);
   486    500       assert( p->nKey+1==(int)strlen(zKey) );
   487    501       if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
   488    502     }
   489    503   
   490    504     if( p ){
   491         -    fts5HashAddPoslistSize(pHash, p);
   492         -    *ppDoclist = (const u8*)&zKey[nTerm+1];
   493         -    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
          505  +    int nHashPre = sizeof(Fts5HashEntry) + nTerm + 1;
          506  +    int nList = p->nData - nHashPre;
          507  +    u8 *pRet = (u8*)(*ppOut = sqlite3_malloc64(nPre + nList + 10));
          508  +    if( pRet ){
          509  +      Fts5HashEntry *pFaux = (Fts5HashEntry*)&pRet[nPre-nHashPre];
          510  +      memcpy(&pRet[nPre], &((u8*)p)[nHashPre], nList);
          511  +      nList += fts5HashAddPoslistSize(pHash, p, pFaux);
          512  +      *pnDoclist = nList;
          513  +    }else{
          514  +      *pnDoclist = 0;
          515  +      return SQLITE_NOMEM;
          516  +    }
   494    517     }else{
   495         -    *ppDoclist = 0;
          518  +    *ppOut = 0;
   496    519       *pnDoclist = 0;
   497    520     }
   498    521   
   499    522     return SQLITE_OK;
   500    523   }
   501    524   
   502    525   int sqlite3Fts5HashScanInit(
................................................................................
   521    544     const u8 **ppDoclist,           /* OUT: pointer to doclist */
   522    545     int *pnDoclist                  /* OUT: size of doclist in bytes */
   523    546   ){
   524    547     Fts5HashEntry *p;
   525    548     if( (p = pHash->pScan) ){
   526    549       char *zKey = fts5EntryKey(p);
   527    550       int nTerm = (int)strlen(zKey);
   528         -    fts5HashAddPoslistSize(pHash, p);
          551  +    fts5HashAddPoslistSize(pHash, p, 0);
   529    552       *pzTerm = zKey;
   530    553       *ppDoclist = (const u8*)&zKey[nTerm+1];
   531    554       *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
   532    555     }else{
   533    556       *pzTerm = 0;
   534    557       *ppDoclist = 0;
   535    558       *pnDoclist = 0;
   536    559     }
   537    560   }

Changes to ext/fts5/fts5_index.c.

  2453   2453   */
  2454   2454   static void fts5SegIterHashInit(
  2455   2455     Fts5Index *p,                   /* FTS5 backend */
  2456   2456     const u8 *pTerm, int nTerm,     /* Term to seek to */
  2457   2457     int flags,                      /* Mask of FTS5INDEX_XXX flags */
  2458   2458     Fts5SegIter *pIter              /* Object to populate */
  2459   2459   ){
  2460         -  const u8 *pList = 0;
  2461   2460     int nList = 0;
  2462   2461     const u8 *z = 0;
  2463   2462     int n = 0;
         2463  +  Fts5Data *pLeaf = 0;
  2464   2464   
  2465   2465     assert( p->pHash );
  2466   2466     assert( p->rc==SQLITE_OK );
  2467   2467   
  2468   2468     if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
         2469  +    const u8 *pList = 0;
         2470  +
  2469   2471       p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
  2470   2472       sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
  2471   2473       n = (z ? (int)strlen((const char*)z) : 0);
         2474  +    if( pList ){
         2475  +      pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
         2476  +      if( pLeaf ){
         2477  +        pLeaf->p = (u8*)pList;
         2478  +      }
         2479  +    }
  2472   2480     }else{
  2473         -    pIter->flags |= FTS5_SEGITER_ONETERM;
  2474         -    sqlite3Fts5HashQuery(p->pHash, (const char*)pTerm, nTerm, &pList, &nList);
         2481  +    p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data), 
         2482  +        (const char*)pTerm, nTerm, (void**)&pLeaf, &nList
         2483  +    );
         2484  +    if( pLeaf ){
         2485  +      pLeaf->p = (u8*)&pLeaf[1];
         2486  +    }
  2475   2487       z = pTerm;
  2476   2488       n = nTerm;
         2489  +    pIter->flags |= FTS5_SEGITER_ONETERM;
  2477   2490     }
  2478   2491   
  2479         -  if( pList ){
  2480         -    Fts5Data *pLeaf;
         2492  +  if( pLeaf ){
  2481   2493       sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
  2482         -    pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
  2483         -    if( pLeaf==0 ) return;
  2484         -    pLeaf->p = (u8*)pList;
  2485   2494       pLeaf->nn = pLeaf->szLeaf = nList;
  2486   2495       pIter->pLeaf = pLeaf;
  2487   2496       pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
  2488   2497       pIter->iEndofDoclist = pLeaf->nn;
  2489   2498   
  2490   2499       if( flags & FTS5INDEX_QUERY_DESC ){
  2491   2500         pIter->flags |= FTS5_SEGITER_REVERSE;

Changes to ext/fts5/fts5_main.c.

   629    629   
   630    630     rc = fts5NewTransaction(pTab);
   631    631     if( rc==SQLITE_OK ){
   632    632       nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
   633    633       pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
   634    634       if( pCsr ){
   635    635         Fts5Global *pGlobal = pTab->pGlobal;
   636         -      memset(pCsr, 0, nByte);
          636  +      memset(pCsr, 0, (size_t)nByte);
   637    637         pCsr->aColumnSize = (int*)&pCsr[1];
   638    638         pCsr->pNext = pGlobal->pCsr;
   639    639         pGlobal->pCsr = pCsr;
   640    640         pCsr->iCsrId = ++pGlobal->iNextId;
   641    641       }else{
   642    642         rc = SQLITE_NOMEM;
   643    643       }
................................................................................
   910    910     const char *zRank = pCsr->zRank;
   911    911     const char *zRankArgs = pCsr->zRankArgs;
   912    912     
   913    913     nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
   914    914     nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
   915    915     pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
   916    916     if( pSorter==0 ) return SQLITE_NOMEM;
   917         -  memset(pSorter, 0, nByte);
          917  +  memset(pSorter, 0, (size_t)nByte);
   918    918     pSorter->nIdx = nPhrase;
   919    919   
   920    920     /* TODO: It would be better to have some system for reusing statement
   921    921     ** handles here, rather than preparing a new one for each query. But that
   922    922     ** is not possible as SQLite reference counts the virtual table objects.
   923    923     ** And since the statement required here reads from this very virtual 
   924    924     ** table, saving it creates a circular reference.

Changes to ext/fts5/fts5_storage.c.

   285    285     sqlite3_int64 nByte;            /* Bytes of space to allocate */
   286    286   
   287    287     nByte = sizeof(Fts5Storage)               /* Fts5Storage object */
   288    288           + pConfig->nCol * sizeof(i64);      /* Fts5Storage.aTotalSize[] */
   289    289     *pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
   290    290     if( !p ) return SQLITE_NOMEM;
   291    291   
   292         -  memset(p, 0, nByte);
          292  +  memset(p, 0, (size_t)nByte);
   293    293     p->aTotalSize = (i64*)&p[1];
   294    294     p->pConfig = pConfig;
   295    295     p->pIndex = pIndex;
   296    296   
   297    297     if( bCreate ){
   298    298       if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
   299    299         int nDefn = 32 + pConfig->nCol*10;

Changes to ext/fts5/fts5_unicode2.c.

   765    765   void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
   766    766     int i = 0;
   767    767     int iTbl = 0;
   768    768     while( i<128 ){
   769    769       int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
   770    770       int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   771    771       for(; i<128 && i<n; i++){
   772         -      aAscii[i] = bToken;
          772  +      aAscii[i] = (u8)bToken;
   773    773       }
   774    774       iTbl++;
   775    775     }
   776    776   }

Changes to ext/fts5/test/fts5aa.test.

   423    423     INSERT INTO n1 VALUES('a b c d');
   424    424   }
   425    425   
   426    426   proc funk {} {
   427    427     db eval { UPDATE n1_config SET v=50 WHERE k='version' }
   428    428     set fd [db incrblob main n1_data block 10]
   429    429     fconfigure $fd -encoding binary -translation binary
   430         -  puts -nonewline $fd "\x44\x45"
          430  +#  puts -nonewline $fd "\x44\x45"
   431    431     close $fd
   432    432   }
   433    433   db func funk funk
   434    434   
   435    435   # This test case corrupts the structure record within the first invocation
   436    436   # of function funk(). Which used to cause the bm25() function to throw an
   437    437   # exception. But since bm25() can now used the cached structure record,
................................................................................
   598    598   }
   599    599   do_execsql_test 23.1 {
   600    600     SELECT * FROM t11, t10 WHERE t11.x = t10.x AND t10.rowid IS NULL;
   601    601   }
   602    602   do_execsql_test 23.2 {
   603    603     SELECT * FROM t11, t10 WHERE t10.rowid IS NULL;
   604    604   }
          605  +
          606  +#-------------------------------------------------------------------------
          607  +do_execsql_test 24.0 {
          608  +  CREATE VIRTUAL TABLE t12 USING fts5(x, detail=%DETAIL%);
          609  +  INSERT INTO t12 VALUES('aaaa');
          610  +}
          611  +do_execsql_test 24.1 {
          612  +  BEGIN;
          613  +    DELETE FROM t12 WHERE rowid=1;
          614  +    SELECT * FROM t12('aaaa');
          615  +    INSERT INTO t12 VALUES('aaaa');
          616  +  END;
          617  +}
          618  +do_execsql_test 24.2 {
          619  +  INSERT INTO t12(t12) VALUES('integrity-check');
          620  +}
          621  +do_execsql_test 24.3 {
          622  +    SELECT * FROM t12('aaaa');
          623  +} {aaaa}
          624  +
          625  +#-------------------------------------------------------------------------
          626  +do_execsql_test 25.0 {
          627  +  CREATE VIRTUAL TABLE t13 USING fts5(x, detail=%DETAIL%);
          628  +}
          629  +do_execsql_test 25.1 {
          630  +  BEGIN;
          631  +  INSERT INTO t13 VALUES('AAAA');
          632  +SELECT * FROM t13('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*');
          633  +
          634  +  END;
          635  +}
          636  +
   605    637   
   606    638   }
   607    639   
   608    640   expand_all_sql db
   609    641   finish_test

Changes to ext/misc/amatch.c.

   743    743   
   744    744     nIn = strlen(zIn);
   745    745     zOut = sqlite3_malloc64(nIn+1);
   746    746     if( zOut ){
   747    747       char q = zIn[0];              /* Quote character (if any ) */
   748    748   
   749    749       if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
   750         -      memcpy(zOut, zIn, nIn+1);
          750  +      memcpy(zOut, zIn, (size_t)(nIn+1));
   751    751       }else{
   752    752         int iOut = 0;               /* Index of next byte to write to output */
   753    753         int iIn;                    /* Index of next byte to read from input */
   754    754   
   755    755         if( q=='[' ) q = ']';
   756    756         for(iIn=1; iIn<nIn; iIn++){
   757    757           if( zIn[iIn]==q ) iIn++;

Changes to ext/misc/closure.c.

   427    427   
   428    428     nIn = strlen(zIn);
   429    429     zOut = sqlite3_malloc64(nIn+1);
   430    430     if( zOut ){
   431    431       char q = zIn[0];              /* Quote character (if any ) */
   432    432   
   433    433       if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
   434         -      memcpy(zOut, zIn, nIn+1);
          434  +      memcpy(zOut, zIn, (size_t)(nIn+1));
   435    435       }else{
   436    436         int iOut = 0;               /* Index of next byte to write to output */
   437    437         int iIn;                    /* Index of next byte to read from input */
   438    438   
   439    439         if( q=='[' ) q = ']';
   440    440         for(iIn=1; iIn<nIn; iIn++){
   441    441           if( zIn[iIn]==q ) iIn++;

Changes to ext/misc/fileio.c.

   154    154     }
   155    155     pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
   156    156     if( pBuf==0 ){
   157    157       sqlite3_result_error_nomem(ctx);
   158    158       fclose(in);
   159    159       return;
   160    160     }
   161         -  if( nIn==fread(pBuf, 1, nIn, in) ){
          161  +  if( nIn==fread(pBuf, 1, (size_t)nIn, in) ){
   162    162       sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
   163    163     }else{
   164    164       sqlite3_result_error_code(ctx, SQLITE_IOERR);
   165    165       sqlite3_free(pBuf);
   166    166     }
   167    167     fclose(in);
   168    168   }

Changes to ext/misc/fuzzer.c.

   452    452   
   453    453     nIn = strlen(zIn);
   454    454     zOut = sqlite3_malloc64(nIn+1);
   455    455     if( zOut ){
   456    456       char q = zIn[0];              /* Quote character (if any ) */
   457    457   
   458    458       if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
   459         -      memcpy(zOut, zIn, nIn+1);
          459  +      memcpy(zOut, zIn, (size_t)(nIn+1));
   460    460       }else{
   461    461         int iOut = 0;               /* Index of next byte to write to output */
   462    462         int iIn;                    /* Index of next byte to read from input */
   463    463   
   464    464         if( q=='[' ) q = ']';
   465    465         for(iIn=1; iIn<nIn; iIn++){
   466    466           if( zIn[iIn]==q ) iIn++;
................................................................................
   520    520       if( pNew==0 ){
   521    521         rc = SQLITE_NOMEM;
   522    522       }else{
   523    523         char *zTab;                 /* Dequoted name of fuzzer data table */
   524    524   
   525    525         memset(pNew, 0, sizeof(*pNew));
   526    526         pNew->zClassName = (char*)&pNew[1];
   527         -      memcpy(pNew->zClassName, zModule, nModule+1);
          527  +      memcpy(pNew->zClassName, zModule, (size_t)(nModule+1));
   528    528   
   529    529         zTab = fuzzerDequote(argv[3]);
   530    530         if( zTab==0 ){
   531    531           rc = SQLITE_NOMEM;
   532    532         }else{
   533    533           rc = fuzzerLoadRules(db, pNew, zDb, zTab, pzErr);
   534    534           sqlite3_free(zTab);

Changes to ext/misc/unionvtab.c.

   252    252   */
   253    253   static void *unionMalloc(int *pRc, sqlite3_int64 nByte){
   254    254     void *pRet;
   255    255     assert( nByte>0 );
   256    256     if( *pRc==SQLITE_OK ){
   257    257       pRet = sqlite3_malloc64(nByte);
   258    258       if( pRet ){
   259         -      memset(pRet, 0, nByte);
          259  +      memset(pRet, 0, (size_t)nByte);
   260    260       }else{
   261    261         *pRc = SQLITE_NOMEM;
   262    262       }
   263    263     }else{
   264    264       pRet = 0;
   265    265     }
   266    266     return pRet;
................................................................................
   275    275   */
   276    276   static char *unionStrdup(int *pRc, const char *zIn){
   277    277     char *zRet = 0;
   278    278     if( zIn ){
   279    279       sqlite3_int64 nByte = strlen(zIn) + 1;
   280    280       zRet = unionMalloc(pRc, nByte);
   281    281       if( zRet ){
   282         -      memcpy(zRet, zIn, nByte);
          282  +      memcpy(zRet, zIn, (size_t)nByte);
   283    283       }
   284    284     }
   285    285     return zRet;
   286    286   }
   287    287   
   288    288   /*
   289    289   ** If the first character of the string passed as the only argument to this

Changes to ext/rtree/rtree.c.

  3751   3751   **
  3752   3752   ** The human readable string takes the form of a Tcl list with one
  3753   3753   ** entry for each cell in the r-tree node. Each entry is itself a
  3754   3754   ** list, containing the 8-byte rowid/pageno followed by the 
  3755   3755   ** <num-dimension>*2 coordinates.
  3756   3756   */
  3757   3757   static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
  3758         -  char *zText = 0;
  3759   3758     RtreeNode node;
  3760   3759     Rtree tree;
  3761   3760     int ii;
         3761  +  int nData;
         3762  +  int errCode;
         3763  +  sqlite3_str *pOut;
  3762   3764   
  3763   3765     UNUSED_PARAMETER(nArg);
  3764   3766     memset(&node, 0, sizeof(RtreeNode));
  3765   3767     memset(&tree, 0, sizeof(Rtree));
  3766   3768     tree.nDim = (u8)sqlite3_value_int(apArg[0]);
         3769  +  if( tree.nDim<1 || tree.nDim>5 ) return;
  3767   3770     tree.nDim2 = tree.nDim*2;
  3768   3771     tree.nBytesPerCell = 8 + 8 * tree.nDim;
  3769   3772     node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
         3773  +  nData = sqlite3_value_bytes(apArg[1]);
         3774  +  if( nData<4 ) return;
         3775  +  if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
  3770   3776   
         3777  +  pOut = sqlite3_str_new(0);
  3771   3778     for(ii=0; ii<NCELL(&node); ii++){
  3772         -    char zCell[512];
  3773         -    int nCell = 0;
  3774   3779       RtreeCell cell;
  3775   3780       int jj;
  3776   3781   
  3777   3782       nodeGetCell(&tree, &node, ii, &cell);
  3778         -    sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
  3779         -    nCell = (int)strlen(zCell);
         3783  +    if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
         3784  +    sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
  3780   3785       for(jj=0; jj<tree.nDim2; jj++){
  3781   3786   #ifndef SQLITE_RTREE_INT_ONLY
  3782         -      sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
  3783         -                       (double)cell.aCoord[jj].f);
         3787  +      sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
  3784   3788   #else
  3785         -      sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
  3786         -                       cell.aCoord[jj].i);
         3789  +      sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
  3787   3790   #endif
  3788         -      nCell = (int)strlen(zCell);
  3789   3791       }
  3790         -
  3791         -    if( zText ){
  3792         -      char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
  3793         -      sqlite3_free(zText);
  3794         -      zText = zTextNew;
  3795         -    }else{
  3796         -      zText = sqlite3_mprintf("{%s}", zCell);
  3797         -    }
         3792  +    sqlite3_str_append(pOut, "}", 1);
  3798   3793     }
  3799         -  
  3800         -  sqlite3_result_text(ctx, zText, -1, sqlite3_free);
         3794  +  errCode = sqlite3_str_errcode(pOut);
         3795  +  sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
         3796  +  sqlite3_result_error_code(ctx, errCode);
  3801   3797   }
  3802   3798   
  3803   3799   /* This routine implements an SQL function that returns the "depth" parameter
  3804   3800   ** from the front of a blob that is an r-tree node.  For example:
  3805   3801   **
  3806   3802   **     SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
  3807   3803   **

Changes to ext/session/changeset.c.

    51     51     }
    52     52     fseek(f, 0, SEEK_END);
    53     53     sz = ftell(f);
    54     54     rewind(f);
    55     55     pBuf = sqlite3_malloc64( sz ? sz : 1 );
    56     56     if( pBuf==0 ){
    57     57       fprintf(stderr, "cannot allocate %d to hold content of \"%s\"\n",
    58         -            sz, zFilename);
           58  +            (int)sz, zFilename);
    59     59       exit(1);
    60     60     }
    61     61     if( sz>0 ){
    62         -    if( fread(pBuf, sz, 1, f)!=1 ){
    63         -      fprintf(stderr, "cannot read all %d bytes of \"%s\"\n", sz, zFilename);
           62  +    if( fread(pBuf, (size_t)sz, 1, f)!=1 ){
           63  +      fprintf(stderr, "cannot read all %d bytes of \"%s\"\n",
           64  +              (int)sz, zFilename);
    64     65         exit(1);
    65     66       }
    66     67       fclose(f);
    67     68     }
    68         -  *pSz = sz;
           69  +  *pSz = (int)sz;
    69     70     *ppBuf = pBuf;
    70     71   }
    71     72   
    72     73   /* Array for converting from half-bytes (nybbles) into ASCII hex
    73     74   ** digits. */
    74     75   static const char hexdigits[] = {
    75     76     '0', '1', '2', '3', '4', '5', '6', '7',

Changes to src/alter.c.

   162    162       pVTab = sqlite3GetVTable(db, pTab);
   163    163       if( pVTab->pVtab->pModule->xRename==0 ){
   164    164         pVTab = 0;
   165    165       }
   166    166     }
   167    167   #endif
   168    168   
   169         -  /* Begin a transaction for database iDb. 
   170         -  ** Then modify the schema cookie (since the ALTER TABLE modifies the
   171         -  ** schema). Open a statement transaction if the table is a virtual
   172         -  ** table.
   173         -  */
          169  +  /* Begin a transaction for database iDb. Then modify the schema cookie
          170  +  ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
          171  +  ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the 
          172  +  ** nested SQL may raise an exception.  */
   174    173     v = sqlite3GetVdbe(pParse);
   175    174     if( v==0 ){
   176    175       goto exit_rename_table;
   177    176     }
          177  +  sqlite3MayAbort(pParse);
   178    178   
   179    179     /* figure out how many UTF-8 characters are in zName */
   180    180     zTabName = pTab->zName;
   181    181     nTabName = sqlite3Utf8CharLen(zTabName, -1);
   182    182   
   183    183     /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
   184    184     ** the schema to use the new table name.  */
................................................................................
   239    239     ** SQLite tables) that are identified by the name of the virtual table.
   240    240     */
   241    241   #ifndef SQLITE_OMIT_VIRTUALTABLE
   242    242     if( pVTab ){
   243    243       int i = ++pParse->nMem;
   244    244       sqlite3VdbeLoadString(v, i, zName);
   245    245       sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
   246         -    sqlite3MayAbort(pParse);
   247    246     }
   248    247   #endif
   249    248   
   250    249     renameReloadSchema(pParse, iDb);
   251    250     renameTestSchema(pParse, zDb, iDb==1);
   252    251   
   253    252   exit_rename_table:
................................................................................
   560    559       goto exit_rename_column;
   561    560     }
   562    561   
   563    562     /* Do the rename operation using a recursive UPDATE statement that
   564    563     ** uses the sqlite_rename_column() SQL function to compute the new
   565    564     ** CREATE statement text for the sqlite_master table.
   566    565     */
          566  +  sqlite3MayAbort(pParse);
   567    567     zNew = sqlite3NameFromToken(db, pNew);
   568    568     if( !zNew ) goto exit_rename_column;
   569    569     assert( pNew->n>0 );
   570    570     bQuote = sqlite3Isquote(pNew->z[0]);
   571    571     sqlite3NestedParse(pParse, 
   572    572         "UPDATE \"%w\".%s SET "
   573    573         "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "

Changes to src/attach.c.

   228    228     /* If the file was opened successfully, read the schema for the new database.
   229    229     ** If this fails, or if opening the file failed, then close the file and 
   230    230     ** remove the entry from the db->aDb[] array. i.e. put everything back the
   231    231     ** way we found it.
   232    232     */
   233    233     if( rc==SQLITE_OK ){
   234    234       db->init.iDb = 0;
   235         -    if( !IsReuseSchema(db) ){
   236         -      db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
          235  +    db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
          236  +    if( !IsReuseSchema(db) && !REOPEN_AS_MEMDB(db) ){
   237    237         sqlite3BtreeEnterAll(db);
   238    238         rc = sqlite3Init(db, &zErrDyn);
   239    239         sqlite3BtreeLeaveAll(db);
   240    240         assert( zErrDyn==0 || rc!=SQLITE_OK );
   241    241       }
   242    242     }
   243    243   #ifdef SQLITE_USER_AUTHENTICATION

Changes to src/btree.c.

  1569   1569           ** for the portion used by the new allocation. */
  1570   1570           put2byte(&aData[pc+2], x);
  1571   1571         }
  1572   1572         return &aData[pc + x];
  1573   1573       }
  1574   1574       iAddr = pc;
  1575   1575       pc = get2byte(&aData[pc]);
  1576         -    if( pc<iAddr+size ){
         1576  +    if( pc<=iAddr+size ){
  1577   1577         if( pc ){
  1578   1578           /* The next slot in the chain is not past the end of the current slot */
  1579   1579           *pRc = SQLITE_CORRUPT_PAGE(pPg);
  1580   1580         }
  1581   1581         return 0;
  1582   1582       }
  1583   1583     }
................................................................................
  2009   2009     }
  2010   2010     testcase( pPage->nCell==MX_CELL(pBt) );
  2011   2011     /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
  2012   2012     ** possible for a root page of a table that contains no rows) then the
  2013   2013     ** offset to the cell content area will equal the page size minus the
  2014   2014     ** bytes of reserved space. */
  2015   2015     assert( pPage->nCell>0
  2016         -       || get2byteNotZero(&data[5])==pBt->usableSize
         2016  +       || get2byteNotZero(&data[5])==(int)pBt->usableSize
  2017   2017          || CORRUPT_DB );
  2018   2018     pPage->nFree = -1;  /* Indicate that this value is yet uncomputed */
  2019   2019     pPage->isInit = 1;
  2020   2020     if( pBt->db->flags & SQLITE_CellSizeCk ){
  2021   2021       return btreeCellSizeCheck(pPage);
  2022   2022     }
  2023   2023     return SQLITE_OK;
................................................................................
  5548   5548             pCur->ix = (u16)idx;
  5549   5549             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
  5550   5550             pCur->curFlags &= ~BTCF_ValidOvfl;
  5551   5551             if( rc ){
  5552   5552               sqlite3_free(pCellKey);
  5553   5553               goto moveto_finish;
  5554   5554             }
  5555         -          c = xRecordCompare(nCell, pCellKey, pIdxKey);
         5555  +          c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
  5556   5556             sqlite3_free(pCellKey);
  5557   5557           }
  5558   5558           assert( 
  5559   5559               (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
  5560   5560            && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
  5561   5561           );
  5562   5562           if( c<0 ){
................................................................................
  7148   7148     }
  7149   7149   
  7150   7150     /* Add any overflow cells */
  7151   7151     for(i=0; i<pPg->nOverflow; i++){
  7152   7152       int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
  7153   7153       if( iCell>=0 && iCell<nNew ){
  7154   7154         pCellptr = &pPg->aCellIdx[iCell * 2];
  7155         -      assert( nCell>=iCell );
  7156         -      memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
         7155  +      if( nCell>iCell ){
         7156  +        memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
         7157  +      }
  7157   7158         nCell++;
  7158   7159         if( pageInsertArray(
  7159   7160               pPg, pBegin, &pData, pCellptr,
  7160   7161               iCell+iNew, 1, pCArray
  7161   7162         ) ) goto editpage_fail;
  7162   7163       }
  7163   7164     }
................................................................................
  7554   7555       if( apOld[i]->nFree<0 ){
  7555   7556         rc = btreeComputeFreeSpace(apOld[i]);
  7556   7557         if( rc ){
  7557   7558           memset(apOld, 0, (i)*sizeof(MemPage*));
  7558   7559           goto balance_cleanup;
  7559   7560         }
  7560   7561       }
  7561         -    nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
  7562   7562       if( (i--)==0 ) break;
  7563   7563   
  7564   7564       if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
  7565   7565         apDiv[i] = pParent->apOvfl[0];
  7566   7566         pgno = get4byte(apDiv[i]);
  7567   7567         szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
  7568   7568         pParent->nOverflow = 0;
................................................................................
  7598   7598         }
  7599   7599         dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc);
  7600   7600       }
  7601   7601     }
  7602   7602   
  7603   7603     /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
  7604   7604     ** alignment */
         7605  +  nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
  7605   7606     nMaxCells = (nMaxCells + 3)&~3;
  7606   7607   
  7607   7608     /*
  7608   7609     ** Allocate space for memory structures
  7609   7610     */
  7610   7611     szScratch =
  7611   7612          nMaxCells*sizeof(u8*)                       /* b.apCell */
  7612   7613        + nMaxCells*sizeof(u16)                       /* b.szCell */
  7613   7614        + pBt->pageSize;                              /* aSpace1 */
  7614   7615   
  7615         -  assert( szScratch<=6*(int)pBt->pageSize );
         7616  +  assert( szScratch<=7*(int)pBt->pageSize );
  7616   7617     b.apCell = sqlite3StackAllocRaw(0, szScratch );
  7617   7618     if( b.apCell==0 ){
  7618   7619       rc = SQLITE_NOMEM_BKPT;
  7619   7620       goto balance_cleanup;
  7620   7621     }
  7621   7622     b.szCell = (u16*)&b.apCell[nMaxCells];
  7622   7623     aSpace1 = (u8*)&b.szCell[nMaxCells];
................................................................................
  9264   9265     int rc;
  9265   9266     MemPage *pPage = 0;
  9266   9267     BtShared *pBt = p->pBt;
  9267   9268   
  9268   9269     assert( sqlite3BtreeHoldsMutex(p) );
  9269   9270     assert( p->inTrans==TRANS_WRITE );
  9270   9271     assert( iTable>=2 );
         9272  +  if( iTable>btreePagecount(pBt) ){
         9273  +    return SQLITE_CORRUPT_BKPT;
         9274  +  }
  9271   9275   
  9272   9276     rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
  9273   9277     if( rc ) return rc;
  9274   9278     rc = sqlite3BtreeClearTable(p, iTable, 0);
  9275   9279     if( rc ){
  9276   9280       releasePage(pPage);
  9277   9281       return rc;

Changes to src/os_unix.c.

  7818   7818     ** array cannot be const.
  7819   7819     */
  7820   7820     static sqlite3_vfs aVfs[] = {
  7821   7821   #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
  7822   7822       UNIXVFS("unix",          autolockIoFinder ),
  7823   7823   #elif OS_VXWORKS
  7824   7824       UNIXVFS("unix",          vxworksIoFinder ),
  7825         -#elif __Fuchsia__
  7826         -    /* We are told that Fuchsia only supports dot-file locking */
  7827         -    UNIXVFS("unix",          dotlockIoFinder ),
  7828   7825   #else
  7829   7826       UNIXVFS("unix",          posixIoFinder ),
  7830   7827   #endif
  7831   7828       UNIXVFS("unix-none",     nolockIoFinder ),
  7832   7829       UNIXVFS("unix-dotfile",  dotlockIoFinder ),
  7833   7830       UNIXVFS("unix-excl",     posixIoFinder ),
  7834   7831   #if OS_VXWORKS

Changes to src/pager.c.

  7173   7173     /* If the cache contains a page with page-number pgno, remove it
  7174   7174     ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for 
  7175   7175     ** page pgno before the 'move' operation, it needs to be retained 
  7176   7176     ** for the page moved there.
  7177   7177     */
  7178   7178     pPg->flags &= ~PGHDR_NEED_SYNC;
  7179   7179     pPgOld = sqlite3PagerLookup(pPager, pgno);
  7180         -  assert( !pPgOld || pPgOld->nRef==1 );
         7180  +  assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
  7181   7181     if( pPgOld ){
         7182  +    if( pPgOld->nRef>1 ){
         7183  +      sqlite3PagerUnrefNotNull(pPgOld);
         7184  +      return SQLITE_CORRUPT_BKPT;
         7185  +    }
  7182   7186       pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
  7183   7187       if( pPager->tempFile ){
  7184   7188         /* Do not discard pages from an in-memory database since we might
  7185   7189         ** need to rollback later.  Just move the page out of the way. */
  7186   7190         sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
  7187   7191       }else{
  7188   7192         sqlite3PcacheDrop(pPgOld);

Changes to src/shell.c.in.

  3380   3380   
  3381   3381         /* echo the sql statement if echo on */
  3382   3382         if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
  3383   3383           utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
  3384   3384         }
  3385   3385   
  3386   3386         /* Show the EXPLAIN QUERY PLAN if .eqp is on */
  3387         -      if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
         3387  +      if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
  3388   3388           sqlite3_stmt *pExplain;
  3389   3389           char *zEQP;
  3390   3390           int triggerEQP = 0;
  3391   3391           disable_debug_trace_modes();
  3392   3392           sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
  3393   3393           if( pArg->autoEQP>=AUTOEQP_trigger ){
  3394   3394             sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
................................................................................
  3429   3429           }
  3430   3430           restore_debug_trace_modes();
  3431   3431         }
  3432   3432   
  3433   3433         if( pArg ){
  3434   3434           pArg->cMode = pArg->mode;
  3435   3435           if( pArg->autoExplain ){
  3436         -          if( sqlite3_column_count(pStmt)==8
  3437         -           && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
  3438         -          ){
         3436  +          if( sqlite3_stmt_isexplain(pStmt)==1 ){
  3439   3437               pArg->cMode = MODE_Explain;
  3440   3438             }
  3441         -          if( sqlite3_column_count(pStmt)==4
  3442         -           && sqlite3_strlike("EXPLAIN QUERY PLAN%", zStmtSql,0)==0 ){
         3439  +          if( sqlite3_stmt_isexplain(pStmt)==2 ){
  3443   3440               pArg->cMode = MODE_EQP;
  3444   3441             }
  3445   3442           }
  3446   3443   
  3447   3444           /* If the shell is currently in ".explain" mode, gather the extra
  3448   3445           ** data required to add indents to the output.*/
  3449   3446           if( pArg->cMode==MODE_Explain ){

Changes to src/sqlite.h.in.

  3892   3892   ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  3893   3893   ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  3894   3894   ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  3895   3895   ** sqlite3_stmt_readonly() returns false for those commands.
  3896   3896   */
  3897   3897   int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3898   3898   
         3899  +/*
         3900  +** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
         3901  +** METHOD: sqlite3_stmt
         3902  +**
         3903  +** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
         3904  +** prepared statement S is an EXPLAIN statement, or 2 if the
         3905  +** statement S is an EXPLAIN QUERY PLAN.
         3906  +** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
         3907  +** an ordinary statement or a NULL pointer.
         3908  +*/
         3909  +int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
         3910  +
  3899   3911   /*
  3900   3912   ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3901   3913   ** METHOD: sqlite3_stmt
  3902   3914   **
  3903   3915   ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3904   3916   ** [prepared statement] S has been stepped at least once using 
  3905   3917   ** [sqlite3_step(S)] but has neither run to completion (returned
................................................................................
  4031   4043   ** the value of the fourth parameter then the resulting string value will
  4032   4044   ** contain embedded NULs.  The result of expressions involving strings
  4033   4045   ** with embedded NULs is undefined.
  4034   4046   **
  4035   4047   ** ^The fifth argument to the BLOB and string binding interfaces
  4036   4048   ** is a destructor used to dispose of the BLOB or
  4037   4049   ** string after SQLite has finished with it.  ^The destructor is called
  4038         -** to dispose of the BLOB or string even if the call to bind API fails.
         4050  +** to dispose of the BLOB or string even if the call to the bind API fails,
         4051  +** except the destructor is not called if the third parameter is a NULL
         4052  +** pointer or the fourth parameter is negative.
  4039   4053   ** ^If the fifth argument is
  4040   4054   ** the special value [SQLITE_STATIC], then SQLite assumes that the
  4041   4055   ** information is in static, unmanaged space and does not need to be freed.
  4042   4056   ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  4043   4057   ** SQLite makes its own private copy of the data immediately, before
  4044   4058   ** the sqlite3_bind_*() routine returns.
  4045   4059   **
................................................................................
  5789   5803   ** CAPI3REF: Return The Filename For A Database Connection
  5790   5804   ** METHOD: sqlite3
  5791   5805   **
  5792   5806   ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  5793   5807   ** associated with database N of connection D.  ^The main database file
  5794   5808   ** has the name "main".  If there is no attached database N on the database
  5795   5809   ** connection D, or if database N is a temporary or in-memory database, then
  5796         -** a NULL pointer is returned.
         5810  +** this function will return either a NULL pointer or an empty string.
  5797   5811   **
  5798   5812   ** ^The filename returned by this function is the output of the
  5799   5813   ** xFullPathname method of the [VFS].  ^In other words, the filename
  5800   5814   ** will be an absolute pathname, even if the filename used
  5801   5815   ** to open the database originally was a URI or relative pathname.
  5802   5816   */
  5803   5817   const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);

Changes to src/test1.c.

  2669   2669     }
  2670   2670   
  2671   2671     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  2672   2672     rc = sqlite3_stmt_readonly(pStmt);
  2673   2673     Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc));
  2674   2674     return TCL_OK;
  2675   2675   }
         2676  +
         2677  +/*
         2678  +** Usage:  sqlite3_stmt_isexplain  STMT
         2679  +**
         2680  +** Return 1, 2, or 0 respectively if STMT is an EXPLAIN statement, an
         2681  +** EXPLAIN QUERY PLAN statement or an ordinary statement or NULL pointer.
         2682  +*/
         2683  +static int SQLITE_TCLAPI test_stmt_isexplain(
         2684  +  void * clientData,
         2685  +  Tcl_Interp *interp,
         2686  +  int objc,
         2687  +  Tcl_Obj *CONST objv[]
         2688  +){
         2689  +  sqlite3_stmt *pStmt;
         2690  +  int rc;
         2691  +
         2692  +  if( objc!=2 ){
         2693  +    Tcl_AppendResult(interp, "wrong # args: should be \"",
         2694  +        Tcl_GetStringFromObj(objv[0], 0), " STMT", 0);
         2695  +    return TCL_ERROR;
         2696  +  }
         2697  +
         2698  +  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
         2699  +  rc = sqlite3_stmt_isexplain(pStmt);
         2700  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
         2701  +  return TCL_OK;
         2702  +}
  2676   2703   
  2677   2704   /*
  2678   2705   ** Usage:  sqlite3_stmt_busy  STMT
  2679   2706   **
  2680   2707   ** Return true if STMT is a non-NULL pointer to a statement
  2681   2708   ** that has been stepped but not to completion.
  2682   2709   */
................................................................................
  7836   7863        { "sqlite3_sql",                   test_sql           ,0 },
  7837   7864        { "sqlite3_expanded_sql",          test_ex_sql        ,0 },
  7838   7865   #ifdef SQLITE_ENABLE_NORMALIZE
  7839   7866        { "sqlite3_normalized_sql",        test_norm_sql      ,0 },
  7840   7867   #endif
  7841   7868        { "sqlite3_next_stmt",             test_next_stmt     ,0 },
  7842   7869        { "sqlite3_stmt_readonly",         test_stmt_readonly ,0 },
         7870  +     { "sqlite3_stmt_isexplain",        test_stmt_isexplain,0 },
  7843   7871        { "sqlite3_stmt_busy",             test_stmt_busy     ,0 },
  7844   7872        { "uses_stmt_journal",             uses_stmt_journal ,0 },
  7845   7873   
  7846   7874        { "sqlite3_release_memory",        test_release_memory,     0},
  7847   7875        { "sqlite3_db_release_memory",     test_db_release_memory,  0},
  7848   7876        { "sqlite3_db_cacheflush",         test_db_cacheflush,      0},
  7849   7877        { "sqlite3_system_errno",          test_system_errno,       0},

Changes to src/vacuum.c.

   140    140   /*
   141    141   ** This routine implements the OP_Vacuum opcode of the VDBE.
   142    142   */
   143    143   int sqlite3RunVacuum(
   144    144     char **pzErrMsg,        /* Write error message here */
   145    145     sqlite3 *db,            /* Database connection */
   146    146     int iDb,                /* Which attached DB to vacuum */
   147         -  sqlite3_value *pOut     /* Write results here, if not NULL */
          147  +  sqlite3_value *pOut     /* Write results here, if not NULL. VACUUM INTO */
   148    148   ){
   149    149     int rc = SQLITE_OK;     /* Return code from service routines */
   150    150     Btree *pMain;           /* The database being vacuumed */
   151    151     Btree *pTemp;           /* The temporary database we vacuum into */
   152    152     u32 saved_mDbFlags;     /* Saved value of db->mDbFlags */
   153    153     u64 saved_flags;        /* Saved value of db->flags */
   154    154     int saved_nChange;      /* Saved value of db->nChange */
   155    155     int saved_nTotalChange; /* Saved value of db->nTotalChange */
          156  +  u32 saved_openFlags;    /* Saved value of db->openFlags */
   156    157     u8 saved_mTrace;        /* Saved trace settings */
   157    158     Db *pDb = 0;            /* Database to detach at end of vacuum */
   158    159     int isMemDb;            /* True if vacuuming a :memory: database */
   159    160     int nRes;               /* Bytes of reserved space at the end of each page */
   160    161     int nDb;                /* Number of attached databases */
   161    162     const char *zDbMain;    /* Schema name of database to vacuum */
   162    163     const char *zOut;       /* Name of output file */
................................................................................
   165    166       sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
   166    167       return SQLITE_ERROR;
   167    168     }
   168    169     if( db->nVdbeActive>1 ){
   169    170       sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
   170    171       return SQLITE_ERROR;
   171    172     }
          173  +  saved_openFlags = db->openFlags;
   172    174     if( pOut ){
   173    175       if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
   174    176         sqlite3SetString(pzErrMsg, db, "non-text filename");
   175    177         return SQLITE_ERROR;
   176    178       }
   177    179       zOut = (const char*)sqlite3_value_text(pOut);
          180  +    db->openFlags &= ~SQLITE_OPEN_READONLY;
          181  +    db->openFlags |= SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE;
   178    182     }else{
   179    183       zOut = "";
   180    184     }
   181    185   
   182    186     /* Save the current value of the database flags so that it can be 
   183    187     ** restored before returning. Then set the writable-schema flag, and
   184    188     ** disable CHECK and foreign key constraints.  */
................................................................................
   209    213     ** actually occurs when doing a vacuum since the vacuum_db is initially
   210    214     ** empty.  Only the journal header is written.  Apparently it takes more
   211    215     ** time to parse and run the PRAGMA to turn journalling off than it does
   212    216     ** to write the journal header file.
   213    217     */
   214    218     nDb = db->nDb;
   215    219     rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
          220  +  db->openFlags = saved_openFlags;
   216    221     if( rc!=SQLITE_OK ) goto end_of_vacuum;
   217    222     assert( (db->nDb-1)==nDb );
   218    223     pDb = &db->aDb[nDb];
   219    224     assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
   220    225     pTemp = pDb->pBt;
   221    226     if( pOut ){
   222    227       sqlite3_file *id = sqlite3PagerFile(sqlite3BtreePager(pTemp));

Changes to src/vdbeapi.c.

  1603   1603   /*
  1604   1604   ** Return true if the prepared statement is guaranteed to not modify the
  1605   1605   ** database.
  1606   1606   */
  1607   1607   int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
  1608   1608     return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
  1609   1609   }
         1610  +
         1611  +/*
         1612  +** Return 1 if the statement is an EXPLAIN and return 2 if the
         1613  +** statement is an EXPLAIN QUERY PLAN
         1614  +*/
         1615  +int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
         1616  +  return pStmt ? ((Vdbe*)pStmt)->explain : 0;
         1617  +}
  1610   1618   
  1611   1619   /*
  1612   1620   ** Return true if the prepared statement is in need of being reset.
  1613   1621   */
  1614   1622   int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
  1615   1623     Vdbe *v = (Vdbe*)pStmt;
  1616   1624     return v!=0 && v->magic==VDBE_MAGIC_RUN && v->pc>=0;

Changes to src/vdbeaux.c.

   635    635     memset(&sIter, 0, sizeof(sIter));
   636    636     sIter.v = v;
   637    637   
   638    638     while( (pOp = opIterNext(&sIter))!=0 ){
   639    639       int opcode = pOp->opcode;
   640    640       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
   641    641        || opcode==OP_VDestroy
          642  +     || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
   642    643        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   643    644         && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
   644    645       ){
   645    646         hasAbort = 1;
   646    647         break;
   647    648       }
   648    649       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;

Changes to src/wherecode.c.

  1156   1156       sqlite3WalkExpr(&w, pWInfo->pWhere);
  1157   1157       sqlite3WalkExprList(&w, pWInfo->pOrderBy);
  1158   1158       sqlite3WalkExprList(&w, pWInfo->pResultSet);
  1159   1159     }
  1160   1160   }
  1161   1161   
  1162   1162   /*
  1163         -** The pTruth expression is always tree because it is the WHERE clause
         1163  +** The pTruth expression is always true because it is the WHERE clause
  1164   1164   ** a partial index that is driving a query loop.  Look through all of the
  1165   1165   ** WHERE clause terms on the query, and if any of those terms must be
  1166   1166   ** true because pTruth is true, then mark those WHERE clause terms as
  1167   1167   ** coded.
  1168   1168   */
  1169   1169   static void whereApplyPartialIndexConstraints(
  1170   1170     Expr *pTruth,

Changes to src/whereexpr.c.

  1516   1516       assert( p->x.pList==0 );
  1517   1517     }else if( ExprHasProperty(p, EP_xIsSelect) ){
  1518   1518       if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
  1519   1519       mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
  1520   1520     }else if( p->x.pList ){
  1521   1521       mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
  1522   1522     }
         1523  +#ifndef SQLITE_OMIT_WINDOWFUNC
         1524  +  if( p->op==TK_FUNCTION && p->y.pWin ){
         1525  +    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
         1526  +    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
         1527  +  }
         1528  +#endif
  1523   1529     return mask;
  1524   1530   }
  1525   1531   Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
  1526   1532     return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
  1527   1533   }
  1528   1534   Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
  1529   1535     int i;

Changes to test/altertab3.test.

    77     77     ALTER TABLE t1 RENAME b TO bbb;
    78     78   }
    79     79   
    80     80   do_execsql_test 3.2 {
    81     81     SELECT sql FROM sqlite_master WHERE name = 'v1'
    82     82   } {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (bbb IN ())}}
    83     83   
           84  +#-------------------------------------------------------------------------
           85  +reset_db
           86  +do_execsql_test 4.0 {
           87  +  CREATE TABLE t1(a, b);
           88  +  CREATE TABLE t3(e, f);
           89  +  CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
           90  +    INSERT INTO t2 VALUES(new.a, new.b);
           91  +  END;
           92  +}
           93  +
           94  +do_catchsql_test 4.1.2 {
           95  +  BEGIN;
           96  +    ALTER TABLE t3 RENAME TO t4;
           97  +} {1 {error in trigger tr1: no such table: main.t2}}
           98  +do_execsql_test 4.1.2 {
           99  +  COMMIT;
          100  +}
          101  +do_execsql_test 4.1.3 {
          102  +  SELECT * FROM sqlite_master WHERE type='table' AND name!='t1';
          103  +} {table t3 t3 3 {CREATE TABLE t3(e, f)}}
          104  +
    84    105   
          106  +do_catchsql_test 4.2.1 {
          107  +  BEGIN;
          108  +    ALTER TABLE t3 RENAME e TO eee;
          109  +} {1 {error in trigger tr1: no such table: main.t2}}
          110  +do_execsql_test 4.2.2 {
          111  +  COMMIT;
          112  +}
          113  +do_execsql_test 4.2.3 {
          114  +  SELECT * FROM sqlite_master WHERE type='table' AND name!='t1';
          115  +} {table t3 t3 3 {CREATE TABLE t3(e, f)}}
    85    116   
    86    117   finish_test
    87    118   
    88    119   

Changes to test/capi3d.test.

   111    111   ifcapable wal {
   112    112     test_is_readonly capi3d-2.6 {PRAGMA journal_mode=WAL} 0
   113    113     test_is_readonly capi3d-2.7 {PRAGMA wal_checkpoint} 0
   114    114   }
   115    115   test_is_readonly capi3d-2.8 {PRAGMA application_id=1234} 0
   116    116   test_is_readonly capi3d-2.9 {VACUUM} 0
   117    117   test_is_readonly capi3d-2.10 {PRAGMA integrity_check} 1
   118         -do_test capi3-2.99 {
          118  +do_test capi3-2.49 {
   119    119     sqlite3_stmt_readonly 0
   120    120   } 1
   121    121   
          122  +
          123  +# Tests for the is-explain interface.
          124  +#
          125  +proc test_is_explain {testname sql truth} {
          126  +  do_test $testname [format {
          127  +    set DB [sqlite3_connection_pointer db]
          128  +    set STMT [sqlite3_prepare $DB {%s} -1 TAIL]
          129  +    set rc [sqlite3_stmt_isexplain $STMT]
          130  +    sqlite3_finalize $STMT
          131  +    set rc
          132  +  } $sql] $truth
          133  +}
          134  +
          135  +test_is_explain capi3d-2.51 {SELECT * FROM sqlite_master} 0
          136  +test_is_explain capi3d-2.52 { explain SELECT * FROM sqlite_master} 1
          137  +test_is_explain capi3d-2.53 {  Explain Query Plan select * FROM sqlite_master} 2
          138  +do_test capi3-2.99 {
          139  +  sqlite3_stmt_isexplain 0
          140  +} 0
          141  +
   122    142   # Tests for sqlite3_stmt_busy
   123    143   #
   124    144   do_test capi3d-3.1 {
   125    145     db eval {INSERT INTO t1 VALUES(6); INSERT INTO t1 VALUES(7);}
   126    146     set STMT [sqlite3_prepare db {SELECT * FROM t1} -1 TAIL]
   127    147     sqlite3_stmt_busy $STMT
   128    148   } {0}

Changes to test/corruptL.test.

   119    119   |   2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00   ................
   120    120   | end crash-acaae0347204ae.db
   121    121   }]} {}
   122    122   
   123    123   do_catchsql_test 1.1 {
   124    124     PRAGMA cell_size_check = off;
   125    125     DROP INDEX t1x1;
   126         -} {1 {no such index: t1x1}}
          126  +} {1 {database disk image is malformed}}
   127    127   
   128    128   do_catchsql_test 1.2 {
   129    129     SELECT sum(s+length(b)) FROM t1 WHERE a IN (110,10,150) AND q IS NULL;
   130         -} {1 {no such table: t1}}
          130  +} {1 {database disk image is malformed}}
   131    131   
   132    132   do_catchsql_test 1.3 {
   133    133     REINDEX t1;
   134         -} {1 {unable to identify the object to be reindexed}}
          134  +} {1 {database disk image is malformed}}
          135  +
          136  +do_catchsql_test 1.4 {
          137  +  PRAGMA integrity_check
          138  +} {1 {database disk image is malformed}}
          139  +
   135    140   
   136    141   #-------------------------------------------------------------------------
   137    142   reset_db
   138    143   do_test 2.0 {
   139    144     sqlite3 db {}
   140    145     db deserialize [decode_hexdb {
   141    146   | size 20480 pagesize 4096 filename crash.txt.db

Changes to test/fts3corrupt4.test.

  3692   3692   | end crash-b794c89d922ac9.db
  3693   3693   }]} {}
  3694   3694   
  3695   3695   do_catchsql_test 22.1 {
  3696   3696     SELECT snippet(t1,'', '', '--',-1,01)==0
  3697   3697       FROM t1 WHERE a MATCH 'rtree OR json1rtree OR json1';
  3698   3698   } {0 {0 0 0 0 0 0 0}}
         3699  +
         3700  +#-------------------------------------------------------------------------
         3701  +reset_db
         3702  +do_test 23.0 {
         3703  +  sqlite3 db {}
         3704  +  db deserialize [decode_hexdb {
         3705  +.open --hexdb
         3706  +| size 28672 pagesize 4096 filename crash-670b15f2955a36.db
         3707  +| page 1 offset 0
         3708  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         3709  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         3710  +|     32: 00 00 00 02 10 00 00 01 00 00 00 07 00 00 00 00   ................
         3711  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         3712  +|    112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00   .....~..........
         3713  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         3714  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         3715  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         3716  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72   .5tablet1_segdir
         3717  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         3718  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         3719  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52   r'(level INTEGER
         3720  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         3721  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         3722  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         3723  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         3724  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74   ock INTEGER,root
         3725  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         3726  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         3727  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         3728  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         3729  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         3730  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         3731  +|   3776: 81 13 74 61 62 6c 75 74 31 5f 73 65 67 6d 65 6e   ..tablut1_segmen
         3732  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         3733  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         3734  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         3735  +|   3840: 20 49 4e 54 45 47 45 42 20 50 52 49 4d 41 52 59    INTEGEB PRIMARY
         3736  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         3737  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         3738  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         3739  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         3740  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         3741  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         3742  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         3743  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         3744  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         3745  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         3746  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         3747  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00   (a,b,c).........
         3748  +| page 3 offset 8192
         3749  +|      0: 0d 00 00 00 25 0b 48 01 0f d8 00 2f 0f 86 0f 74   ....%.H..../...t
         3750  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         3751  +|     32: 0e 8d 0e 74 0e 5a fe 40 0e 24 0e 08 0d ef 0d d5   ...t.Z.@.$......
         3752  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 81 35 0d 1b 0c fb   .......h.O.5....
         3753  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 00 00 00 00   .......x.W.>....
         3754  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 10   .........?%.....
         3755  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         3756  +|   2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42   4.0 20160609 DEB
         3757  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         3758  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53    VTAB ENABLE FTS
         3759  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         3760  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41   ABLE GEOPOLY ENA
         3761  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         3762  +|   3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20    MEMSYS5 ENABLE 
         3763  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         3764  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         3765  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48   OAD EXTENSION TH
         3766  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 35 0f   READSAFE=0.$..5.
         3767  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         3768  +|   3104: 4e 41 52 59 18 23 55 00 25 0f 19 54 48 52 45 41   NARY.#U.%..THREA
         3769  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         3770  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         3771  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         3772  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         3773  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         3774  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         3775  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         3776  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         3777  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         3778  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         3779  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         3780  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         3781  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         3782  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         3783  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         3784  +|   3360: 0f 19 45 4e 41 42 4c 44 20 52 54 52 45 45 58 42   ..ENABLD RTREEXB
         3785  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         3786  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         3787  +|   3408: 19 05 00 24 0f 17 45 4e 40 42 4c 45 20 52 54 52   ...$..EN@BLE RTR
         3788  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         3789  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         3790  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4d 41 42 4c   NARY....)..EMABL
         3791  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 4c 45   E MEMSYS5XNOCALE
         3792  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         3793  +|   3504: 4e 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   NSYS5XRTRIM....%
         3794  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         3795  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         3796  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         3797  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         3798  +|   3584: 4e 31 58 52 54 5f b9 4d 1a 12 05 00 29 0f 19 45   N1XRT_.M....)..E
         3799  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 31 4c 59 58 42 49   NABLE GEOP1LYXBI
         3800  +|   3616: 4e 41 52 58 1a 11 05 00 29 0f 19 45 4e 41 42 4c   NARX....)..ENABL
         3801  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         3802  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 57 45   ....)..ENABLE WE
         3803  +|   3664: 4f 50 4f 4c 59 48 52 54 52 49 4d 17 0f 05 00 23   OPOLYHRTRIM....#
         3804  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         3805  +|   3696: 4e 41 53 59 17 0e 05 00 23 0f 19 45 4e 40 42 4b   NASY....#..EN@BK
         3806  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         3807  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         3808  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         3809  +|   3760: 4c 45 20 46 54 94 34 58 42 49 4e 41 52 59 17 0b   LE FT.4XBINARY..
         3810  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 43 70 46 54 53 34   ..#..ENABLCpFTS4
         3811  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         3812  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         3813  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3814  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         3815  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 32 53   ...1..ENABLE D2S
         3816  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         3817  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3818  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         3819  +|   3920: 05 0b 27 0f 19 44 45 42 55 47 58 42 49 4e 41 52   ..'..DEBUGXBINAR
         3820  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         3821  +|   3952: 43 41 53 45 10 03 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         3822  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         3823  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         3824  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         3825  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 35 52 3d 67   ...C..COMPIL5R=g
         3826  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         3827  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 02 43   9XNOCASE&...C..C
         3828  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         3829  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 00 00 00 00 00   0 20160609X.....
         3830  +| page 5 offset 16384
         3831  +|      0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00   ................
         3832  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33   ...........0 253
         3833  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         3834  +|   3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35   09.%....4.%....5
         3835  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 08 55 1a   .%....0000000.U.
         3836  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         3837  +|   3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 61 75   .dbstat.%....eau
         3838  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         3839  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         3840  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         3841  +|   3120: 01 35 03 25 0f 00 00 0c 97 63 63 03 25 03 00 01   .5.%.....cc.%...
         3842  +|   3136: 06 65 6f 70 6f 6c 7a 03 25 11 00 00 05 6a 73 6f   .eopolz.%....jso
         3843  +|   3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00   n1.%....load.%..
         3844  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         3845  +|   3184: 03 25 3d f0 03 04 73 79 73 35 03 25 15 00 00 04   .%=...sys5.%....
         3846  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         3847  +|   3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03   %....threadsafe.
         3848  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         3849  +|   3248: 08 08 08 09 08 17 8d 12 30 20 38 33 37 e3 aa e0   ........0 837...
         3850  +|   3264: 12 d1 06 00 01 06 00 01 06 00 1f 03 00 01 03 00   ................
         3851  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 49 09 01 07   .....2016060I...
         3852  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         3853  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         3854  +|   3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04   ...0000000......
         3855  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02   ......binary<...
         3856  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3857  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         3858  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         3859  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         3860  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         3861  +|   3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01   bstat...........
         3862  +|   3456: 04 65 62 75 67 09 04 01 f0 01 02 00 01 02 00 00   .ebug...........
         3863  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02   .enable?........
         3864  +|   3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00   ................
         3865  +|   3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01   ................
         3866  +|   3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         3867  +|   3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         3868  +|   3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73   n............fts
         3869  +|   3568: 34 09 0a 03 f3 01 03 00 01 03 00 19 01 35 09 0d   4............5..
         3870  +|   3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03   ..........gcc...
         3871  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         3872  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         3873  +|   3632: 09 13 03 00 01 03 00 00 f3 00 00 04 6c 6f 61 64   ............load
         3874  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         3875  +|   3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79   ...........emory
         3876  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         3877  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         3878  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         3879  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3880  +|   3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         3881  +|   3760: 03 01 02 02 00 03 01 02 02 00 46 01 02 02 00 00   ..........F.....
         3882  +|   3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00   .omit...........
         3883  +|   3792: 05 72 74 72 64 65 09 19 03 00 01 03 00 01 03 00   .rtrde..........
         3884  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         3885  +|   3824: 01 02 02 00 03 01 02 01 ff 03 01 02 02 00 03 01   ................
         3886  +|   3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         3887  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3888  +|   3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02   ...threadsafe...
         3889  +|   3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         3890  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02   .........x......
         3891  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3892  +|   3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         3893  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         3894  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         3895  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         3896  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3897  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         3898  +|   4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         3899  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         3900  +|   4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 02 02   ................
         3901  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3902  +| page 6 offset 20480
         3903  +|      0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00   ................
         3904  +|   4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 09 09   ................
         3905  +| page 7 offset 24576
         3906  +|      0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         3907  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
         3908  +|   4032: 6d 65 71 97 65 3d 35 0d 04 02 23 6d 65 72 67 65   meq.e=5...#merge
         3909  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
         3910  +|   4064: 69 74 79 00 00 00 00 00 00 00 00 00 00 00 00 00   ity.............
         3911  +| end crash-670b15f2955a36.db
         3912  +}]} {}
         3913  +
         3914  +do_catchsql_test 23.1 {
         3915  +  SELECT 'FyzLy'FROM t1 WHERE t1 MATCH 'j';
         3916  +} {1 {database disk image is malformed}}
  3699   3917   
  3700   3918   finish_test
  3701   3919   

Changes to test/fuzzcheck.c.

   527    527     if( nIn<4 ) return -1;
   528    528     n = (unsigned int)nIn;
   529    529     a = sqlite3_malloc64( nAlloc );
   530    530     if( a==0 ){
   531    531       fprintf(stderr, "Out of memory!\n");
   532    532       exit(1);
   533    533     }
   534         -  memset(a, 0, nAlloc);
          534  +  memset(a, 0, (size_t)nAlloc);
   535    535     for(i=k=0; i<n; i++){
   536    536       unsigned char c = (unsigned char)zIn[i];
   537    537       if( isxdigit(c) ){
   538    538         k++;
   539    539         if( k & 1 ){
   540    540           b = hexToInt(c)*16;
   541    541         }else{
................................................................................
   564    564             }
   565    565             a = sqlite3_realloc64( a, newSize );
   566    566             if( a==0 ){
   567    567               fprintf(stderr, "Out of memory!\n");
   568    568               exit(1);
   569    569             }
   570    570             assert( newSize > nAlloc );
   571         -          memset(a+nAlloc, 0, newSize - nAlloc);
          571  +          memset(a+nAlloc, 0, (size_t)(newSize - nAlloc));
   572    572             nAlloc = newSize;
   573    573           }
   574    574           if( j>=(unsigned)mx ){
   575    575             mx = (j + 4095)&~4095;
   576    576             if( mx>MX_FILE_SZ ) mx = MX_FILE_SZ;
   577    577           }
   578    578           assert( j<nAlloc );

Changes to test/fuzzdata7.db.

cannot compute difference between binary files

Changes to test/fuzzdata8.db.

cannot compute difference between binary files

Changes to test/memdb1.test.

   180    180     set rc [catch {db deserialize a b c} msg]
   181    181     lappend rc $msg
   182    182   } {1 {unknown option: a}}
   183    183   do_test 620 {
   184    184     set rc [catch {db serialize a b} msg]
   185    185     lappend rc $msg
   186    186   } {1 {wrong # args: should be "db serialize ?DATABASE?"}}
          187  +
          188  +#-------------------------------------------------------------------------
          189  +reset_db
          190  +do_execsql_test 700 {
          191  +  CREATE TABLE t1(a, b);
          192  +  PRAGMA schema_version = 0;
          193  +}
          194  +do_test 710 {
          195  +  set ser [db serialize main]
          196  +  db close
          197  +  sqlite3 db
          198  +  db deserialize main $ser
          199  +  catchsql {
          200  +    CREATE VIRTUAL TABLE t1 USING rtree(id, a, b, c, d);
          201  +  }
          202  +} {1 {table t1 already exists}}
   187    203   
   188    204   finish_test

Changes to test/sessionfuzz.c.

   826    826   static int conflictCall(
   827    827     void *NotUsed,
   828    828     int eConflict,
   829    829     sqlite3_changeset_iter *p
   830    830   ){
   831    831     (void)NotUsed;
   832    832     (void)p;
   833         -  printf("Conflict %d\n", eConflict);
   834    833     return SQLITE_CHANGESET_OMIT;
   835    834   }
   836    835   
   837    836   /*
   838    837   ** Reset the database file
   839    838   */
   840    839   static void db_reset(sqlite3 *db){

Changes to test/vacuum-into.test.

    82     82     execsql { VACUUM INTO target() }
    83     83     file exists test.db2
    84     84   } 1
    85     85   do_catchsql_test vacuum-into-420 {
    86     86     VACUUM INTO target2()
    87     87   } {1 {no such function: target2}}
    88     88   
           89  +# The ability to VACUUM INTO a read-only database
           90  +db close
           91  +sqlite3 db test.db -readonly 1
           92  +forcedelete test.db2
           93  +do_execsql_test vacuum-into-500 {
           94  +  VACUUM INTO 'test.db2';
           95  +}
           96  +sqlite3 db2 test.db2
           97  +do_test vacuum-into-510 {
           98  +  db2 eval {SELECT name FROM sqlite_master ORDER BY 1}
           99  +} {t1 t1b t2}
          100  +db2 close
          101  +db close
    89    102   
    90    103   finish_test

Changes to test/window1.test.

   715    715   } {6 6 6}
   716    716   
   717    717   do_execsql_test 17.3 {
   718    718     SELECT 10+sum(a) OVER (ORDER BY a) 
   719    719     FROM t8 
   720    720     ORDER BY 10+sum(a) OVER (ORDER BY a) DESC;
   721    721   } {16 13 11}
          722  +
          723  +#-------------------------------------------------------------------------
          724  +#
          725  +reset_db
          726  +do_execsql_test 18.0 {
          727  +  CREATE TABLE t1 ( t1_id INTEGER PRIMARY KEY );
          728  +  CREATE TABLE t2 ( t2_id INTEGER PRIMARY KEY );
          729  +  CREATE TABLE t3 ( t3_id INTEGER PRIMARY KEY );
          730  +
          731  +  INSERT INTO t1 VALUES(1),  (3), (5);
          732  +  INSERT INTO t2 VALUES      (3), (5);
          733  +  INSERT INTO t3 VALUES(10), (11), (12);
          734  +}
          735  +
          736  +do_execsql_test 18.1 {
          737  +  SELECT t1.* FROM t1, t2 WHERE 
          738  +    t1_id=t2_id AND t1_id IN (
          739  +        SELECT t1_id + row_number() OVER ( ORDER BY t1_id ) FROM t3
          740  +    )
          741  +}
          742  +
          743  +do_execsql_test 18.2 {
          744  +  SELECT t1.* FROM t1, t2 WHERE 
          745  +    t1_id=t2_id AND t1_id IN (
          746  +        SELECT         row_number() OVER ( ORDER BY t1_id ) FROM t3
          747  +    )
          748  +} {3}
   722    749   
   723    750   
   724    751   finish_test

Changes to tool/cg_anno.tcl.

     1      1   #!/bin/sh
     2      2   # \
     3         -exec tclsh  "$0" ${1+"$@"}
            3  +exec tclsh "$0" ${1+"$@"}
            4  +#
     4      5   # A wrapper around cg_annotate that sets appropriate command-line options
     5      6   # and rearranges the output so that annotated files occur in a consistent
     6      7   # sorted order.  Used by the speed-check.tcl script.
     7      8   #
     8      9   
     9     10   set in [open "|cg_annotate --show=Ir --auto=yes --context=40 $argv" r]
    10     11   set dest !

Added tool/extract-sqlite3h.tcl.

            1  +#!/usr/bin/tclsh
            2  +#
            3  +# Given an sqlite3.c source file identified by the command-line
            4  +# argument, extract the "sqlite3.h" header file that is embedded inside
            5  +# the sqlite3.c source file and write it to standard output.
            6  +#
            7  +if {[llength $argv]!=1} {
            8  +  puts stderr "Usage: $argv0 sqlite3.c >sqlite3.h"
            9  +  exit 1
           10  +}
           11  +set in [open [lindex $argv 0] rb]
           12  +while {![eof $in]} {
           13  +  set line [gets $in]
           14  +  if {[string match {* Begin file sqlite3.h *} $line]} break
           15  +}
           16  +while {![eof $in]} {
           17  +  set line [gets $in]
           18  +  if {[string match {* End of sqlite3.h *} $line]} break
           19  +  puts $line
           20  +}
           21  +close $in

Changes to tool/showdb.c.

   824    824     }
   825    825     if( nLocal<nPayload ){
   826    826       int ovfl = decodeInt32(a+nLocal);
   827    827       int cnt = 0;
   828    828       while( ovfl && (cnt++)<g.mxPage ){
   829    829         page_usage_msg(ovfl, "overflow %d from cell %d of page %d",
   830    830                        cnt, cellno, pgno);
   831         -      a = fileRead((ovfl-1)*g.pagesize, 4);
          831  +      a = fileRead((ovfl-1)*(sqlite3_int64)g.pagesize, 4);
   832    832         ovfl = decodeInt32(a);
   833    833         sqlite3_free(a);
   834    834       }
   835    835     }
   836    836   }
   837    837   
   838    838