From: drh Date: Wed, 10 Dec 2008 16:45:50 +0000 (+0000) Subject: Add explicit casts to silence nuisance warnings from VC++. (CVS 6004) X-Git-Tag: version-3.6.10~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f49661a4ebacce2681d126675ed7fc187ff23410;p=thirdparty%2Fsqlite.git Add explicit casts to silence nuisance warnings from VC++. (CVS 6004) FossilOrigin-Name: da1cbfa766f7f379c01f4ac9c1210462d8d7c590 --- diff --git a/manifest b/manifest index 648d7be4c3..ebaffa9d74 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\smemcpy()\srather\sthan\s"="\sto\scopy\sa\sstructure,\sin\sorder\sto\swork\saround\na\sbug\sin\sthe\sXLC\scompiler\son\sAIX.\s\sTicket\s#3344.\s(CVS\s6003) -D 2008-12-10T11:49:06 +C Add\sexplicit\scasts\sto\ssilence\snuisance\swarnings\sfrom\sVC++.\s(CVS\s6004) +D 2008-12-10T16:45:51 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in f7e4c81c347b04f7b0f1c1b081a168645d7b8af7 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -95,14 +95,14 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc F sqlite3.def a1be7b9a4b8b51ac41c6ff6e8e44a14ef66b338b F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad F src/alter.c 0a00c184052b7fd20271e783f65fec4efec6fe30 -F src/analyze.c 301a1358f4f4d84d96608927d8ddcf471c53ad9a -F src/attach.c 85c6a3d0daf11965b47604190d7cf5597dc88382 +F src/analyze.c c86fd6a1425b22b3a46ce72ad403e4280026364f +F src/attach.c 1c35f95da3c62d19de75b44cfefd12c81c1791b3 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/bitvec.c 4300d311b17fb3c1476623fd895a8feac02a0b08 F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a -F src/btree.c 05fae412abe4f72aa52611f5a7180b73f2414d99 +F src/btree.c ba7baa987f9723882ef4655886327622e02a497f F src/btree.h 179c3ea813780df78a289a8f5130db18e6d4616e -F src/btreeInt.h 8d21590c97b6a2c00cce1f78ed5dc5756e835108 +F src/btreeInt.h 7ef2c872371d7508657f8d7a4efe651c741d6ee6 F src/build.c ce642b06016d94b0dbc34d379bac82b597baf8d5 F src/callback.c e970e5beddbdb23f89a6d05cb1a6419d9f755624 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c @@ -119,7 +119,7 @@ F src/insert.c 73c4b33767d9540f8ead5d903504ed93f48ad147 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3 F src/loadext.c 2f53996c693a347edc2d773e9217dde49d96ae64 -F src/main.c 331b2652e72ae64918d2347c7a96c5ed770b6f19 +F src/main.c 12b674019503ad90649cd8e6295425ef3078ce12 F src/malloc.c 89c7c58fbec06b80101fdc6dcdf9ee849b7cd7ac F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c F src/mem1.c bb8e26adde7d463270e961f045802c61dbabc8f1 @@ -139,8 +139,8 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c 36196e71292a44bf2d393413cd8c86199694b8b4 F src/os_unix.c cec838fe55eaa53f1ff02ecb311cdd2188c4db95 F src/os_win.c 79e55bbe2177c4824d24d365b1274703c710f504 -F src/pager.c a193da9e271898077de815819e4c29fc2b6ece2a -F src/pager.h a02ef8e6cc7e78b54874166e5ce786c9d4c489bf +F src/pager.c e72e92d44365d75563d26957e6ba4a2ec0796da5 +F src/pager.h 37f5173612b7803f44656c16e80df3280234bb18 F src/parse.y 1f4b7ad690864911919da0c76fa96fd72694185e F src/pcache.c 16dc8da6e6ba6250f8dfd9ee46036db1cbceedc6 F src/pcache.h f20c3e82dd6da622c3fe296170cb1801f9a2d75a @@ -664,7 +664,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P d1d05e2a8a6e474e4921742ba055200d7f4d21ce -R 3cb1e54e772a65be57b4db65ef2876e3 +P 18bbcafc16bb985a7c74e07ffb9c4f28273a7cfd +R 16b9d8cfa7d0b4c8f37a0a76a742de3d U drh -Z 967f0ee55c615c78cea9e570be2fe2d2 +Z 23fbcb130f7b999f989b3af42a01d87f diff --git a/manifest.uuid b/manifest.uuid index 80d70010ef..b9620763a2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -18bbcafc16bb985a7c74e07ffb9c4f28273a7cfd \ No newline at end of file +da1cbfa766f7f379c01f4ac9c1210462d8d7c590 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index b7f65dbebb..b4422e7ea5 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code associated with the ANALYZE command. ** -** @(#) $Id: analyze.c,v 1.46 2008/11/19 16:52:44 danielk1977 Exp $ +** @(#) $Id: analyze.c,v 1.47 2008/12/10 16:45:51 drh Exp $ */ #ifndef SQLITE_OMIT_ANALYZE #include "sqliteInt.h" @@ -33,7 +33,7 @@ static void openStatTable( sqlite3 *db = pParse->db; Db *pDb; int iRootPage; - int createStat1 = 0; + u8 createStat1 = 0; Table *pStat; Vdbe *v = sqlite3GetVdbe(pParse); diff --git a/src/attach.c b/src/attach.c index ccf1463f29..2a7525ae93 100644 --- a/src/attach.c +++ b/src/attach.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.80 2008/11/19 09:05:27 danielk1977 Exp $ +** $Id: attach.c,v 1.81 2008/12/10 16:45:51 drh Exp $ */ #include "sqliteInt.h" @@ -335,7 +335,8 @@ static void codeAttach( assert( v || db->mallocFailed ); if( v ){ sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3); - sqlite3VdbeChangeP5(v, pFunc->nArg); + assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg ); + sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg)); sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF); /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this diff --git a/src/btree.c b/src/btree.c index 75090d002b..3f1287394f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.545 2008/12/05 22:40:08 drh Exp $ +** $Id: btree.c,v 1.546 2008/12/10 16:45:51 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -316,9 +316,9 @@ static int saveCursorPosition(BtCursor *pCur){ ** data. */ if( rc==SQLITE_OK && 0==pCur->apPage[0]->intKey){ - void *pKey = sqlite3Malloc(pCur->nKey); + void *pKey = sqlite3Malloc( (int)pCur->nKey ); if( pKey ){ - rc = sqlite3BtreeKey(pCur, 0, pCur->nKey, pKey); + rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); if( rc==SQLITE_OK ){ pCur->pKey = pKey; }else{ @@ -575,7 +575,7 @@ void sqlite3BtreeParseCellPtr( u8 *pCell, /* Pointer to the cell text. */ CellInfo *pInfo /* Fill in this structure */ ){ - int n; /* Number bytes in cell content header */ + u16 n; /* Number bytes in cell content header */ u32 nPayload; /* Number of bytes of cell payload */ assert( sqlite3_mutex_held(pPage->pBt->mutex) ); @@ -590,7 +590,7 @@ void sqlite3BtreeParseCellPtr( }else{ nPayload = 0; } - n += getVarint(&pCell[n], (u64*)&pInfo->nKey); + n += (u16)getVarint(&pCell[n], (u64*)&pInfo->nKey); pInfo->nData = nPayload; }else{ pInfo->nData = 0; @@ -605,12 +605,12 @@ void sqlite3BtreeParseCellPtr( */ int nSize; /* Total size of cell content in bytes */ nSize = nPayload + n; - pInfo->nLocal = nPayload; + pInfo->nLocal = (u16)nPayload; pInfo->iOverflow = 0; if( (nSize & ~3)==0 ){ nSize = 4; /* Minimum cell size is 4 */ } - pInfo->nSize = nSize; + pInfo->nSize = (int)nSize; }else{ /* If the payload will not fit completely on the local page, we have ** to decide how much to store locally and how much to spill onto @@ -629,11 +629,11 @@ void sqlite3BtreeParseCellPtr( maxLocal = pPage->maxLocal; surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize - 4); if( surplus <= maxLocal ){ - pInfo->nLocal = surplus; + pInfo->nLocal = (u16)surplus; }else{ - pInfo->nLocal = minLocal; + pInfo->nLocal = (u16)minLocal; } - pInfo->iOverflow = pInfo->nLocal + n; + pInfo->iOverflow = (u16)(pInfo->nLocal + n); pInfo->nSize = pInfo->iOverflow + 4; } } @@ -789,7 +789,7 @@ static int allocateSpace(MemPage *pPage, int nByte){ assert( nByte>=0 ); /* Minimum cell size is 4 */ assert( pPage->nFree>=nByte ); assert( pPage->nOverflow==0 ); - pPage->nFree -= nByte; + pPage->nFree -= (u16)nByte; hdr = pPage->hdrOffset; nFrag = data[hdr+7]; @@ -800,13 +800,14 @@ static int allocateSpace(MemPage *pPage, int nByte){ while( (pc = get2byte(&data[addr]))>0 ){ size = get2byte(&data[pc+2]); if( size>=nByte ){ + int x = size - nByte; if( sizenFree += size; + pPage->nFree += (u16)size; /* Coalesce adjacent free blocks */ addr = pPage->hdrOffset + 1; while( (pbegin = get2byte(&data[addr]))>0 ){ - int pnext, psize; + int pnext, psize, x; assert( pbegin>addr ); assert( pbegin<=pPage->pBt->usableSize-4 ); pnext = get2byte(&data[pbegin]); psize = get2byte(&data[pbegin+2]); if( pbegin + psize + 3 >= pnext && pnext>0 ){ int frag = pnext - (pbegin+psize); - if( (frag<0) || (frag>data[pPage->hdrOffset+7]) ){ + if( (frag<0) || (frag>(int)data[pPage->hdrOffset+7]) ){ return SQLITE_CORRUPT_BKPT; } - data[pPage->hdrOffset+7] -= frag; - put2byte(&data[pbegin], get2byte(&data[pnext])); - put2byte(&data[pbegin+2], pnext+get2byte(&data[pnext+2])-pbegin); + data[pPage->hdrOffset+7] -= (u8)frag; + x = get2byte(&data[pnext]); + put2byte(&data[pbegin], x); + x = pnext + get2byte(&data[pnext+2]) - pbegin; + put2byte(&data[pbegin+2], x); }else{ addr = pbegin; } @@ -900,8 +903,8 @@ static int freeSpace(MemPage *pPage, int start, int size){ int top; pbegin = get2byte(&data[hdr+1]); memcpy(&data[hdr+1], &data[pbegin], 2); - top = get2byte(&data[hdr+5]); - put2byte(&data[hdr+5], top + get2byte(&data[pbegin+2])); + top = get2byte(&data[hdr+5]) + get2byte(&data[pbegin+2]); + put2byte(&data[hdr+5], top); } assert( sqlite3PagerIswriteable(pPage->pDbPage) ); return SQLITE_OK; @@ -924,7 +927,7 @@ static int decodeFlags(MemPage *pPage, int flagByte){ assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); - pPage->leaf = flagByte>>3; assert( PTF_LEAF == 1<<3 ); + pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 ); flagByte &= ~PTF_LEAF; pPage->childPtrSize = 4-4*pPage->leaf; pBt = pPage->pBt; @@ -962,14 +965,14 @@ int sqlite3BtreeInitPage(MemPage *pPage){ assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) ); if( !pPage->isInit ){ - int pc; /* Address of a freeblock within pPage->aData[] */ - int hdr; /* Offset to beginning of page header */ + u16 pc; /* Address of a freeblock within pPage->aData[] */ + u8 hdr; /* Offset to beginning of page header */ u8 *data; /* Equal to pPage->aData */ BtShared *pBt; /* The main btree structure */ - int usableSize; /* Amount of usable space on each page */ - int cellOffset; /* Offset from start of page to first cell pointer */ - int nFree; /* Number of unused bytes on the page */ - int top; /* First byte of the cell content area */ + u16 usableSize; /* Amount of usable space on each page */ + u16 cellOffset; /* Offset from start of page to first cell pointer */ + u16 nFree; /* Number of unused bytes on the page */ + u16 top; /* First byte of the cell content area */ pBt = pPage->pBt; @@ -1006,7 +1009,7 @@ int sqlite3BtreeInitPage(MemPage *pPage){ nFree += size; pc = next; } - pPage->nFree = nFree; + pPage->nFree = (u16)nFree; if( nFree>=usableSize ){ /* Free space cannot exceed total page size */ return SQLITE_CORRUPT_BKPT; @@ -1044,8 +1047,8 @@ int sqlite3BtreeInitPage(MemPage *pPage){ static void zeroPage(MemPage *pPage, int flags){ unsigned char *data = pPage->aData; BtShared *pBt = pPage->pBt; - int hdr = pPage->hdrOffset; - int first; + u8 hdr = pPage->hdrOffset; + u16 first; assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); @@ -1237,7 +1240,7 @@ int sqlite3BtreeOpen( BtShared *pBt = 0; /* Shared part of btree structure */ Btree *p; /* Handle to return */ int rc = SQLITE_OK; - int nReserve; + u8 nReserve; unsigned char zDbHeader[100]; /* Set the variable isMemdb to true for an in-memory database, or @@ -1634,6 +1637,7 @@ int sqlite3BtreeSyncDisabled(Btree *p){ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){ int rc = SQLITE_OK; BtShared *pBt = p->pBt; + assert( nReserve>=-1 && nReserve<=255 ); sqlite3BtreeEnter(p); if( pBt->pageSizeFixed ){ sqlite3BtreeLeave(p); @@ -1642,6 +1646,7 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){ if( nReserve<0 ){ nReserve = pBt->pageSize - pBt->usableSize; } + assert( nReserve>=0 && nReserve<=255 ); if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE && ((pageSize-1)&pageSize)==0 ){ assert( (pageSize & 7)==0 ); @@ -1650,7 +1655,7 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){ freeTempSpace(pBt); rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize); } - pBt->usableSize = pBt->pageSize - nReserve; + pBt->usableSize = pBt->pageSize - (u16)nReserve; sqlite3BtreeLeave(p); return rc; } @@ -1695,7 +1700,7 @@ int sqlite3BtreeSetAutoVacuum(Btree *p, int autoVacuum){ #else BtShared *pBt = p->pBt; int rc = SQLITE_OK; - int av = (autoVacuum?1:0); + u8 av = autoVacuum ?1:0; sqlite3BtreeEnter(p); if( pBt->pageSizeFixed && av!=pBt->autoVacuum ){ @@ -1793,8 +1798,8 @@ static int lockBtree(BtShared *pBt){ ** again with the correct page-size. */ releasePage(pPage1); - pBt->usableSize = usableSize; - pBt->pageSize = pageSize; + pBt->usableSize = (u16)usableSize; + pBt->pageSize = (u16)pageSize; freeTempSpace(pBt); sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize); return SQLITE_OK; @@ -1915,7 +1920,8 @@ static int newDatabase(BtShared *pBt){ put2byte(&data[16], pBt->pageSize); data[18] = 1; data[19] = 1; - data[20] = pBt->pageSize - pBt->usableSize; + assert( pBt->usableSize<=pBt->pageSize && pBt->usableSize+255>=pBt->pageSize); + data[20] = (u8)(pBt->pageSize - pBt->usableSize); data[21] = 64; data[22] = 32; data[23] = 32; @@ -2070,7 +2076,7 @@ static int setChildPtrmaps(MemPage *pPage){ int nCell; /* Number of cells in page pPage */ int rc; /* Return code */ BtShared *pBt = pPage->pBt; - int isInitOrig = pPage->isInit; + u8 isInitOrig = pPage->isInit; Pgno pgno = pPage->pgno; assert( sqlite3_mutex_held(pPage->pBt->mutex) ); @@ -2130,7 +2136,7 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ } put4byte(pPage->aData, iTo); }else{ - int isInitOrig = pPage->isInit; + u8 isInitOrig = pPage->isInit; int i; int nCell; @@ -2813,6 +2819,7 @@ static int btreeCursor( BtShared *pBt = p->pBt; assert( sqlite3BtreeHoldsMutex(p) ); + assert( wrFlag==0 || wrFlag==1 ); if( wrFlag ){ if( pBt->readOnly ){ return SQLITE_READONLY; @@ -2852,7 +2859,7 @@ static int btreeCursor( pCur->pKeyInfo = pKeyInfo; pCur->pBtree = p; pCur->pBt = pBt; - pCur->wrFlag = wrFlag; + pCur->wrFlag = (u8)wrFlag; pCur->pNext = pBt->pCursor; if( pCur->pNext ){ pCur->pNext->pPrev = pCur; @@ -3215,7 +3222,7 @@ static int accessPayload( getCellInfo(pCur); aPayload = pCur->info.pCell + pCur->info.nHeader; - nKey = (pPage->intKey ? 0 : pCur->info.nKey); + nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey); if( skipKey ){ offset += nKey; @@ -3422,7 +3429,7 @@ static const unsigned char *fetchPayload( if( pPage->intKey ){ nKey = 0; }else{ - nKey = pCur->info.nKey; + nKey = (int)pCur->info.nKey; } if( skipKey ){ aPayload += nKey; @@ -3692,7 +3699,7 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){ *pRes = 0; rc = moveToRightmost(pCur); getCellInfo(pCur); - pCur->atLast = rc==SQLITE_OK; + pCur->atLast = rc==SQLITE_OK ?1:0; } } return rc; @@ -3776,9 +3783,9 @@ int sqlite3BtreeMovetoUnpacked( goto moveto_finish; } if( biasRight ){ - pCur->aiIdx[pCur->iPage] = upr; + pCur->aiIdx[pCur->iPage] = (u16)upr; }else{ - pCur->aiIdx[pCur->iPage] = (upr+lwr)/2; + pCur->aiIdx[pCur->iPage] = (u16)((upr+lwr)/2); } if( lwr<=upr ) for(;;){ void *pCellKey; @@ -3807,14 +3814,14 @@ int sqlite3BtreeMovetoUnpacked( pCellKey = (void *)fetchPayload(pCur, &available, 0); nCellKey = pCur->info.nKey; if( available>=nCellKey ){ - c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pIdxKey); + c = sqlite3VdbeRecordCompare((int)nCellKey, pCellKey, pIdxKey); }else{ - pCellKey = sqlite3Malloc( nCellKey ); + pCellKey = sqlite3Malloc( (int)nCellKey ); if( pCellKey==0 ){ rc = SQLITE_NOMEM; goto moveto_finish; } - rc = sqlite3BtreeKey(pCur, 0, nCellKey, (void *)pCellKey); + rc = sqlite3BtreeKey(pCur, 0, (int)nCellKey, (void*)pCellKey); c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pIdxKey); sqlite3_free(pCellKey); if( rc ) goto moveto_finish; @@ -3841,7 +3848,7 @@ int sqlite3BtreeMovetoUnpacked( pCur->info.nKey = nCellKey; break; } - pCur->aiIdx[pCur->iPage] = (lwr+upr)/2; + pCur->aiIdx[pCur->iPage] = (u16)((lwr+upr)/2); } assert( lwr==upr+1 ); assert( pPage->isInit ); @@ -3858,7 +3865,7 @@ int sqlite3BtreeMovetoUnpacked( rc = SQLITE_OK; goto moveto_finish; } - pCur->aiIdx[pCur->iPage] = lwr; + pCur->aiIdx[pCur->iPage] = (u16)lwr; pCur->info.nSize = 0; pCur->validNKey = 0; rc = moveToChild(pCur, chldPg); @@ -3885,7 +3892,8 @@ int sqlite3BtreeMoveto( UnpackedRecord aSpace[16]; /* Temp space for pIdxKey - to avoid a malloc */ if( pKey ){ - pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, nKey, pKey, + assert( nKey==(i64)(int)nKey ); + pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, aSpace, sizeof(aSpace)); if( pIdxKey==0 ) return SQLITE_NOMEM; }else{ @@ -4513,10 +4521,11 @@ static int fillInCell( pSrc = pData; nSrc = nData; nData = 0; - }else{ - nPayload += nKey; + }else{ + /* TBD: Perhaps raise SQLITE_CORRUPT if nKey is larger than 31 bits? */ + nPayload += (int)nKey; pSrc = pKey; - nSrc = nKey; + nSrc = (int)nKey; } *pnSize = info.nSize; spaceLeft = info.nLocal; @@ -4525,7 +4534,6 @@ static int fillInCell( while( nPayload>0 ){ if( spaceLeft==0 ){ - int isExact = 0; #ifndef SQLITE_OMIT_AUTOVACUUM Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */ if( pBt->autoVacuum ){ @@ -4534,12 +4542,9 @@ static int fillInCell( } while( PTRMAP_ISPAGE(pBt, pgnoOvfl) || pgnoOvfl==PENDING_BYTE_PAGE(pBt) ); - if( pgnoOvfl>1 ){ - /* isExact = 1; */ - } } #endif - rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, isExact); + rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0); #ifndef SQLITE_OMIT_AUTOVACUUM /* If the database supports auto-vacuum, and the second or subsequent ** overflow page is being allocated, add an entry to the pointer-map @@ -4690,6 +4695,8 @@ static int insertCell( u8 *ptr; /* Used for moving information around in data[] */ assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); + assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 ); + assert( pPage->nOverflow<=ArraySize(pPage->aOvfl) ); assert( sz==cellSizePtr(pPage, pCell) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); if( pPage->nOverflow || sz+2>pPage->nFree ){ @@ -4700,7 +4707,7 @@ static int insertCell( j = pPage->nOverflow++; assert( j<(int)(sizeof(pPage->aOvfl)/sizeof(pPage->aOvfl[0])) ); pPage->aOvfl[j].pCell = pCell; - pPage->aOvfl[j].idx = i; + pPage->aOvfl[j].idx = (u16)i; pPage->nFree = 0; }else{ int rc = sqlite3PagerWrite(pPage->pDbPage); @@ -4776,6 +4783,7 @@ static void assemblePage( assert( pPage->nOverflow==0 ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); + assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 ); totalSize = 0; for(i=0; ipBt->usableSize ); } - pPage->nCell = nCell; + pPage->nCell = (u16)nCell; } /* @@ -5173,7 +5181,7 @@ static int balance_nonroot(BtCursor *pCur){ szCell[nCell] = cellSizePtr(pOld, apCell[nCell]); if( ISAUTOVACUUM ){ int a; - aFrom[nCell] = i; + aFrom[nCell] = (u8)i; assert( i>=0 && i<6 ); for(a=0; anOverflow; a++){ if( pOld->aOvfl[a].pCell==apCell[nCell] ){ aFrom[nCell] = 0xFF; @@ -5206,7 +5214,8 @@ static int balance_nonroot(BtCursor *pCur){ aFrom[nCell] = 0xFF; } dropCell(pParent, nxDiv, sz); - szCell[nCell] -= leafCorrection; + assert( leafCorrection==0 || leafCorrection==4 ); + szCell[nCell] -= (u16)leafCorrection; assert( get4byte(pTemp)==pgnoOld[i] ); if( !pOld->leaf ){ assert( leafCorrection==0 ); @@ -6598,7 +6607,7 @@ int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){ if( idx==7 ){ assert( pBt->autoVacuum || iMeta==0 ); assert( iMeta==0 || iMeta==1 ); - pBt->incrVacuum = iMeta; + pBt->incrVacuum = (u8)iMeta; } #endif } @@ -6857,7 +6866,7 @@ static int checkTreePage( pCell = findCell(pPage,i); sqlite3BtreeParseCellPtr(pPage, pCell, &info); sz = info.nData; - if( !pPage->intKey ) sz += info.nKey; + if( !pPage->intKey ) sz += (int)info.nKey; assert( sz==info.nPayload ); if( sz>info.nLocal ){ int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4); @@ -7173,8 +7182,8 @@ static int btreeCopyFile(Btree *pTo, Btree *pFrom){ /* Variable nNewPage is the number of pages required to store the ** contents of pFrom using the current page-size of pTo. */ - nNewPage = ((i64)nFromPage * (i64)nFromPageSize + (i64)nToPageSize - 1) / - (i64)nToPageSize; + nNewPage = (Pgno) + (((i64)nFromPage*(i64)nFromPageSize+(i64)nToPageSize-1)/(i64)nToPageSize); for(i=1; rc==SQLITE_OK && (i<=nToPage || i<=nNewPage); i++){ @@ -7223,7 +7232,7 @@ static int btreeCopyFile(Btree *pTo, Btree *pFrom){ iOff += nFromPageSize ){ DbPage *pFromPage = 0; - Pgno iFrom = (iOff/nFromPageSize)+1; + Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1; if( iFrom==PENDING_BYTE_PAGE(pBtFrom) ){ continue; @@ -7304,7 +7313,7 @@ static int btreeCopyFile(Btree *pTo, Btree *pFrom){ iOff += nFromPageSize ){ DbPage *pFromPage = 0; - Pgno iFrom = (iOff/nFromPageSize)+1; + Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1; if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom>nFromPage ){ continue; diff --git a/src/btreeInt.h b/src/btreeInt.h index dc702efc0a..4e4fefd3ba 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btreeInt.h,v 1.36 2008/11/19 10:22:33 danielk1977 Exp $ +** $Id: btreeInt.h,v 1.37 2008/12/10 16:45:51 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -375,10 +375,10 @@ struct BtShared { #endif u16 pageSize; /* Total number of bytes on a page */ u16 usableSize; /* Number of usable bytes on each page */ - int maxLocal; /* Maximum local payload in non-LEAFDATA tables */ - int minLocal; /* Minimum local payload in non-LEAFDATA tables */ - int maxLeaf; /* Maximum local payload in a LEAFDATA table */ - int minLeaf; /* Minimum local payload in a LEAFDATA table */ + u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ + u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ + u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ + u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ u8 inTransaction; /* Transaction state */ int nTransaction; /* Number of open transactions (read + write) */ void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ @@ -620,7 +620,7 @@ struct IntegrityCk { ** Read or write a two- and four-byte big-endian integer values. */ #define get2byte(x) ((x)[0]<<8 | (x)[1]) -#define put2byte(p,v) ((p)[0] = (v)>>8, (p)[1] = (v)) +#define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v)) #define get4byte sqlite3Get4byte #define put4byte sqlite3Put4byte diff --git a/src/main.c b/src/main.c index c019c0a01f..2aa29acfda 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.516 2008/12/09 14:46:10 drh Exp $ +** $Id: main.c,v 1.517 2008/12/10 16:45:51 drh Exp $ */ #include "sqliteInt.h" #include @@ -1201,12 +1201,15 @@ int sqlite3BtreeFactory( */ const char *sqlite3_errmsg(sqlite3 *db){ const char *z; - if( !db || db->mallocFailed ){ + if( !db ){ return sqlite3ErrStr(SQLITE_NOMEM); } if( !sqlite3SafetyCheckSickOrOk(db) ){ return sqlite3ErrStr(SQLITE_MISUSE); } + if( db->mallocFailed ){ + return sqlite3ErrStr(SQLITE_NOMEM); + } sqlite3_mutex_enter(db->mutex); assert( !db->mallocFailed ); z = (char*)sqlite3_value_text(db->pErr); diff --git a/src/pager.c b/src/pager.c index 5ea075e583..b95a0bf826 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.510 2008/11/29 22:49:23 drh Exp $ +** @(#) $Id: pager.c,v 1.511 2008/12/10 16:45:51 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -3825,7 +3825,7 @@ int sqlite3PagerRollback(Pager *pPager){ ** Return TRUE if the database file is opened read-only. Return FALSE ** if the database is (in theory) writable. */ -int sqlite3PagerIsreadonly(Pager *pPager){ +u8 sqlite3PagerIsreadonly(Pager *pPager){ return pPager->readOnly; } diff --git a/src/pager.h b/src/pager.h index e3437be70f..76d7067565 100644 --- a/src/pager.h +++ b/src/pager.h @@ -13,7 +13,7 @@ ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** -** @(#) $Id: pager.h,v 1.87 2008/11/19 10:22:33 danielk1977 Exp $ +** @(#) $Id: pager.h,v 1.88 2008/12/10 16:45:51 drh Exp $ */ #ifndef _PAGER_H_ @@ -93,7 +93,7 @@ int sqlite3PagerBegin(DbPage*, int exFlag); int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno, int); int sqlite3PagerCommitPhaseTwo(Pager*); int sqlite3PagerRollback(Pager*); -int sqlite3PagerIsreadonly(Pager*); +u8 sqlite3PagerIsreadonly(Pager*); int sqlite3PagerStmtBegin(Pager*); int sqlite3PagerStmtCommit(Pager*); int sqlite3PagerStmtRollback(Pager*);