Code changes that make it easier to prove that no 32-bit integer overflows
happen during memory allocation. No problems fixed; this change is just to make future maintenance easier. FossilOrigin-Name: 215650a5a1d55bdbca9c92524804a1a54456a17f42a17e53747b21a6507506f5
This commit is contained in:
+1
-1
@@ -407,7 +407,7 @@ static void statInit(
|
||||
int nCol; /* Number of columns in index being sampled */
|
||||
int nKeyCol; /* Number of key columns */
|
||||
int nColUp; /* nCol rounded up for alignment */
|
||||
int n; /* Bytes of space to allocate */
|
||||
i64 n; /* Bytes of space to allocate */
|
||||
sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
/* Maximum number of samples. 0 if STAT4 data is not collected */
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ static void attachFunc(
|
||||
if( aNew==0 ) return;
|
||||
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
|
||||
}else{
|
||||
aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
|
||||
aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(1+(i64)db->nDb));
|
||||
if( aNew==0 ) return;
|
||||
}
|
||||
db->aDb = aNew;
|
||||
|
||||
+1
-1
@@ -344,7 +344,7 @@ int sqlite3BitvecBuiltinTest(int sz, int *aOp){
|
||||
/* Allocate the Bitvec to be tested and a linear array of
|
||||
** bits to act as the reference */
|
||||
pBitvec = sqlite3BitvecCreate( sz );
|
||||
pV = sqlite3MallocZero( (sz+7)/8 + 1 );
|
||||
pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
|
||||
pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
|
||||
if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
|
||||
|
||||
|
||||
+3
-2
@@ -729,7 +729,7 @@ static int saveCursorKey(BtCursor *pCur){
|
||||
** below. */
|
||||
void *pKey;
|
||||
pCur->nKey = sqlite3BtreePayloadSize(pCur);
|
||||
pKey = sqlite3Malloc( pCur->nKey + 9 + 8 );
|
||||
pKey = sqlite3Malloc( ((i64)pCur->nKey) + 9 + 8 );
|
||||
if( pKey ){
|
||||
rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -6100,7 +6100,7 @@ bypass_moveto_root:
|
||||
rc = SQLITE_CORRUPT_PAGE(pPage);
|
||||
goto moveto_index_finish;
|
||||
}
|
||||
pCellKey = sqlite3Malloc( nCell+nOverrun );
|
||||
pCellKey = sqlite3Malloc( (u64)nCell+(u64)nOverrun );
|
||||
if( pCellKey==0 ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
goto moveto_index_finish;
|
||||
@@ -11289,6 +11289,7 @@ int sqlite3BtreeIsInBackup(Btree *p){
|
||||
*/
|
||||
void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
|
||||
BtShared *pBt = p->pBt;
|
||||
assert( nBytes==0 || nBytes==sizeof(Schema) );
|
||||
sqlite3BtreeEnter(p);
|
||||
if( !pBt->pSchema && nBytes ){
|
||||
pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
|
||||
|
||||
+16
-8
@@ -68,6 +68,7 @@ static SQLITE_NOINLINE void lockTable(
|
||||
}
|
||||
}
|
||||
|
||||
assert( pToplevel->nTableLock < 0x7fff0000 );
|
||||
nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
|
||||
pToplevel->aTableLock =
|
||||
sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
|
||||
@@ -2089,7 +2090,8 @@ static void identPut(char *z, int *pIdx, char *zSignedIdent){
|
||||
** from sqliteMalloc() and must be freed by the calling function.
|
||||
*/
|
||||
static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
int i, k, n;
|
||||
int i, k, len;
|
||||
i64 n;
|
||||
char *zStmt;
|
||||
char *zSep, *zSep2, *zEnd;
|
||||
Column *pCol;
|
||||
@@ -2113,8 +2115,9 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
sqlite3OomFault(db);
|
||||
return 0;
|
||||
}
|
||||
sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
|
||||
k = sqlite3Strlen30(zStmt);
|
||||
assert( n>14 && n<=0x7fffffff );
|
||||
memcpy(zStmt, "CREATE TABLE ", 13);
|
||||
k = 13;
|
||||
identPut(zStmt, &k, p->zName);
|
||||
zStmt[k++] = '(';
|
||||
for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
|
||||
@@ -2126,13 +2129,15 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
/* SQLITE_AFF_REAL */ " REAL",
|
||||
/* SQLITE_AFF_FLEXNUM */ " NUM",
|
||||
};
|
||||
int len;
|
||||
const char *zType;
|
||||
|
||||
sqlite3_snprintf(n-k, &zStmt[k], zSep);
|
||||
k += sqlite3Strlen30(&zStmt[k]);
|
||||
len = sqlite3Strlen30(zSep);
|
||||
assert( k+len<n );
|
||||
memcpy(&zStmt[k], zSep, len);
|
||||
k += len;
|
||||
zSep = zSep2;
|
||||
identPut(zStmt, &k, pCol->zCnName);
|
||||
assert( k<n );
|
||||
assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
|
||||
assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
|
||||
testcase( pCol->affinity==SQLITE_AFF_BLOB );
|
||||
@@ -2147,11 +2152,14 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
assert( pCol->affinity==SQLITE_AFF_BLOB
|
||||
|| pCol->affinity==SQLITE_AFF_FLEXNUM
|
||||
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
|
||||
assert( k+len<n );
|
||||
memcpy(&zStmt[k], zType, len);
|
||||
k += len;
|
||||
assert( k<=n );
|
||||
}
|
||||
sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
|
||||
len = sqlite3Strlen30(zEnd);
|
||||
assert( k+len<n );
|
||||
memcpy(&zStmt[k], zEnd, len+1);
|
||||
return zStmt;
|
||||
}
|
||||
|
||||
@@ -3845,7 +3853,7 @@ Index *sqlite3AllocateIndexObject(
|
||||
char **ppExtra /* Pointer to the "extra" space */
|
||||
){
|
||||
Index *p; /* Allocated index object */
|
||||
int nByte; /* Bytes of space for Index object + arrays */
|
||||
i64 nByte; /* Bytes of space for Index object + arrays */
|
||||
|
||||
nByte = ROUND8(sizeof(Index)) + /* Index structure */
|
||||
ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
|
||||
|
||||
+1
-1
@@ -3369,7 +3369,7 @@ static char *exprINAffinity(Parse *pParse, const Expr *pExpr){
|
||||
char *zRet;
|
||||
|
||||
assert( pExpr->op==TK_IN );
|
||||
zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
|
||||
zRet = sqlite3DbMallocRaw(pParse->db, 1+(i64)nVal);
|
||||
if( zRet ){
|
||||
int i;
|
||||
for(i=0; i<nVal; i++){
|
||||
|
||||
+1
-1
@@ -1420,7 +1420,7 @@ static void replaceFunc(
|
||||
assert( zRep==sqlite3_value_text(argv[2]) );
|
||||
nOut = nStr + 1;
|
||||
assert( nOut<SQLITE_MAX_LENGTH );
|
||||
zOut = contextMalloc(context, (i64)nOut);
|
||||
zOut = contextMalloc(context, nOut);
|
||||
if( zOut==0 ){
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-2
@@ -567,13 +567,13 @@ static int memdbOpen(
|
||||
}
|
||||
if( p==0 ){
|
||||
MemStore **apNew;
|
||||
p = sqlite3Malloc( sizeof(*p) + szName + 3 );
|
||||
p = sqlite3Malloc( sizeof(*p) + (i64)szName + 3 );
|
||||
if( p==0 ){
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
apNew = sqlite3Realloc(memdb_g.apMemStore,
|
||||
sizeof(apNew[0])*(memdb_g.nMemStore+1) );
|
||||
sizeof(apNew[0])*(1+(i64)memdb_g.nMemStore) );
|
||||
if( apNew==0 ){
|
||||
sqlite3_free(p);
|
||||
sqlite3_mutex_leave(pVfsMutex);
|
||||
|
||||
+9
-10
@@ -3938,7 +3938,7 @@ static int winOpenSharedMemory(winFile *pDbFd){
|
||||
p = sqlite3MallocZero( sizeof(*p) );
|
||||
if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
|
||||
nName = sqlite3Strlen30(pDbFd->zPath);
|
||||
pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
|
||||
pNew = sqlite3MallocZero( sizeof(*pShmNode) + (i64)nName + 17 );
|
||||
if( pNew==0 ){
|
||||
sqlite3_free(p);
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
@@ -4759,7 +4759,7 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
size_t i, j;
|
||||
DWORD pid;
|
||||
int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX);
|
||||
int nMax, nBuf, nDir, nLen;
|
||||
i64 nMax, nBuf, nDir, nLen;
|
||||
char *zBuf;
|
||||
|
||||
/* It's odd to simulate an io-error here, but really this is just
|
||||
@@ -4771,7 +4771,8 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
|
||||
/* Allocate a temporary buffer to store the fully qualified file
|
||||
** name for the temporary file. If this fails, we cannot continue.
|
||||
*/
|
||||
nMax = pVfs->mxPathname; nBuf = nMax + 2;
|
||||
nMax = pVfs->mxPathname;
|
||||
nBuf = 2 + (i64)nMax;
|
||||
zBuf = sqlite3MallocZero( nBuf );
|
||||
if( !zBuf ){
|
||||
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
|
||||
@@ -5630,7 +5631,7 @@ static int winFullPathnameNoMutex(
|
||||
** for converting the relative path name to an absolute
|
||||
** one by prepending the data directory and a slash.
|
||||
*/
|
||||
char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
|
||||
char *zOut = sqlite3MallocZero( 1+(u64)pVfs->mxPathname );
|
||||
if( !zOut ){
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
@@ -5725,13 +5726,12 @@ static int winFullPathnameNoMutex(
|
||||
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
|
||||
"winFullPathname1", zRelative);
|
||||
}
|
||||
nByte += 3;
|
||||
zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
|
||||
zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
|
||||
if( zTemp==0 ){
|
||||
sqlite3_free(zConverted);
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
|
||||
nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte+3, zTemp, 0);
|
||||
if( nByte==0 ){
|
||||
sqlite3_free(zConverted);
|
||||
sqlite3_free(zTemp);
|
||||
@@ -5751,13 +5751,12 @@ static int winFullPathnameNoMutex(
|
||||
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
|
||||
"winFullPathname3", zRelative);
|
||||
}
|
||||
nByte += 3;
|
||||
zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
|
||||
zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
|
||||
if( zTemp==0 ){
|
||||
sqlite3_free(zConverted);
|
||||
return SQLITE_IOERR_NOMEM_BKPT;
|
||||
}
|
||||
nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
|
||||
nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
|
||||
if( nByte==0 ){
|
||||
sqlite3_free(zConverted);
|
||||
sqlite3_free(zTemp);
|
||||
|
||||
+17
-13
@@ -1291,7 +1291,7 @@ static void checkPage(PgHdr *pPg){
|
||||
** If an error occurs while reading from the journal file, an SQLite
|
||||
** error code is returned.
|
||||
*/
|
||||
static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){
|
||||
static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){
|
||||
int rc; /* Return code */
|
||||
u32 len; /* Length in bytes of super-journal name */
|
||||
i64 szJ; /* Total size in bytes of journal file pJrnl */
|
||||
@@ -2527,12 +2527,12 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
|
||||
char *zJournal; /* Pointer to one journal within MJ file */
|
||||
char *zSuperPtr; /* Space to hold super-journal filename */
|
||||
char *zFree = 0; /* Free this buffer */
|
||||
int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
|
||||
i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
|
||||
|
||||
/* Allocate space for both the pJournal and pSuper file descriptors.
|
||||
** If successful, open the super-journal file for reading.
|
||||
*/
|
||||
pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
|
||||
pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
|
||||
if( !pSuper ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
pJournal = 0;
|
||||
@@ -2550,11 +2550,14 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
|
||||
*/
|
||||
rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
|
||||
if( rc!=SQLITE_OK ) goto delsuper_out;
|
||||
nSuperPtr = pVfs->mxPathname+1;
|
||||
nSuperPtr = 1 + (i64)pVfs->mxPathname;
|
||||
assert( nSuperJournal>=0 && nSuperPtr>0 );
|
||||
zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2);
|
||||
if( !zFree ){
|
||||
rc = SQLITE_NOMEM_BKPT;
|
||||
goto delsuper_out;
|
||||
}else{
|
||||
assert( nSuperJournal<=0x7fffffff );
|
||||
}
|
||||
zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
|
||||
zSuperJournal = &zFree[4];
|
||||
@@ -2815,7 +2818,7 @@ static int pager_playback(Pager *pPager, int isHot){
|
||||
** for pageSize.
|
||||
*/
|
||||
zSuper = pPager->pTmpSpace;
|
||||
rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
|
||||
rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
|
||||
if( rc==SQLITE_OK && zSuper[0] ){
|
||||
rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
|
||||
}
|
||||
@@ -2954,7 +2957,7 @@ end_playback:
|
||||
** which case it requires 4 0x00 bytes in memory immediately before
|
||||
** the filename. */
|
||||
zSuper = &pPager->pTmpSpace[4];
|
||||
rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
|
||||
rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
|
||||
testcase( rc!=SQLITE_OK );
|
||||
}
|
||||
if( rc==SQLITE_OK
|
||||
@@ -4724,6 +4727,7 @@ int sqlite3PagerOpen(
|
||||
u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
|
||||
const char *zUri = 0; /* URI args to copy */
|
||||
int nUriByte = 1; /* Number of bytes of URI args at *zUri */
|
||||
|
||||
|
||||
/* Figure out how much space is required for each journal file-handle
|
||||
** (there are two of them, the main journal and the sub-journal). */
|
||||
@@ -4750,8 +4754,8 @@ int sqlite3PagerOpen(
|
||||
*/
|
||||
if( zFilename && zFilename[0] ){
|
||||
const char *z;
|
||||
nPathname = pVfs->mxPathname+1;
|
||||
zPathname = sqlite3DbMallocRaw(0, nPathname*2);
|
||||
nPathname = pVfs->mxPathname + 1;
|
||||
zPathname = sqlite3DbMallocRaw(0, 2*(i64)nPathname);
|
||||
if( zPathname==0 ){
|
||||
return SQLITE_NOMEM_BKPT;
|
||||
}
|
||||
@@ -4838,14 +4842,14 @@ int sqlite3PagerOpen(
|
||||
ROUND8(sizeof(*pPager)) + /* Pager structure */
|
||||
ROUND8(pcacheSize) + /* PCache object */
|
||||
ROUND8(pVfs->szOsFile) + /* The main db file */
|
||||
journalFileSize * 2 + /* The two journal files */
|
||||
(u64)journalFileSize * 2 + /* The two journal files */
|
||||
SQLITE_PTRSIZE + /* Space to hold a pointer */
|
||||
4 + /* Database prefix */
|
||||
nPathname + 1 + /* database filename */
|
||||
nUriByte + /* query parameters */
|
||||
nPathname + 8 + 1 + /* Journal filename */
|
||||
(u64)nPathname + 1 + /* database filename */
|
||||
(u64)nUriByte + /* query parameters */
|
||||
(u64)nPathname + 8 + 1 + /* Journal filename */
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
nPathname + 4 + 1 + /* WAL filename */
|
||||
(u64)nPathname + 4 + 1 + /* WAL filename */
|
||||
#endif
|
||||
3 /* Terminator */
|
||||
);
|
||||
|
||||
+4
-4
@@ -538,12 +538,12 @@ static int pcache1UnderMemoryPressure(PCache1 *pCache){
|
||||
*/
|
||||
static void pcache1ResizeHash(PCache1 *p){
|
||||
PgHdr1 **apNew;
|
||||
unsigned int nNew;
|
||||
unsigned int i;
|
||||
u64 nNew;
|
||||
u32 i;
|
||||
|
||||
assert( sqlite3_mutex_held(p->pGroup->mutex) );
|
||||
|
||||
nNew = p->nHash*2;
|
||||
nNew = 2*(u64)p->nHash;
|
||||
if( nNew<256 ){
|
||||
nNew = 256;
|
||||
}
|
||||
@@ -766,7 +766,7 @@ static void pcache1Destroy(sqlite3_pcache *p);
|
||||
static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
|
||||
PCache1 *pCache; /* The newly created page cache */
|
||||
PGroup *pGroup; /* The group the new page cache will belong to */
|
||||
int sz; /* Bytes of memory required to allocate the new cache */
|
||||
i64 sz; /* Bytes of memory required to allocate the new cache */
|
||||
|
||||
assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
|
||||
assert( szExtra < 300 );
|
||||
|
||||
+1
-1
@@ -1057,7 +1057,7 @@ void sqlite3_str_appendall(sqlite3_str *p, const char *z){
|
||||
static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
|
||||
char *zText;
|
||||
assert( p->mxAlloc>0 && !isMalloced(p) );
|
||||
zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
|
||||
zText = sqlite3DbMallocRaw(p->db, 1+(u64)p->nChar );
|
||||
if( zText ){
|
||||
memcpy(zText, p->zText, p->nChar+1);
|
||||
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
|
||||
|
||||
@@ -1016,6 +1016,14 @@ typedef INT16_TYPE LogEst;
|
||||
#define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32))
|
||||
#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
|
||||
|
||||
/*
|
||||
** Macro SMXV(n) return the maximum value that can be held in variable n,
|
||||
** assuming n is a signed integer type. UMXV(n) is similar for unsigned
|
||||
** integer types.
|
||||
*/
|
||||
#define SMXV(n) ((((i64)1)<<(sizeof(n)-1))-1)
|
||||
#define UMXV(n) ((((i64)1)<<(sizeof(n)))-1)
|
||||
|
||||
/*
|
||||
** Round up a number to the next larger multiple of 8. This is used
|
||||
** to force 8-byte alignment on 64-bit architectures.
|
||||
|
||||
+5
-5
@@ -276,7 +276,7 @@ static VdbeCursor *allocateCursor(
|
||||
*/
|
||||
Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
|
||||
|
||||
int nByte;
|
||||
i64 nByte;
|
||||
VdbeCursor *pCx = 0;
|
||||
nByte =
|
||||
ROUND8P(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
|
||||
@@ -304,7 +304,7 @@ static VdbeCursor *allocateCursor(
|
||||
pMem->szMalloc = 0;
|
||||
return 0;
|
||||
}
|
||||
pMem->szMalloc = nByte;
|
||||
pMem->szMalloc = (int)nByte;
|
||||
}
|
||||
|
||||
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
|
||||
@@ -7325,7 +7325,7 @@ case OP_RowSetTest: { /* jump, in1, in3 */
|
||||
*/
|
||||
case OP_Program: { /* jump0 */
|
||||
int nMem; /* Number of memory registers for sub-program */
|
||||
int nByte; /* Bytes of runtime space required for sub-program */
|
||||
i64 nByte; /* Bytes of runtime space required for sub-program */
|
||||
Mem *pRt; /* Register to allocate runtime space */
|
||||
Mem *pMem; /* Used to iterate through memory cells */
|
||||
Mem *pEnd; /* Last memory cell in new array */
|
||||
@@ -7376,7 +7376,7 @@ case OP_Program: { /* jump0 */
|
||||
nByte = ROUND8(sizeof(VdbeFrame))
|
||||
+ nMem * sizeof(Mem)
|
||||
+ pProgram->nCsr * sizeof(VdbeCursor*)
|
||||
+ (pProgram->nOp + 7)/8;
|
||||
+ (7 + (i64)pProgram->nOp)/8;
|
||||
pFrame = sqlite3DbMallocZero(db, nByte);
|
||||
if( !pFrame ){
|
||||
goto no_mem;
|
||||
@@ -7384,7 +7384,7 @@ case OP_Program: { /* jump0 */
|
||||
sqlite3VdbeMemRelease(pRt);
|
||||
pRt->flags = MEM_Blob|MEM_Dyn;
|
||||
pRt->z = (char*)pFrame;
|
||||
pRt->n = nByte;
|
||||
pRt->n = (int)nByte;
|
||||
pRt->xDel = sqlite3VdbeFrameMemDel;
|
||||
|
||||
pFrame->v = p;
|
||||
|
||||
+5
-2
@@ -2233,7 +2233,9 @@ int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
|
||||
Column *pCol = &p->pTab->aCol[iIdx];
|
||||
if( pCol->iDflt>0 ){
|
||||
if( p->apDflt==0 ){
|
||||
int nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
|
||||
int nByte;
|
||||
assert( sizeof(sqlite3_value*)*UMXV(p->pTab->nCol) < 0x7fffffff );
|
||||
nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
|
||||
p->apDflt = (sqlite3_value**)sqlite3DbMallocZero(db, nByte);
|
||||
if( p->apDflt==0 ) goto preupdate_old_out;
|
||||
}
|
||||
@@ -2383,7 +2385,8 @@ int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
|
||||
*/
|
||||
assert( p->op==SQLITE_UPDATE );
|
||||
if( !p->aNew ){
|
||||
p->aNew = (Mem *)sqlite3DbMallocZero(db, sizeof(Mem) * p->pCsr->nField);
|
||||
assert( sizeof(Mem)*UMXV(p->pCsr->nField) < 0x7fffffff );
|
||||
p->aNew = (Mem *)sqlite3DbMallocZero(db, sizeof(Mem)*p->pCsr->nField);
|
||||
if( !p->aNew ){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto preupdate_new_out;
|
||||
|
||||
+3
-2
@@ -726,7 +726,7 @@ static Op *opIterNext(VdbeOpIter *p){
|
||||
}
|
||||
|
||||
if( pRet->p4type==P4_SUBPROGRAM ){
|
||||
int nByte = (p->nSub+1)*sizeof(SubProgram*);
|
||||
i64 nByte = (1+(u64)p->nSub)*sizeof(SubProgram*);
|
||||
int j;
|
||||
for(j=0; j<p->nSub; j++){
|
||||
if( p->apSub[j]==pRet->p4.pProgram ) break;
|
||||
@@ -1198,7 +1198,7 @@ void sqlite3VdbeScanStatus(
|
||||
const char *zName /* Name of table or index being scanned */
|
||||
){
|
||||
if( IS_STMT_SCANSTATUS(p->db) ){
|
||||
sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
|
||||
i64 nByte = (1+(i64)p->nScan) * sizeof(ScanStatus);
|
||||
ScanStatus *aNew;
|
||||
aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
|
||||
if( aNew ){
|
||||
@@ -4219,6 +4219,7 @@ UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
|
||||
){
|
||||
UnpackedRecord *p; /* Unpacked record to return */
|
||||
int nByte; /* Number of bytes required for *p */
|
||||
assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
|
||||
nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
|
||||
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
|
||||
if( !p ) return 0;
|
||||
|
||||
+2
-2
@@ -1440,7 +1440,7 @@ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
|
||||
|
||||
if( pRec==0 ){
|
||||
Index *pIdx = p->pIdx; /* Index being probed */
|
||||
int nByte; /* Bytes of space to allocate */
|
||||
i64 nByte; /* Bytes of space to allocate */
|
||||
int i; /* Counter variable */
|
||||
int nCol = pIdx->nColumn; /* Number of index columns including rowid */
|
||||
|
||||
@@ -1506,7 +1506,7 @@ static int valueFromFunction(
|
||||
){
|
||||
sqlite3_context ctx; /* Context object for function invocation */
|
||||
sqlite3_value **apVal = 0; /* Function arguments */
|
||||
int nVal = 0; /* Size of apVal[] array */
|
||||
int nVal = 0; /* Number of function arguments */
|
||||
FuncDef *pFunc = 0; /* Function definition */
|
||||
sqlite3_value *pVal = 0; /* New value */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
|
||||
+4
-2
@@ -936,7 +936,7 @@ int sqlite3VdbeSorterInit(
|
||||
VdbeSorter *pSorter; /* The new sorter */
|
||||
KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
|
||||
int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
|
||||
int sz; /* Size of pSorter in bytes */
|
||||
i64 sz; /* Size of pSorter in bytes */
|
||||
int rc = SQLITE_OK;
|
||||
#if SQLITE_MAX_WORKER_THREADS==0
|
||||
# define nWorker 0
|
||||
@@ -964,6 +964,8 @@ int sqlite3VdbeSorterInit(
|
||||
assert( pCsr->pKeyInfo );
|
||||
assert( !pCsr->isEphemeral );
|
||||
assert( pCsr->eCurType==CURTYPE_SORTER );
|
||||
assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
|
||||
< 0x7fffffff );
|
||||
szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
|
||||
sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
|
||||
|
||||
@@ -1177,7 +1179,7 @@ static int vdbeSorterJoinAll(VdbeSorter *pSorter, int rcin){
|
||||
*/
|
||||
static MergeEngine *vdbeMergeEngineNew(int nReader){
|
||||
int N = 2; /* Smallest power of two >= nReader */
|
||||
int nByte; /* Total bytes of space to allocate */
|
||||
i64 nByte; /* Total bytes of space to allocate */
|
||||
MergeEngine *pNew; /* Pointer to allocated object to return */
|
||||
|
||||
assert( nReader<=SORTER_MAX_MERGE_COUNT );
|
||||
|
||||
@@ -753,7 +753,7 @@ static SQLITE_NOINLINE int walIndexPageRealloc(
|
||||
|
||||
/* Enlarge the pWal->apWiData[] array if required */
|
||||
if( pWal->nWiData<=iPage ){
|
||||
sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
|
||||
sqlite3_int64 nByte = sizeof(u32*)*(1+(i64)iPage);
|
||||
volatile u32 **apNew;
|
||||
apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte);
|
||||
if( !apNew ){
|
||||
|
||||
Reference in New Issue
Block a user