Wapp

Check-in [482776f0ef]
Login

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

Overview
Comment:Update the built-in SQLite to the 3.28.0 beta.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 482776f0ef54220cb70dcf1bb8af5050ec1fd85d84af05a957ce440788df8cb0
User & Date: drh 2019-04-15 19:00:02
Context
2019-04-23
18:04
Fix a typo in the quickref.md document. check-in: 713d5e77fc user: drh tags: trunk
2019-04-15
19:00
Update the built-in SQLite to the 3.28.0 beta. check-in: 482776f0ef user: drh tags: trunk
2019-04-10
15:22
Improved JSON string literal encoding. check-in: 4b187296d9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tclsqlite3.c.

  1161   1161   **
  1162   1162   ** See also: [sqlite3_libversion()],
  1163   1163   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  1164   1164   ** [sqlite_version()] and [sqlite_source_id()].
  1165   1165   */
  1166   1166   #define SQLITE_VERSION        "3.28.0"
  1167   1167   #define SQLITE_VERSION_NUMBER 3028000
  1168         -#define SQLITE_SOURCE_ID      "2019-04-09 01:26:31 8820408597341344b308277ce6ef41b47c7514d6c613520789b05ee52cbedae8"
         1168  +#define SQLITE_SOURCE_ID      "2019-04-15 15:41:33 09fa0b3c4adf7f81a777975762029ad43dbdc76b02dc32d2307e1c42465213c9"
  1169   1169   
  1170   1170   /*
  1171   1171   ** CAPI3REF: Run-Time Library Version Numbers
  1172   1172   ** KEYWORDS: sqlite3_version sqlite3_sourceid
  1173   1173   **
  1174   1174   ** These interfaces provide the same information as the [SQLITE_VERSION],
  1175   1175   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
 13415  13415   ** the hash table.
 13416  13416   */
 13417  13417   struct Hash {
 13418  13418     unsigned int htsize;      /* Number of buckets in the hash table */
 13419  13419     unsigned int count;       /* Number of entries in this table */
 13420  13420     HashElem *first;          /* The first element of the array */
 13421  13421     struct _ht {              /* the hash table */
 13422         -    int count;                 /* Number of entries with this hash */
        13422  +    unsigned int count;        /* Number of entries with this hash */
 13423  13423       HashElem *chain;           /* Pointer to first entry with this hash */
 13424  13424     } *ht;
 13425  13425   };
 13426  13426   
 13427  13427   /* Each element in the hash table is an instance of the following 
 13428  13428   ** structure.  All elements are stored on a single doubly-linked list.
 13429  13429   **
................................................................................
 18754  18754   SQLITE_PRIVATE   void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8);
 18755  18755   #endif
 18756  18756   #endif
 18757  18757   
 18758  18758   
 18759  18759   SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
 18760  18760   SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
        18761  +SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
 18761  18762   SQLITE_PRIVATE void sqlite3Dequote(char*);
 18762  18763   SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
 18763  18764   SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
 18764  18765   SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
 18765  18766   SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
 18766  18767   SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
 18767  18768   SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
................................................................................
 27365  27366   /*
 27366  27367   ** Set the StrAccum object to an error mode.
 27367  27368   */
 27368  27369   static void setStrAccumError(StrAccum *p, u8 eError){
 27369  27370     assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
 27370  27371     p->accError = eError;
 27371  27372     if( p->mxAlloc ) sqlite3_str_reset(p);
        27373  +  if( eError==SQLITE_TOOBIG ) sqlite3ErrorToParser(p->db, eError);
 27372  27374   }
 27373  27375   
 27374  27376   /*
 27375  27377   ** Extra argument values from a PrintfArguments object
 27376  27378   */
 27377  27379   static sqlite3_int64 getIntArg(PrintfArguments *p){
 27378  27380     if( p->nArg<=p->nUsed ) return 0;
................................................................................
 29855  29857   #ifndef SQLITE_OMIT_UTF16
 29856  29858   /*
 29857  29859   ** This routine transforms the internal text encoding used by pMem to
 29858  29860   ** desiredEnc. It is an error if the string is already of the desired
 29859  29861   ** encoding, or if *pMem does not contain a string value.
 29860  29862   */
 29861  29863   SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
 29862         -  int len;                    /* Maximum length of output string in bytes */
 29863         -  unsigned char *zOut;                  /* Output buffer */
 29864         -  unsigned char *zIn;                   /* Input iterator */
 29865         -  unsigned char *zTerm;                 /* End of input */
 29866         -  unsigned char *z;                     /* Output iterator */
        29864  +  sqlite3_int64 len;          /* Maximum length of output string in bytes */
        29865  +  unsigned char *zOut;        /* Output buffer */
        29866  +  unsigned char *zIn;         /* Input iterator */
        29867  +  unsigned char *zTerm;       /* End of input */
        29868  +  unsigned char *z;           /* Output iterator */
 29867  29869     unsigned int c;
 29868  29870   
 29869  29871     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 29870  29872     assert( pMem->flags&MEM_Str );
 29871  29873     assert( pMem->enc!=desiredEnc );
 29872  29874     assert( pMem->enc!=0 );
 29873  29875     assert( pMem->n>=0 );
................................................................................
 29908  29910     if( desiredEnc==SQLITE_UTF8 ){
 29909  29911       /* When converting from UTF-16, the maximum growth results from
 29910  29912       ** translating a 2-byte character to a 4-byte UTF-8 character.
 29911  29913       ** A single byte is required for the output string
 29912  29914       ** nul-terminator.
 29913  29915       */
 29914  29916       pMem->n &= ~1;
 29915         -    len = pMem->n * 2 + 1;
        29917  +    len = 2 * (sqlite3_int64)pMem->n + 1;
 29916  29918     }else{
 29917  29919       /* When converting from UTF-8 to UTF-16 the maximum growth is caused
 29918  29920       ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
 29919  29921       ** character. Two bytes are required in the output buffer for the
 29920  29922       ** nul-terminator.
 29921  29923       */
 29922         -    len = pMem->n * 2 + 2;
        29924  +    len = 2 * (sqlite3_int64)pMem->n + 2;
 29923  29925     }
 29924  29926   
 29925  29927     /* Set zIn to point at the start of the input buffer and zTerm to point 1
 29926  29928     ** byte past the end.
 29927  29929     **
 29928  29930     ** Variable zOut is set to point at the output buffer, space obtained
 29929  29931     ** from sqlite3_malloc().
................................................................................
 30422  30424     }else{
 30423  30425       pParse->nErr++;
 30424  30426       sqlite3DbFree(db, pParse->zErrMsg);
 30425  30427       pParse->zErrMsg = zMsg;
 30426  30428       pParse->rc = SQLITE_ERROR;
 30427  30429     }
 30428  30430   }
        30431  +
        30432  +/*
        30433  +** If database connection db is currently parsing SQL, then transfer
        30434  +** error code errCode to that parser if the parser has not already
        30435  +** encountered some other kind of error.
        30436  +*/
        30437  +SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3 *db, int errCode){
        30438  +  Parse *pParse;
        30439  +  if( db==0 || (pParse = db->pParse)==0 ) return errCode;
        30440  +  pParse->rc = errCode;
        30441  +  pParse->nErr++;
        30442  +  return errCode;
        30443  +}
 30429  30444   
 30430  30445   /*
 30431  30446   ** Convert an SQL-style quoted string into a normal string by removing
 30432  30447   ** the quote characters.  The conversion is done in-place.  If the
 30433  30448   ** input does not begin with a quote character, then this routine
 30434  30449   ** is a no-op.
 30435  30450   **
................................................................................
 31774  31789     char *z;               /* Pointer to where zName will be stored */
 31775  31790     int i;                 /* Index in pIn[] where zName is stored */
 31776  31791   
 31777  31792     nInt = nName/4 + 3;
 31778  31793     assert( pIn==0 || pIn[0]>=3 );  /* Verify ok to add new elements */
 31779  31794     if( pIn==0 || pIn[1]+nInt > pIn[0] ){
 31780  31795       /* Enlarge the allocation */
 31781         -    int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
        31796  +    sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt;
 31782  31797       VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
 31783  31798       if( pOut==0 ) return pIn;
 31784  31799       if( pIn==0 ) pOut[1] = 2;
 31785  31800       pIn = pOut;
 31786  31801       pIn[0] = nAlloc;
 31787  31802     }
 31788  31803     i = pIn[1];
................................................................................
 31980  31995   */
 31981  31996   static HashElem *findElementWithHash(
 31982  31997     const Hash *pH,     /* The pH to be searched */
 31983  31998     const char *pKey,   /* The key we are searching for */
 31984  31999     unsigned int *pHash /* Write the hash value here */
 31985  32000   ){
 31986  32001     HashElem *elem;                /* Used to loop thru the element list */
 31987         -  int count;                     /* Number of elements left to test */
        32002  +  unsigned int count;            /* Number of elements left to test */
 31988  32003     unsigned int h;                /* The computed hash */
 31989  32004     static HashElem nullElement = { 0, 0, 0, 0 };
 31990  32005   
 31991  32006     if( pH->ht ){   /*OPTIMIZATION-IF-TRUE*/
 31992  32007       struct _ht *pEntry;
 31993  32008       h = strHash(pKey) % pH->htsize;
 31994  32009       pEntry = &pH->ht[h];
................................................................................
 32028  32043       elem->next->prev = elem->prev;
 32029  32044     }
 32030  32045     if( pH->ht ){
 32031  32046       pEntry = &pH->ht[h];
 32032  32047       if( pEntry->chain==elem ){
 32033  32048         pEntry->chain = elem->next;
 32034  32049       }
        32050  +    assert( pEntry->count>0 );
 32035  32051       pEntry->count--;
 32036         -    assert( pEntry->count>=0 );
 32037  32052     }
 32038  32053     sqlite3_free( elem );
 32039  32054     pH->count--;
 32040  32055     if( pH->count==0 ){
 32041  32056       assert( pH->first==0 );
 32042  32057       assert( pH->count==0 );
 32043  32058       sqlite3HashClear(pH);
................................................................................
 49113  49128   
 49114  49129   /*
 49115  49130   ** Malloc function used by SQLite to obtain space from the buffer configured
 49116  49131   ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
 49117  49132   ** exists, this function falls back to sqlite3Malloc().
 49118  49133   */
 49119  49134   SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
 49120         -  /* During rebalance operations on a corrupt database file, it is sometimes
 49121         -  ** (rarely) possible to overread the temporary page buffer by a few bytes.
 49122         -  ** Enlarge the allocation slightly so that this does not cause problems. */
        49135  +  assert( sz<=65536+8 ); /* These allocations are never very large */
 49123  49136     return pcache1Alloc(sz);
 49124  49137   }
 49125  49138   
 49126  49139   /*
 49127  49140   ** Free an allocated buffer obtained from sqlite3PageMalloc().
 49128  49141   */
 49129  49142   SQLITE_PRIVATE void sqlite3PageFree(void *p){
................................................................................
 58873  58886     int iPage,               /* The page we seek */
 58874  58887     volatile u32 **ppPage    /* Write the page pointer here */
 58875  58888   ){
 58876  58889     int rc = SQLITE_OK;
 58877  58890   
 58878  58891     /* Enlarge the pWal->apWiData[] array if required */
 58879  58892     if( pWal->nWiData<=iPage ){
 58880         -    int nByte = sizeof(u32*)*(iPage+1);
        58893  +    sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
 58881  58894       volatile u32 **apNew;
 58882  58895       apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
 58883  58896       if( !apNew ){
 58884  58897         *ppPage = 0;
 58885  58898         return SQLITE_NOMEM_BKPT;
 58886  58899       }
 58887  58900       memset((void*)&apNew[pWal->nWiData], 0,
................................................................................
 58977  58990       s2 = aIn[1];
 58978  58991     }else{
 58979  58992       s1 = s2 = 0;
 58980  58993     }
 58981  58994   
 58982  58995     assert( nByte>=8 );
 58983  58996     assert( (nByte&0x00000007)==0 );
        58997  +  assert( nByte<=65536 );
 58984  58998   
 58985  58999     if( nativeCksum ){
 58986  59000       do {
 58987  59001         s1 += *aData++ + s2;
 58988  59002         s2 += *aData++ + s1;
 58989  59003       }while( aData<aEnd );
 58990  59004     }else{
................................................................................
 59914  59928   ** The calling routine should invoke walIteratorFree() to destroy the
 59915  59929   ** WalIterator object when it has finished with it.
 59916  59930   */
 59917  59931   static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
 59918  59932     WalIterator *p;                 /* Return value */
 59919  59933     int nSegment;                   /* Number of segments to merge */
 59920  59934     u32 iLast;                      /* Last frame in log */
 59921         -  int nByte;                      /* Number of bytes to allocate */
        59935  +  sqlite3_int64 nByte;            /* Number of bytes to allocate */
 59922  59936     int i;                          /* Iterator variable */
 59923  59937     ht_slot *aTmp;                  /* Temp space used by merge-sort */
 59924  59938     int rc = SQLITE_OK;             /* Return Code */
 59925  59939   
 59926  59940     /* This routine only runs while holding the checkpoint lock. And
 59927  59941     ** it only runs if there is actually content in the log (mxFrame>0).
 59928  59942     */
................................................................................
 74596  74610   SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
 74597  74611     assert( sqlite3VdbeCheckMemInvariants(pMem) );
 74598  74612     assert( !sqlite3VdbeMemIsRowSet(pMem) );
 74599  74613     testcase( pMem->db==0 );
 74600  74614   
 74601  74615     /* If the bPreserve flag is set to true, then the memory cell must already
 74602  74616     ** contain a valid string or blob value.  */
 74603         -  assert( bPreserve==0 
 74604         -       || pMem->flags&(MEM_Blob|MEM_Str)
 74605         -       || MemNullNochng(pMem)
 74606         -  );
        74617  +  assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 74607  74618     testcase( bPreserve && pMem->z==0 );
 74608  74619   
 74609  74620     assert( pMem->szMalloc==0
 74610  74621          || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
 74611  74622     if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
 74612  74623       pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
 74613  74624       bPreserve = 0;
................................................................................
 74713  74724     testcase( sqlite3_value_nochange(pMem) );
 74714  74725     assert( !sqlite3VdbeMemIsRowSet(pMem) );
 74715  74726     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 74716  74727   
 74717  74728     /* Set nByte to the number of bytes required to store the expanded blob. */
 74718  74729     nByte = pMem->n + pMem->u.nZero;
 74719  74730     if( nByte<=0 ){
        74731  +    if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
 74720  74732       nByte = 1;
 74721  74733     }
 74722  74734     if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
 74723  74735       return SQLITE_NOMEM_BKPT;
 74724  74736     }
 74725  74737   
 74726  74738     memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
................................................................................
 75469  75481     */
 75470  75482     if( xDel==SQLITE_TRANSIENT ){
 75471  75483       u32 nAlloc = nByte;
 75472  75484       if( flags&MEM_Term ){
 75473  75485         nAlloc += (enc==SQLITE_UTF8?1:2);
 75474  75486       }
 75475  75487       if( nByte>iLimit ){
 75476         -      return SQLITE_TOOBIG;
        75488  +      return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
 75477  75489       }
 75478  75490       testcase( nAlloc==0 );
 75479  75491       testcase( nAlloc==31 );
 75480  75492       testcase( nAlloc==32 );
 75481  75493       if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
 75482  75494         return SQLITE_NOMEM_BKPT;
 75483  75495       }
................................................................................
 76455  76467     ** more frequent reallocs and hence provide more opportunities for 
 76456  76468     ** simulated OOM faults.  SQLITE_TEST_REALLOC_STRESS is generally used
 76457  76469     ** during testing only.  With SQLITE_TEST_REALLOC_STRESS grow the op array
 76458  76470     ** by the minimum* amount required until the size reaches 512.  Normal
 76459  76471     ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
 76460  76472     ** size of the op array or add 1KB of space, whichever is smaller. */
 76461  76473   #ifdef SQLITE_TEST_REALLOC_STRESS
 76462         -  int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
        76474  +  sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc
        76475  +                        : (sqlite3_int64)v->nOpAlloc+nOp);
 76463  76476   #else
 76464         -  int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
        76477  +  sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc
        76478  +                        : (sqlite3_int64)(1024/sizeof(Op)));
 76465  76479     UNUSED_PARAMETER(nOp);
 76466  76480   #endif
 76467  76481   
 76468  76482     /* Ensure that the size of a VDBE does not grow too large */
 76469  76483     if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
 76470  76484       sqlite3OomFault(p->db);
 76471  76485       return SQLITE_NOMEM;
................................................................................
 77245  77259     Vdbe *p,                        /* VM to add scanstatus() to */
 77246  77260     int addrExplain,                /* Address of OP_Explain (or 0) */
 77247  77261     int addrLoop,                   /* Address of loop counter */ 
 77248  77262     int addrVisit,                  /* Address of rows visited counter */
 77249  77263     LogEst nEst,                    /* Estimated number of output rows */
 77250  77264     const char *zName               /* Name of table or index being scanned */
 77251  77265   ){
 77252         -  int nByte = (p->nScan+1) * sizeof(ScanStatus);
        77266  +  sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
 77253  77267     ScanStatus *aNew;
 77254  77268     aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
 77255  77269     if( aNew ){
 77256  77270       ScanStatus *pNew = &aNew[p->nScan++];
 77257  77271       pNew->addrExplain = addrExplain;
 77258  77272       pNew->addrLoop = addrLoop;
 77259  77273       pNew->addrVisit = addrVisit;
................................................................................
 78366  78380   #endif /* !SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE */
 78367  78381   
 78368  78382   /* An instance of this object describes bulk memory available for use
 78369  78383   ** by subcomponents of a prepared statement.  Space is allocated out
 78370  78384   ** of a ReusableSpace object by the allocSpace() routine below.
 78371  78385   */
 78372  78386   struct ReusableSpace {
 78373         -  u8 *pSpace;          /* Available memory */
 78374         -  int nFree;           /* Bytes of available memory */
 78375         -  int nNeeded;         /* Total bytes that could not be allocated */
        78387  +  u8 *pSpace;            /* Available memory */
        78388  +  sqlite3_int64 nFree;   /* Bytes of available memory */
        78389  +  sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */
 78376  78390   };
 78377  78391   
 78378  78392   /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
 78379  78393   ** from the ReusableSpace object.  Return a pointer to the allocated
 78380  78394   ** memory on success.  If insufficient memory is available in the
 78381  78395   ** ReusableSpace object, increase the ReusableSpace.nNeeded
 78382  78396   ** value by the amount needed and return NULL.
................................................................................
 78388  78402   ** This allocator is employed to repurpose unused slots at the end of the
 78389  78403   ** opcode array of prepared state for other memory needs of the prepared
 78390  78404   ** statement.
 78391  78405   */
 78392  78406   static void *allocSpace(
 78393  78407     struct ReusableSpace *p,  /* Bulk memory available for allocation */
 78394  78408     void *pBuf,               /* Pointer to a prior allocation */
 78395         -  int nByte                 /* Bytes of memory needed */
        78409  +  sqlite3_int64 nByte       /* Bytes of memory needed */
 78396  78410   ){
 78397  78411     assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
 78398  78412     if( pBuf==0 ){
 78399  78413       nByte = ROUND8(nByte);
 78400  78414       if( nByte <= p->nFree ){
 78401  78415         p->nFree -= nByte;
 78402  78416         pBuf = &p->pSpace[p->nFree];
................................................................................
 81345  81359     sqlite3_int64 iElapse;
 81346  81360     assert( p->startTime>0 );
 81347  81361     assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
 81348  81362     assert( db->init.busy==0 );
 81349  81363     assert( p->zSql!=0 );
 81350  81364     sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
 81351  81365     iElapse = (iNow - p->startTime)*1000000;
 81352         -#ifndef SQLITE_OMIT_DEPRECATED  	
        81366  +#ifndef SQLITE_OMIT_DEPRECATED
 81353  81367     if( db->xProfile ){
 81354  81368       db->xProfile(db->pProfileArg, p->zSql, iElapse);
 81355  81369     }
 81356  81370   #endif
 81357  81371     if( db->mTrace & SQLITE_TRACE_PROFILE ){
 81358  81372       db->xTrace(SQLITE_TRACE_PROFILE, db->pTraceArg, p, (void*)&iElapse);
 81359  81373     }
................................................................................
 92241  92255       ** In this case, allocate space at p->aAlloc[] to copy the requested
 92242  92256       ** range into. Then return a copy of pointer p->aAlloc to the caller.  */
 92243  92257       int nRem;                     /* Bytes remaining to copy */
 92244  92258   
 92245  92259       /* Extend the p->aAlloc[] allocation if required. */
 92246  92260       if( p->nAlloc<nByte ){
 92247  92261         u8 *aNew;
 92248         -      int nNew = MAX(128, p->nAlloc*2);
        92262  +      sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
 92249  92263         while( nByte>nNew ) nNew = nNew*2;
 92250  92264         aNew = sqlite3Realloc(p->aAlloc, nNew);
 92251  92265         if( !aNew ) return SQLITE_NOMEM_BKPT;
 92252  92266         p->nAlloc = nNew;
 92253  92267         p->aAlloc = aNew;
 92254  92268       }
 92255  92269   
................................................................................
 93533  93547   
 93534  93548     if( pSorter->list.aMemory ){
 93535  93549       int nMin = pSorter->iMemory + nReq;
 93536  93550   
 93537  93551       if( nMin>pSorter->nMemory ){
 93538  93552         u8 *aNew;
 93539  93553         int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
 93540         -      int nNew = pSorter->nMemory * 2;
        93554  +      sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory;
 93541  93555         while( nNew < nMin ) nNew = nNew*2;
 93542  93556         if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
 93543  93557         if( nNew < nMin ) nNew = nMin;
 93544  93558   
 93545  93559         aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
 93546  93560         if( !aNew ) return SQLITE_NOMEM_BKPT;
 93547  93561         pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
................................................................................
 98190  98204   ** argument. If an OOM condition is encountered, NULL is returned
 98191  98205   ** and the db->mallocFailed flag set.
 98192  98206   */
 98193  98207   #ifndef SQLITE_OMIT_CTE
 98194  98208   static With *withDup(sqlite3 *db, With *p){
 98195  98209     With *pRet = 0;
 98196  98210     if( p ){
 98197         -    int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
        98211  +    sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
 98198  98212       pRet = sqlite3DbMallocZero(db, nByte);
 98199  98213       if( pRet ){
 98200  98214         int i;
 98201  98215         pRet->nCte = p->nCte;
 98202  98216         for(i=0; i<p->nCte; i++){
 98203  98217           pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
 98204  98218           pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
................................................................................
 98455  98469       if( pList==0 ){
 98456  98470         goto no_mem;
 98457  98471       }
 98458  98472       pList->nExpr = 0;
 98459  98473     }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
 98460  98474       ExprList *pNew;
 98461  98475       pNew = sqlite3DbRealloc(db, pList, 
 98462         -             sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
        98476  +         sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
 98463  98477       if( pNew==0 ){
 98464  98478         goto no_mem;
 98465  98479       }
 98466  98480       pList = pNew;
 98467  98481     }
 98468  98482     pItem = &pList->a[pList->nExpr++];
 98469  98483     assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
................................................................................
106151 106165       if( !REOPEN_AS_MEMDB(db) ){
106152 106166         rc = sqlite3Init(db, &zErrDyn);
106153 106167       }
106154 106168       sqlite3BtreeLeaveAll(db);
106155 106169       assert( zErrDyn==0 || rc!=SQLITE_OK );
106156 106170     }
106157 106171   #ifdef SQLITE_USER_AUTHENTICATION
106158         -  if( rc==SQLITE_OK ){
       106172  +  if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
106159 106173       u8 newAuth = 0;
106160 106174       rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
106161 106175       if( newAuth<db->auth.authLevel ){
106162 106176         rc = SQLITE_AUTH_USER;
106163 106177       }
106164 106178     }
106165 106179   #endif
................................................................................
110588 110602     sqlite3 *db,      /* Connection to notify of malloc failures */
110589 110603     void *pArray,     /* Array of objects.  Might be reallocated */
110590 110604     int szEntry,      /* Size of each object in the array */
110591 110605     int *pnEntry,     /* Number of objects currently in use */
110592 110606     int *pIdx         /* Write the index of a new slot here */
110593 110607   ){
110594 110608     char *z;
110595         -  int n = *pnEntry;
       110609  +  sqlite3_int64 n = *pIdx = *pnEntry;
110596 110610     if( (n & (n-1))==0 ){
110597         -    int sz = (n==0) ? 1 : 2*n;
       110611  +    sqlite3_int64 sz = (n==0) ? 1 : 2*n;
110598 110612       void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110599 110613       if( pNew==0 ){
110600 110614         *pIdx = -1;
110601 110615         return pArray;
110602 110616       }
110603 110617       pArray = pNew;
110604 110618     }
110605 110619     z = (char*)pArray;
110606 110620     memset(&z[n * szEntry], 0, szEntry);
110607         -  *pIdx = n;
110608 110621     ++*pnEntry;
110609 110622     return pArray;
110610 110623   }
110611 110624   
110612 110625   /*
110613 110626   ** Append a new element to the given IdList.  Create a new IdList if
110614 110627   ** need be.
................................................................................
110711 110724     assert( nExtra>=1 );
110712 110725     assert( pSrc!=0 );
110713 110726     assert( iStart<=pSrc->nSrc );
110714 110727   
110715 110728     /* Allocate additional space if needed */
110716 110729     if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110717 110730       SrcList *pNew;
110718         -    int nAlloc = pSrc->nSrc*2+nExtra;
       110731  +    sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra;
110719 110732       sqlite3 *db = pParse->db;
110720 110733   
110721 110734       if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110722 110735         sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110723 110736                         SQLITE_MAX_SRCLIST);
110724 110737         return 0;
110725 110738       }
................................................................................
111218 111231     Index *pIdx       /* The index that triggers the constraint */
111219 111232   ){
111220 111233     char *zErr;
111221 111234     int j;
111222 111235     StrAccum errMsg;
111223 111236     Table *pTab = pIdx->pTable;
111224 111237   
111225         -  sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
       111238  +  sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 
       111239  +                      pParse->db->aLimit[SQLITE_LIMIT_LENGTH]);
111226 111240     if( pIdx->aColExpr ){
111227 111241       sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
111228 111242     }else{
111229 111243       for(j=0; j<pIdx->nKeyCol; j++){
111230 111244         char *zCol;
111231 111245         assert( pIdx->aiColumn[j]>=0 );
111232 111246         zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
................................................................................
111467 111481         if( sqlite3StrICmp(zName, pWith->a[i].zName)==0 ){
111468 111482           sqlite3ErrorMsg(pParse, "duplicate WITH table name: %s", zName);
111469 111483         }
111470 111484       }
111471 111485     }
111472 111486   
111473 111487     if( pWith ){
111474         -    int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
       111488  +    sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111475 111489       pNew = sqlite3DbRealloc(db, pWith, nByte);
111476 111490     }else{
111477 111491       pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111478 111492     }
111479 111493     assert( (pNew!=0 && zName!=0) || db->mallocFailed );
111480 111494   
111481 111495     if( db->mallocFailed ){
................................................................................
134578 134592   
134579 134593   /*
134580 134594   ** Add a new module argument to pTable->azModuleArg[].
134581 134595   ** The string is not copied - the pointer is stored.  The
134582 134596   ** string will be freed automatically when the table is
134583 134597   ** deleted.
134584 134598   */
134585         -static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
134586         -  int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
       134599  +static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
       134600  +  sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134587 134601     char **azModuleArg;
       134602  +  sqlite3 *db = pParse->db;
       134603  +  if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
       134604  +    sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
       134605  +  }
134588 134606     azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134589 134607     if( azModuleArg==0 ){
134590 134608       sqlite3DbFree(db, zArg);
134591 134609     }else{
134592 134610       int i = pTable->nModuleArg++;
134593 134611       azModuleArg[i] = zArg;
134594 134612       azModuleArg[i+1] = 0;
................................................................................
134615 134633     pTable = pParse->pNewTable;
134616 134634     if( pTable==0 ) return;
134617 134635     assert( 0==pTable->pIndex );
134618 134636   
134619 134637     db = pParse->db;
134620 134638   
134621 134639     assert( pTable->nModuleArg==0 );
134622         -  addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
134623         -  addModuleArgument(db, pTable, 0);
134624         -  addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
       134640  +  addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
       134641  +  addModuleArgument(pParse, pTable, 0);
       134642  +  addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
134625 134643     assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134626 134644          || (pParse->sNameToken.z==pName1->z && pName2->z==0)
134627 134645     );
134628 134646     pParse->sNameToken.n = (int)(
134629 134647         &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
134630 134648     );
134631 134649   
................................................................................
134650 134668   ** virtual table currently under construction in pParse->pTable.
134651 134669   */
134652 134670   static void addArgumentToVtab(Parse *pParse){
134653 134671     if( pParse->sArg.z && pParse->pNewTable ){
134654 134672       const char *z = (const char*)pParse->sArg.z;
134655 134673       int n = pParse->sArg.n;
134656 134674       sqlite3 *db = pParse->db;
134657         -    addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
       134675  +    addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134658 134676     }
134659 134677   }
134660 134678   
134661 134679   /*
134662 134680   ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
134663 134681   ** has been completely parsed.
134664 134682   */
................................................................................
134939 134957   */
134940 134958   static int growVTrans(sqlite3 *db){
134941 134959     const int ARRAY_INCR = 5;
134942 134960   
134943 134961     /* Grow the sqlite3.aVTrans array if required */
134944 134962     if( (db->nVTrans%ARRAY_INCR)==0 ){
134945 134963       VTable **aVTrans;
134946         -    int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
       134964  +    sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)*
       134965  +                                 ((sqlite3_int64)db->nVTrans + ARRAY_INCR);
134947 134966       aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134948 134967       if( !aVTrans ){
134949 134968         return SQLITE_NOMEM_BKPT;
134950 134969       }
134951 134970       memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
134952 134971       db->aVTrans = aVTrans;
134953 134972     }
................................................................................
135435 135454       return 0;
135436 135455     }
135437 135456     pMod->pEpoTab = pTab;
135438 135457     pTab->nTabRef = 1;
135439 135458     pTab->pSchema = db->aDb[0].pSchema;
135440 135459     assert( pTab->nModuleArg==0 );
135441 135460     pTab->iPKey = -1;
135442         -  addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135443         -  addModuleArgument(db, pTab, 0);
135444         -  addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
       135461  +  addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
       135462  +  addModuleArgument(pParse, pTab, 0);
       135463  +  addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135445 135464     rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135446 135465     if( rc ){
135447 135466       sqlite3ErrorMsg(pParse, "%s", zErr);
135448 135467       sqlite3DbFree(db, zErr);
135449 135468       sqlite3VtabEponymousTableClear(db, pMod);
135450 135469       return 0;
135451 135470     }
................................................................................
155294 155313     if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
155295 155314     if( cnt<0 ) cnt = 0;
155296 155315     if( sz==0 || cnt==0 ){
155297 155316       sz = 0;
155298 155317       pStart = 0;
155299 155318     }else if( pBuf==0 ){
155300 155319       sqlite3BeginBenignMalloc();
155301         -    pStart = sqlite3Malloc( sz*cnt );  /* IMP: R-61949-35727 */
       155320  +    pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt );  /* IMP: R-61949-35727 */
155302 155321       sqlite3EndBenignMalloc();
155303 155322       if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
155304 155323     }else{
155305 155324       pStart = pBuf;
155306 155325     }
155307 155326     db->lookaside.pStart = pStart;
155308 155327     db->lookaside.pInit = 0;
................................................................................
169332 169351       sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
169333 169352       rc = SQLITE_ERROR;
169334 169353     }else{
169335 169354       char const **aArg = 0;
169336 169355       int iArg = 0;
169337 169356       z = &z[n+1];
169338 169357       while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
169339         -      int nNew = sizeof(char *)*(iArg+1);
169340         -      char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
       169358  +      sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
       169359  +      char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
169341 169360         if( !aNew ){
169342 169361           sqlite3_free(zCopy);
169343 169362           sqlite3_free((void *)aArg);
169344 169363           return SQLITE_NOMEM;
169345 169364         }
169346 169365         aArg = aNew;
169347 169366         aArg[iArg++] = z;
................................................................................
170240 170259     UNUSED_PARAMETER(idxStr);
170241 170260     UNUSED_PARAMETER(nVal);
170242 170261   
170243 170262     fts3tokResetCursor(pCsr);
170244 170263     if( idxNum==1 ){
170245 170264       const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
170246 170265       int nByte = sqlite3_value_bytes(apVal[0]);
170247         -    pCsr->zInput = sqlite3_malloc(nByte+1);
       170266  +    pCsr->zInput = sqlite3_malloc64(nByte+1);
170248 170267       if( pCsr->zInput==0 ){
170249 170268         rc = SQLITE_NOMEM;
170250 170269       }else{
170251 170270         memcpy(pCsr->zInput, zByte, nByte);
170252 170271         pCsr->zInput[nByte] = 0;
170253 170272         rc = pTab->pMod->xOpen(pTab->pTok, pCsr->zInput, nByte, &pCsr->pCsr);
170254 170273         if( rc==SQLITE_OK ){
................................................................................
172104 172123       if( pE ){
172105 172124         aElem = &pE;
172106 172125         nElem = 1;
172107 172126       }
172108 172127     }
172109 172128   
172110 172129     if( nElem>0 ){
172111         -    int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172112         -    pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
       172130  +    sqlite3_int64 nByte;
       172131  +    nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
       172132  +    pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
172113 172133       if( !pReader ){
172114 172134         rc = SQLITE_NOMEM;
172115 172135       }else{
172116 172136         memset(pReader, 0, nByte);
172117 172137         pReader->iIdx = 0x7FFFFFFF;
172118 172138         pReader->ppNextElem = (Fts3HashElem **)&pReader[1];
172119 172139         memcpy(pReader->ppNextElem, aElem, nElem*sizeof(Fts3HashElem *));
................................................................................
173719 173739   ){
173720 173740     char *pBlob;             /* The BLOB encoding of the document size */
173721 173741     int nBlob;               /* Number of bytes in the BLOB */
173722 173742     sqlite3_stmt *pStmt;     /* Statement used to insert the encoding */
173723 173743     int rc;                  /* Result code from subfunctions */
173724 173744   
173725 173745     if( *pRC ) return;
173726         -  pBlob = sqlite3_malloc( 10*p->nColumn );
       173746  +  pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
173727 173747     if( pBlob==0 ){
173728 173748       *pRC = SQLITE_NOMEM;
173729 173749       return;
173730 173750     }
173731 173751     fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
173732 173752     rc = fts3SqlStmt(p, SQL_REPLACE_DOCSIZE, &pStmt, 0);
173733 173753     if( rc ){
................................................................................
173769 173789     sqlite3_stmt *pStmt;     /* Statement for reading and writing */
173770 173790     int i;                   /* Loop counter */
173771 173791     int rc;                  /* Result code from subfunctions */
173772 173792   
173773 173793     const int nStat = p->nColumn+2;
173774 173794   
173775 173795     if( *pRC ) return;
173776         -  a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
       173796  +  a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
173777 173797     if( a==0 ){
173778 173798       *pRC = SQLITE_NOMEM;
173779 173799       return;
173780 173800     }
173781 173801     pBlob = (char*)&a[nStat];
173782 173802     rc = fts3SqlStmt(p, SQL_SELECT_STAT, &pStmt, 0);
173783 173803     if( rc ){
................................................................................
173890 173910         rc = SQLITE_NOMEM;
173891 173911       }else{
173892 173912         rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
173893 173913         sqlite3_free(zSql);
173894 173914       }
173895 173915   
173896 173916       if( rc==SQLITE_OK ){
173897         -      int nByte = sizeof(u32) * (p->nColumn+1)*3;
173898         -      aSz = (u32 *)sqlite3_malloc(nByte);
       173917  +      sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
       173918  +      aSz = (u32 *)sqlite3_malloc64(nByte);
173899 173919         if( aSz==0 ){
173900 173920           rc = SQLITE_NOMEM;
173901 173921         }else{
173902 173922           memset(aSz, 0, nByte);
173903 173923           aSzIns = &aSz[p->nColumn+1];
173904 173924           aSzDel = &aSzIns[p->nColumn+1];
173905 173925         }
................................................................................
173957 173977     Fts3Table *p,                   /* FTS3 table handle */
173958 173978     sqlite3_int64 iAbsLevel,        /* Absolute level to open */
173959 173979     int nSeg,                       /* Number of segments to merge */
173960 173980     Fts3MultiSegReader *pCsr        /* Cursor object to populate */
173961 173981   ){
173962 173982     int rc;                         /* Return Code */
173963 173983     sqlite3_stmt *pStmt = 0;        /* Statement used to read %_segdir entry */  
173964         -  int nByte;                      /* Bytes allocated at pCsr->apSegment[] */
       173984  +  sqlite3_int64 nByte;            /* Bytes allocated at pCsr->apSegment[] */
173965 173985   
173966 173986     /* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173967 173987     memset(pCsr, 0, sizeof(*pCsr));
173968 173988     nByte = sizeof(Fts3SegReader *) * nSeg;
173969         -  pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
       173989  +  pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);
173970 173990   
173971 173991     if( pCsr->apSegment==0 ){
173972 173992       rc = SQLITE_NOMEM;
173973 173993     }else{
173974 173994       memset(pCsr->apSegment, 0, nByte);
173975 173995       rc = fts3SqlStmt(p, SQL_SELECT_LEVEL, &pStmt, 0);
173976 173996     }
................................................................................
175942 175962   
175943 175963     if( nArg>1 && sqlite3_value_int(apVal[2 + p->nColumn + 2])<0 ){
175944 175964       rc = SQLITE_CONSTRAINT;
175945 175965       goto update_out;
175946 175966     }
175947 175967   
175948 175968     /* Allocate space to hold the change in document sizes */
175949         -  aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
       175969  +  aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
175950 175970     if( aSzDel==0 ){
175951 175971       rc = SQLITE_NOMEM;
175952 175972       goto update_out;
175953 175973     }
175954 175974     aSzIns = &aSzDel[p->nColumn+1];
175955 175975     memset(aSzDel, 0, sizeof(aSzDel[0])*(p->nColumn+1)*2);
175956 175976   
................................................................................
176196 176216   /*************************************************************************
176197 176217   ** Start of MatchinfoBuffer code.
176198 176218   */
176199 176219   
176200 176220   /*
176201 176221   ** Allocate a two-slot MatchinfoBuffer object.
176202 176222   */
176203         -static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
       176223  +static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
176204 176224     MatchinfoBuffer *pRet;
176205         -  int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
176206         -  int nStr = (int)strlen(zMatchinfo);
       176225  +  sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
       176226  +                           + sizeof(MatchinfoBuffer);
       176227  +  sqlite3_int64 nStr = strlen(zMatchinfo);
176207 176228   
176208         -  pRet = sqlite3_malloc(nByte + nStr+1);
       176229  +  pRet = sqlite3_malloc64(nByte + nStr+1);
176209 176230     if( pRet ){
176210 176231       memset(pRet, 0, nByte);
176211 176232       pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
176212         -    pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
176213         -    pRet->nElem = nElem;
       176233  +    pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
       176234  +                                      + sizeof(u32)*((int)nElem+1);
       176235  +    pRet->nElem = (int)nElem;
176214 176236       pRet->zMatchinfo = ((char*)pRet) + nByte;
176215 176237       memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
176216 176238       pRet->aRef[0] = 1;
176217 176239     }
176218 176240   
176219 176241     return pRet;
176220 176242   }
................................................................................
177067 177089     ){
177068 177090       return SQLITE_OK;
177069 177091     }
177070 177092     sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
177071 177093     return SQLITE_ERROR;
177072 177094   }
177073 177095   
177074         -static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177075         -  int nVal;                       /* Number of integers output by cArg */
       177096  +static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
       177097  +  size_t nVal;                      /* Number of integers output by cArg */
177076 177098   
177077 177099     switch( cArg ){
177078 177100       case FTS3_MATCHINFO_NDOC:
177079 177101       case FTS3_MATCHINFO_NPHRASE: 
177080 177102       case FTS3_MATCHINFO_NCOL: 
177081 177103         nVal = 1;
177082 177104         break;
................................................................................
177352 177374           if( rc==SQLITE_OK ){
177353 177375             rc = fts3MatchinfoLcs(pCsr, pInfo);
177354 177376           }
177355 177377           break;
177356 177378   
177357 177379         case FTS3_MATCHINFO_LHITS_BM:
177358 177380         case FTS3_MATCHINFO_LHITS: {
177359         -        int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
       177381  +        size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177360 177382           memset(pInfo->aMatchinfo, 0, nZero);
177361 177383           rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
177362 177384           break;
177363 177385         }
177364 177386   
177365 177387         default: {
177366 177388           Fts3Expr *pExpr;
................................................................................
177421 177443   
177422 177444     /* If Fts3Cursor.pMIBuffer is NULL, then this is the first time the
177423 177445     ** matchinfo function has been called for this query. In this case 
177424 177446     ** allocate the array used to accumulate the matchinfo data and
177425 177447     ** initialize those elements that are constant for every row.
177426 177448     */
177427 177449     if( pCsr->pMIBuffer==0 ){
177428         -    int nMatchinfo = 0;           /* Number of u32 elements in match-info */
       177450  +    size_t nMatchinfo = 0;        /* Number of u32 elements in match-info */
177429 177451       int i;                        /* Used to iterate through zArg */
177430 177452   
177431 177453       /* Determine the number of phrases in the query */
177432 177454       pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
177433 177455       sInfo.nPhrase = pCsr->nPhrase;
177434 177456   
177435 177457       /* Determine the number of integers in the buffer returned by this call. */
................................................................................
185682 185704        && s.a[0]==s.a[s.nVertex*2-2]
185683 185705        && s.a[1]==s.a[s.nVertex*2-1]
185684 185706        && (s.z++, geopolySkipSpace(&s)==0)
185685 185707       ){
185686 185708         GeoPoly *pOut;
185687 185709         int x = 1;
185688 185710         s.nVertex--;  /* Remove the redundant vertex at the end */
185689         -      pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
       185711  +      pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
185690 185712         x = 1;
185691 185713         if( pOut==0 ) goto parse_json_err;
185692 185714         pOut->nVertex = s.nVertex;
185693 185715         memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
185694 185716         pOut->hdr[0] = *(unsigned char*)&x;
185695 185717         pOut->hdr[1] = (s.nVertex>>16)&0xff;
185696 185718         pOut->hdr[2] = (s.nVertex>>8)&0xff;
................................................................................
186068 186090         r = GeoY(p,ii);
186069 186091         if( r<mnY ) mnY = (float)r;
186070 186092         else if( r>mxY ) mxY = (float)r;
186071 186093       }
186072 186094       if( pRc ) *pRc = SQLITE_OK;
186073 186095       if( aCoord==0 ){
186074 186096         geopolyBboxFill:
186075         -      pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
       186097  +      pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
186076 186098         if( pOut==0 ){
186077 186099           sqlite3_free(p);
186078 186100           if( context ) sqlite3_result_error_nomem(context);
186079 186101           if( pRc ) *pRc = SQLITE_NOMEM;
186080 186102           return 0;
186081 186103         }
186082 186104         pOut->nVertex = 4;
................................................................................
186464 186486     return p;
186465 186487   }
186466 186488   
186467 186489   /*
186468 186490   ** Determine the overlap between two polygons
186469 186491   */
186470 186492   static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
186471         -  int nVertex = p1->nVertex + p2->nVertex + 2;
       186493  +  sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
186472 186494     GeoOverlap *p;
186473         -  int nByte;
       186495  +  sqlite3_int64 nByte;
186474 186496     GeoEvent *pThisEvent;
186475 186497     double rX;
186476 186498     int rc = 0;
186477 186499     int needSort = 0;
186478 186500     GeoSegment *pActive = 0;
186479 186501     GeoSegment *pSeg;
186480 186502     unsigned char aOverlap[4];
186481 186503   
186482 186504     nByte = sizeof(GeoEvent)*nVertex*2 
186483 186505              + sizeof(GeoSegment)*nVertex 
186484 186506              + sizeof(GeoOverlap);
186485         -  p = sqlite3_malloc( nByte );
       186507  +  p = sqlite3_malloc64( nByte );
186486 186508     if( p==0 ) return -1;
186487 186509     p->aEvent = (GeoEvent*)&p[1];
186488 186510     p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
186489 186511     p->nEvent = p->nSegment = 0;
186490 186512     geopolyAddSegments(p, p1, 1);
186491 186513     geopolyAddSegments(p, p2, 2);
186492 186514     pThisEvent = geopolySortEventsByX(p->aEvent, p->nEvent);
................................................................................
186637 186659     int argc, const char *const*argv,   /* Parameters to CREATE TABLE statement */
186638 186660     sqlite3_vtab **ppVtab,              /* OUT: New virtual table */
186639 186661     char **pzErr,                       /* OUT: Error message, if any */
186640 186662     int isCreate                        /* True for xCreate, false for xConnect */
186641 186663   ){
186642 186664     int rc = SQLITE_OK;
186643 186665     Rtree *pRtree;
186644         -  int nDb;              /* Length of string argv[1] */
186645         -  int nName;            /* Length of string argv[2] */
       186666  +  sqlite3_int64 nDb;              /* Length of string argv[1] */
       186667  +  sqlite3_int64 nName;            /* Length of string argv[2] */
186646 186668     sqlite3_str *pSql;
186647 186669     char *zSql;
186648 186670     int ii;
186649 186671   
186650 186672     sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
186651 186673   
186652 186674     /* Allocate the sqlite3_vtab structure */
186653         -  nDb = (int)strlen(argv[1]);
186654         -  nName = (int)strlen(argv[2]);
186655         -  pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
       186675  +  nDb = strlen(argv[1]);
       186676  +  nName = strlen(argv[2]);
       186677  +  pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
186656 186678     if( !pRtree ){
186657 186679       return SQLITE_NOMEM;
186658 186680     }
186659 186681     memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
186660 186682     pRtree->nBusy = 1;
186661 186683     pRtree->base.pModule = &rtreeModule;
186662 186684     pRtree->zDb = (char *)&pRtree[1];
................................................................................
189073 189095   **     * a special "cleanup table" state.
189074 189096   **
189075 189097   ** abIndexed:
189076 189098   **   If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
189077 189099   **   it points to an array of flags nTblCol elements in size. The flag is
189078 189100   **   set for each column that is either a part of the PK or a part of an
189079 189101   **   index. Or clear otherwise.
       189102  +**
       189103  +**   If there are one or more partial indexes on the table, all fields of
       189104  +**   this array set set to 1. This is because in that case, the module has
       189105  +**   no way to tell which fields will be required to add and remove entries
       189106  +**   from the partial indexes.
189080 189107   **   
189081 189108   */
189082 189109   struct RbuObjIter {
189083 189110     sqlite3_stmt *pTblIter;         /* Iterate through tables */
189084 189111     sqlite3_stmt *pIdxIter;         /* Index iterator */
189085 189112     int nTblCol;                    /* Size of azTblCol[] array */
189086 189113     char **azTblCol;                /* Array of unquoted target column names */
................................................................................
189868 189895   **
189869 189896   ** If an error (i.e. an OOM condition) occurs, return NULL and leave an 
189870 189897   ** error code in the rbu handle passed as the first argument. Or, if an 
189871 189898   ** error has already occurred when this function is called, return NULL 
189872 189899   ** immediately without attempting the allocation or modifying the stored
189873 189900   ** error code.
189874 189901   */
189875         -static void *rbuMalloc(sqlite3rbu *p, int nByte){
       189902  +static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){
189876 189903     void *pRet = 0;
189877 189904     if( p->rc==SQLITE_OK ){
189878 189905       assert( nByte>0 );
189879 189906       pRet = sqlite3_malloc64(nByte);
189880 189907       if( pRet==0 ){
189881 189908         p->rc = SQLITE_NOMEM;
189882 189909       }else{
................................................................................
189889 189916   
189890 189917   /*
189891 189918   ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
189892 189919   ** there is room for at least nCol elements. If an OOM occurs, store an
189893 189920   ** error code in the RBU handle passed as the first argument.
189894 189921   */
189895 189922   static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
189896         -  int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
       189923  +  sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189897 189924     char **azNew;
189898 189925   
189899 189926     azNew = (char**)rbuMalloc(p, nByte);
189900 189927     if( azNew ){
189901 189928       pIter->azTblCol = azNew;
189902 189929       pIter->azTblType = &azNew[nCol];
189903 189930       pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
................................................................................
190083 190110           sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
190084 190111       );
190085 190112     }
190086 190113   
190087 190114     pIter->nIndex = 0;
190088 190115     while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
190089 190116       const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
       190117  +    int bPartial = sqlite3_column_int(pList, 4);
190090 190118       sqlite3_stmt *pXInfo = 0;
190091 190119       if( zIdx==0 ) break;
       190120  +    if( bPartial ){
       190121  +      memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
       190122  +    }
190092 190123       p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
190093 190124           sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
190094 190125       );
190095 190126       while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
190096 190127         int iCid = sqlite3_column_int(pXInfo, 1);
190097 190128         if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
190098 190129       }
................................................................................
190529 190560   ** string, an error code is left in the rbu handle passed as the first
190530 190561   ** argument and NULL is returned. Or, if an error has already occurred
190531 190562   ** when this function is called, NULL is returned immediately, without
190532 190563   ** attempting the allocation or modifying the stored error code.
190533 190564   */
190534 190565   static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
190535 190566     char *zRet = 0;
190536         -  int nByte = nBind*2 + 1;
       190567  +  sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1;
190537 190568   
190538 190569     zRet = (char*)rbuMalloc(p, nByte);
190539 190570     if( zRet ){
190540 190571       int i;
190541 190572       for(i=0; i<nBind; i++){
190542 190573         zRet[i*2] = '?';
190543 190574         zRet[i*2+1] = (i+1==nBind) ? '\0' : ',';
................................................................................
190790 190821       rc = sqlite3_reset(p->objiter.pTmpInsert);
190791 190822     }
190792 190823   
190793 190824     if( rc!=SQLITE_OK ){
190794 190825       sqlite3_result_error_code(pCtx, rc);
190795 190826     }
190796 190827   }
       190828  +
       190829  +static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
       190830  +  sqlite3_stmt *pStmt = 0;
       190831  +  int rc = p->rc;
       190832  +  char *zRet = 0;
       190833  +
       190834  +  if( rc==SQLITE_OK ){
       190835  +    rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
       190836  +        "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
       190837  +    );
       190838  +  }
       190839  +  if( rc==SQLITE_OK ){
       190840  +    int rc2;
       190841  +    rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
       190842  +    if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
       190843  +      const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
       190844  +      if( zSql ){
       190845  +        int nParen = 0;           /* Number of open parenthesis */
       190846  +        int i;
       190847  +        for(i=0; zSql[i]; i++){
       190848  +          char c = zSql[i];
       190849  +          if( c=='(' ){
       190850  +            nParen++;
       190851  +          }
       190852  +          else if( c==')' ){
       190853  +            nParen--;
       190854  +            if( nParen==0 ){
       190855  +              i++;
       190856  +              break;
       190857  +            }
       190858  +          }else if( c=='"' || c=='\'' || c=='`' ){
       190859  +            for(i++; 1; i++){
       190860  +              if( zSql[i]==c ){
       190861  +                if( zSql[i+1]!=c ) break;
       190862  +                i++;
       190863  +              }
       190864  +            }
       190865  +          }else if( c=='[' ){
       190866  +            for(i++; 1; i++){
       190867  +              if( zSql[i]==']' ) break;
       190868  +            }
       190869  +          }
       190870  +        }
       190871  +        if( zSql[i] ){
       190872  +          zRet = rbuStrndup(&zSql[i], &rc);
       190873  +        }
       190874  +      }
       190875  +    }
       190876  +
       190877  +    rc2 = sqlite3_finalize(pStmt);
       190878  +    if( rc==SQLITE_OK ) rc = rc2;
       190879  +  }
       190880  +
       190881  +  p->rc = rc;
       190882  +  return zRet;
       190883  +}
190797 190884   
190798 190885   /*
190799 190886   ** Ensure that the SQLite statement handles required to update the 
190800 190887   ** target database object currently indicated by the iterator passed 
190801 190888   ** as the second argument are available.
190802 190889   */
190803 190890   static int rbuObjIterPrepareAll(
................................................................................
190820 190907   
190821 190908       if( zIdx ){
190822 190909         const char *zTbl = pIter->zTbl;
190823 190910         char *zImposterCols = 0;    /* Columns for imposter table */
190824 190911         char *zImposterPK = 0;      /* Primary key declaration for imposter */
190825 190912         char *zWhere = 0;           /* WHERE clause on PK columns */
190826 190913         char *zBind = 0;
       190914  +      char *zPart = 0;
190827 190915         int nBind = 0;
190828 190916   
190829 190917         assert( pIter->eType!=RBU_PK_VTAB );
190830 190918         zCollist = rbuObjIterGetIndexCols(
190831 190919             p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
190832 190920         );
190833 190921         zBind = rbuObjIterGetBindlist(p, nBind);
       190922  +      zPart = rbuObjIterGetIndexWhere(p, pIter);
190834 190923   
190835 190924         /* Create the imposter table used to write to this index. */
190836 190925         sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
190837 190926         sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
190838 190927         rbuMPrintfExec(p, p->dbMain,
190839 190928             "CREATE TABLE \"rbu_imp_%w\"( %s, PRIMARY KEY( %s ) ) WITHOUT ROWID",
190840 190929             zTbl, zImposterCols, zImposterPK
................................................................................
190859 190948         }
190860 190949   
190861 190950         /* Create the SELECT statement to read keys in sorted order */
190862 190951         if( p->rc==SQLITE_OK ){
190863 190952           char *zSql;
190864 190953           if( rbuIsVacuum(p) ){
190865 190954             zSql = sqlite3_mprintf(
190866         -              "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
       190955  +              "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s",
190867 190956                 zCollist, 
190868 190957                 pIter->zDataTbl,
190869         -              zCollist, zLimit
       190958  +              zPart, zCollist, zLimit
190870 190959             );
190871 190960           }else
190872 190961   
190873 190962           if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
190874 190963             zSql = sqlite3_mprintf(
190875         -              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
       190964  +              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s",
190876 190965                 zCollist, p->zStateDb, pIter->zDataTbl,
190877         -              zCollist, zLimit
       190966  +              zPart, zCollist, zLimit
190878 190967             );
190879 190968           }else{
190880 190969             zSql = sqlite3_mprintf(
190881         -              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
       190970  +              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s "
190882 190971                 "UNION ALL "
190883 190972                 "SELECT %s, rbu_control FROM '%q' "
190884         -              "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
       190973  +              "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 "
190885 190974                 "ORDER BY %s%s",
190886         -              zCollist, p->zStateDb, pIter->zDataTbl, 
       190975  +              zCollist, p->zStateDb, pIter->zDataTbl, zPart,
190887 190976                 zCollist, pIter->zDataTbl, 
       190977  +              zPart,
       190978  +              (zPart ? "AND" : "WHERE"),
190888 190979                 zCollist, zLimit
190889 190980             );
190890 190981           }
190891 190982           p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
190892 190983         }
190893 190984   
190894 190985         sqlite3_free(zImposterCols);
190895 190986         sqlite3_free(zImposterPK);
190896 190987         sqlite3_free(zWhere);
190897 190988         sqlite3_free(zBind);
       190989  +      sqlite3_free(zPart);
190898 190990       }else{
190899 190991         int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
190900 190992                       ||(pIter->eType==RBU_PK_NONE)
190901 190993                       ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
190902 190994         const char *zTbl = pIter->zTbl;       /* Table this step applies to */
190903 190995         const char *zWrite;                   /* Imposter table name */
190904 190996   
................................................................................
193324 193416   
193325 193417     /* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
193326 193418     ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space 
193327 193419     ** instead of a file on disk.  */
193328 193420     assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
193329 193421     if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
193330 193422       if( iRegion<=p->nShm ){
193331         -      int nByte = (iRegion+1) * sizeof(char*);
       193423  +      sqlite3_int64 nByte = (iRegion+1) * sizeof(char*);
193332 193424         char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
193333 193425         if( apNew==0 ){
193334 193426           rc = SQLITE_NOMEM;
193335 193427         }else{
193336 193428           memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
193337 193429           p->apShm = apNew;
193338 193430           p->nShm = iRegion+1;
................................................................................
195835 195927   ** Growing the hash table in this case is a performance optimization only,
195836 195928   ** it is not required for correct operation.
195837 195929   */
195838 195930   static int sessionGrowHash(int bPatchset, SessionTable *pTab){
195839 195931     if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
195840 195932       int i;
195841 195933       SessionChange **apNew;
195842         -    int nNew = (pTab->nChange ? pTab->nChange : 128) * 2;
       195934  +    sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128);
195843 195935   
195844 195936       apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
195845 195937       if( apNew==0 ){
195846 195938         if( pTab->nChange==0 ){
195847 195939           return SQLITE_ERROR;
195848 195940         }
195849 195941         return SQLITE_OK;
................................................................................
196762 196854   /*
196763 196855   ** Ensure that there is room in the buffer to append nByte bytes of data.
196764 196856   ** If not, use sqlite3_realloc() to grow the buffer so that there is.
196765 196857   **
196766 196858   ** If successful, return zero. Otherwise, if an OOM condition is encountered,
196767 196859   ** set *pRc to SQLITE_NOMEM and return non-zero.
196768 196860   */
196769         -static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){
       196861  +static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
196770 196862     if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
196771 196863       u8 *aNew;
196772 196864       i64 nNew = p->nAlloc ? p->nAlloc : 128;
196773 196865       do {
196774 196866         nNew = nNew*2;
196775 196867       }while( (nNew-p->nBuf)<nByte );
196776 196868   
................................................................................
197880 197972         sessionBufferGrow(&p->tblhdr, nByte, &rc);
197881 197973       }else{
197882 197974         rc = SQLITE_CORRUPT_BKPT;
197883 197975       }
197884 197976     }
197885 197977   
197886 197978     if( rc==SQLITE_OK ){
197887         -    int iPK = sizeof(sqlite3_value*)*p->nCol*2;
       197979  +    size_t iPK = sizeof(sqlite3_value*)*p->nCol*2;
197888 197980       memset(p->tblhdr.aBuf, 0, iPK);
197889 197981       memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
197890 197982       p->in.iNext += nCopy;
197891 197983     }
197892 197984   
197893 197985     p->apValue = (sqlite3_value**)p->tblhdr.aBuf;
197894 197986     p->abPK = (u8*)&p->apValue[p->nCol*2];
................................................................................
199184 199276     while( pApply->constraints.nBuf ){
199185 199277       sqlite3_changeset_iter *pIter2 = 0;
199186 199278       SessionBuffer cons = pApply->constraints;
199187 199279       memset(&pApply->constraints, 0, sizeof(SessionBuffer));
199188 199280   
199189 199281       rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
199190 199282       if( rc==SQLITE_OK ){
199191         -      int nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
       199283  +      size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199192 199284         int rc2;
199193 199285         pIter2->bPatchset = bPatchset;
199194 199286         pIter2->zTab = (char*)zTab;
199195 199287         pIter2->nCol = pApply->nCol;
199196 199288         pIter2->abPK = pApply->abPK;
199197 199289         sessionBufferGrow(&pIter2->tblhdr, nByte, &rc);
199198 199290         pIter2->apValue = (sqlite3_value**)pIter2->tblhdr.aBuf;
................................................................................
212473 212565     if( p->rc==SQLITE_OK && nLvl>=pWriter->nDlidx ){
212474 212566       Fts5DlidxWriter *aDlidx = (Fts5DlidxWriter*)sqlite3_realloc64(
212475 212567           pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
212476 212568       );
212477 212569       if( aDlidx==0 ){
212478 212570         p->rc = SQLITE_NOMEM;
212479 212571       }else{
212480         -      int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
       212572  +      size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212481 212573         memset(&aDlidx[pWriter->nDlidx], 0, nByte);
212482 212574         pWriter->aDlidx = aDlidx;
212483 212575         pWriter->nDlidx = nLvl;
212484 212576       }
212485 212577     }
212486 212578     return p->rc;
212487 212579   }
................................................................................
217824 217916     fts5_extension_function xFunc,  /* Aux. function implementation */
217825 217917     void(*xDestroy)(void*)          /* Destructor for pUserData */
217826 217918   ){
217827 217919     Fts5Global *pGlobal = (Fts5Global*)pApi;
217828 217920     int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
217829 217921     if( rc==SQLITE_OK ){
217830 217922       Fts5Auxiliary *pAux;
217831         -    int nName;                      /* Size of zName in bytes, including \0 */
217832         -    int nByte;                      /* Bytes of space to allocate */
       217923  +    sqlite3_int64 nName;            /* Size of zName in bytes, including \0 */
       217924  +    sqlite3_int64 nByte;            /* Bytes of space to allocate */
217833 217925   
217834         -    nName = (int)strlen(zName) + 1;
       217926  +    nName = strlen(zName) + 1;
217835 217927       nByte = sizeof(Fts5Auxiliary) + nName;
217836         -    pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte);
       217928  +    pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte);
217837 217929       if( pAux ){
217838         -      memset(pAux, 0, nByte);
       217930  +      memset(pAux, 0, (size_t)nByte);
217839 217931         pAux->zFunc = (char*)&pAux[1];
217840 217932         memcpy(pAux->zFunc, zName, nName);
217841 217933         pAux->pGlobal = pGlobal;
217842 217934         pAux->pUserData = pUserData;
217843 217935         pAux->xFunc = xFunc;
217844 217936         pAux->xDestroy = xDestroy;
217845 217937         pAux->pNext = pGlobal->pAux;
................................................................................
217861 217953     const char *zName,              /* Name of new function */
217862 217954     void *pUserData,                /* User data for aux. function */
217863 217955     fts5_tokenizer *pTokenizer,     /* Tokenizer implementation */
217864 217956     void(*xDestroy)(void*)          /* Destructor for pUserData */
217865 217957   ){
217866 217958     Fts5Global *pGlobal = (Fts5Global*)pApi;
217867 217959     Fts5TokenizerModule *pNew;
217868         -  int nName;                      /* Size of zName and its \0 terminator */
217869         -  int nByte;                      /* Bytes of space to allocate */
       217960  +  sqlite3_int64 nName;            /* Size of zName and its \0 terminator */
       217961  +  sqlite3_int64 nByte;            /* Bytes of space to allocate */
217870 217962     int rc = SQLITE_OK;
217871 217963   
217872         -  nName = (int)strlen(zName) + 1;
       217964  +  nName = strlen(zName) + 1;
217873 217965     nByte = sizeof(Fts5TokenizerModule) + nName;
217874         -  pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte);
       217966  +  pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte);
217875 217967     if( pNew ){
217876         -    memset(pNew, 0, nByte);
       217968  +    memset(pNew, 0, (size_t)nByte);
217877 217969       pNew->zName = (char*)&pNew[1];
217878 217970       memcpy(pNew->zName, zName, nName);
217879 217971       pNew->pUserData = pUserData;
217880 217972       pNew->x = *pTokenizer;
217881 217973       pNew->xDestroy = xDestroy;
217882 217974       pNew->pNext = pGlobal->pTok;
217883 217975       pGlobal->pTok = pNew;
................................................................................
218004 218096   static void fts5SourceIdFunc(
218005 218097     sqlite3_context *pCtx,          /* Function call context */
218006 218098     int nArg,                       /* Number of args */
218007 218099     sqlite3_value **apUnused        /* Function arguments */
218008 218100   ){
218009 218101     assert( nArg==0 );
218010 218102     UNUSED_PARAM2(nArg, apUnused);
218011         -  sqlite3_result_text(pCtx, "fts5: 2019-04-07 18:21:12 80704a16f6dbbeacc65fa36a3623df10292a28aeacf9e2c1d2891258479e3b89", -1, SQLITE_TRANSIENT);
       218103  +  sqlite3_result_text(pCtx, "fts5: 2019-04-15 15:41:33 09fa0b3c4adf7f81a777975762029ad43dbdc76b02dc32d2307e1c42465213c9", -1, SQLITE_TRANSIENT);
218012 218104   }
218013 218105   
218014 218106   /*
218015 218107   ** Return true if zName is the extension on one of the shadow tables used
218016 218108   ** by this module.
218017 218109   */
218018 218110   static int fts5ShadowName(const char *zName){
................................................................................
219649 219741       if( p ){
219650 219742         const char *zCat = "L* N* Co";
219651 219743         int i;
219652 219744         memset(p, 0, sizeof(Unicode61Tokenizer));
219653 219745   
219654 219746         p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
219655 219747         p->nFold = 64;
219656         -      p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
       219748  +      p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
219657 219749         if( p->aFold==0 ){
219658 219750           rc = SQLITE_NOMEM;
219659 219751         }
219660 219752   
219661 219753         /* Search for a "categories" argument */
219662 219754         for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
219663 219755           if( 0==sqlite3_stricmp(azArg[i], "categories") ){
................................................................................
222768 222860   #endif
222769 222861     return rc;
222770 222862   }
222771 222863   #endif /* SQLITE_CORE */
222772 222864   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222773 222865   
222774 222866   /************** End of stmt.c ************************************************/
222775         -#if __LINE__!=222774
       222867  +#if __LINE__!=222866
222776 222868   #undef SQLITE_SOURCE_ID
222777         -#define SQLITE_SOURCE_ID      "2019-04-09 01:26:31 8820408597341344b308277ce6ef41b47c7514d6c613520789b05ee52cbealt2"
       222869  +#define SQLITE_SOURCE_ID      "2019-04-15 15:41:33 09fa0b3c4adf7f81a777975762029ad43dbdc76b02dc32d2307e1c424652alt2"
222778 222870   #endif
222779 222871   /* Return the source-id for this library */
222780 222872   SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222781 222873   /************************** End of sqlite3.c ******************************/
222782 222874   #endif /* USE_SYSTEM_SQLITE */
222783 222875   /*
222784 222876   ** 2001 September 15