From: drh Date: Sat, 14 Aug 2010 16:02:52 +0000 (+0000) Subject: Minor simplifications to btree.c in support of full-coverage testing. X-Git-Tag: version-3.7.2~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d433ce2ab4fd9f22a8c4f3da3c76c233dd2cb7f;p=thirdparty%2Fsqlite.git Minor simplifications to btree.c in support of full-coverage testing. FossilOrigin-Name: 364df6c7735447cc2187923918a35bf62d82decc --- diff --git a/manifest b/manifest index f4cb648b96..9ab23c533a 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Tweaks\sto\scomments\sin\spager.c.\s\sFix\stwo\scompiler\swarnings. -D 2010-08-14T12:42:45 +C Minor\ssimplifications\sto\sbtree.c\sin\ssupport\sof\sfull-coverage\stesting. +D 2010-08-14T16:02:52 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -116,7 +116,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 51d83300fe0baee39405c416ceb19a58ed30a8ed F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef F src/btmutex.c 96a12f50f7a17475155971a241d85ec5171573ff -F src/btree.c 042a5c0a6a8b6121019b258737872b1ab703d39e +F src/btree.c 4d861dd1620afb925cd4192bbf37ae9adb0f9fa1 F src/btree.h b4ba2fdf6b64c7c376bdfffa826af6b786b151d9 F src/btreeInt.h 5b034ff54800046cc5870605d683ac1f9134bd99 F src/build.c 0018d49629fc4807100c988dd191dd95e185bb38 @@ -846,14 +846,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P d8bbab78fa56b076dfafb36daa7d6ef0b07f9a44 -R 00ed3364cfce8a4105ed9a3a25cad7ed +P 68a49f7fe382e4d36e1259cdeec956c942906ddb +R b1c481dfca4b477e31b2e4af146892a8 U drh -Z 25d17dd4620d7e65e11d0b88322d1479 +Z e57dcfeb0f939d5ce958fed0088bea4e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMZo9IoxKgR168RlERAp1LAJwOT7m3IIp+K8QF3N/Nj+jyeFSJlACfXB9z -d6d5VsCmNb5RNvHYenT8x/U= -=t0vs +iD8DBQFMZr4voxKgR168RlERAu/MAJ9MTU0aCRWDXO4vBzXH44vQSjsLvwCfTpi/ +5wlpXOWGqiiDyRwwIlXwR/I= +=job1 -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 276b1bf56c..05f2f669e2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -68a49f7fe382e4d36e1259cdeec956c942906ddb \ No newline at end of file +364df6c7735447cc2187923918a35bf62d82decc \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 312f1ef987..9ccf5500e7 100644 --- a/src/btree.c +++ b/src/btree.c @@ -32,7 +32,16 @@ int sqlite3BtreeTrace=1; /* True to enable tracing */ # define TRACE(X) #endif - +/* +** Extract a 2-byte big-endian integer from an array of unsigned bytes. +** But if the value is zero, make it 65536. +** +** This routine is used to extract the "offset to cell content area" value +** from the header of a btree page. If the page size is 65536 and the page +** is empty, the offset should be 65536, but the 2-byte value stores zero. +** This routine makes the necessary adjustment to 65536. +*/ +#define get2byteNotZero(X) (((((int)get2byte(X))-1)&0xffff)+1) #ifndef SQLITE_OMIT_SHARED_CACHE /* @@ -1154,8 +1163,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ nFrag = data[hdr+7]; assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); gap = pPage->cellOffset + 2*pPage->nCell; - top = get2byte(&data[hdr+5]); - if( top==0 ) top = 65536; + top = get2byteNotZero(&data[hdr+5]); if( gap>top ) return SQLITE_CORRUPT_BKPT; testcase( gap+2==top ); testcase( gap+1==top ); @@ -1165,8 +1173,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ /* Always defragment highly fragmented pages */ rc = defragmentPage(pPage); if( rc ) return rc; - top = get2byte(&data[hdr+5]); - if( top==0 ) top = 65536; + top = get2byteNotZero(&data[hdr+5]); }else if( gap+2<=top ){ /* Search the freelist looking for a free slot big enough to satisfy ** the request. The allocation is made from the first free slot in @@ -1208,8 +1215,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ if( gap+2+nByte>top ){ rc = defragmentPage(pPage); if( rc ) return rc; - top = get2byte(&data[hdr+5]); - if( top==0 ) top = 65536; + top = get2byteNotZero(&data[hdr+5]); assert( gap+nByte<=top ); } @@ -1392,8 +1398,7 @@ static int btreeInitPage(MemPage *pPage){ pPage->nOverflow = 0; usableSize = pBt->usableSize; pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf; - top = get2byte(&data[hdr+5]); - if( top==0 ) top = 65536; + top = get2byteNotZero(&data[hdr+5]); pPage->nCell = get2byte(&data[hdr+3]); if( pPage->nCell>MX_CELL(pBt) ){ /* To many cells for a single page. The page must be corrupt */ @@ -5490,7 +5495,7 @@ static void assemblePage( /* Check that the page has just been zeroed by zeroPage() */ assert( pPage->nCell==0 ); - assert( get2byte(&data[hdr+5])==(nUsable&0xffff) ); + assert( get2byteNotZero(&data[hdr+5])==nUsable ); pCellptr = &data[pPage->cellOffset + nCell*2]; cellbody = nUsable; @@ -5556,7 +5561,8 @@ static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){ assert( sqlite3PagerIswriteable(pParent->pDbPage) ); assert( pPage->nOverflow==1 ); - if( pPage->nCell<=0 ) return SQLITE_CORRUPT_BKPT; + /* This error condition is now caught prior to reaching this function */ + if( NEVER(pPage->nCell<=0) ) return SQLITE_CORRUPT_BKPT; /* Allocate a new page. This page will become the right-sibling of ** pPage. Make the parent page writable, so that the new divider cell @@ -7665,8 +7671,7 @@ static int checkTreePage( if( hit==0 ){ pCheck->mallocFailed = 1; }else{ - int contentOffset = get2byte(&data[hdr+5]); - if( contentOffset==0 ) contentOffset = 65536; + int contentOffset = get2byteNotZero(&data[hdr+5]); assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */ memset(hit+contentOffset, 0, usableSize-contentOffset); memset(hit, 1, contentOffset);