1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Simplifications and additional testcase() macros for btree.c. (CVS 6866)

FossilOrigin-Name: 1b8c3a8246a5d8b8f5607014f68483735a403249
This commit is contained in:
drh
2009-07-09 02:24:35 +00:00
parent 4e6604ee80
commit df35a08cb7
3 changed files with 16 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\stypo\sin\s(6861):\s"ifndef\sSQLITE_TEST"\s->\s"ifdef\sSQLITE_TEST".\s(CVS\s6865) C Simplifications\sand\sadditional\stestcase()\smacros\sfor\sbtree.c.\s(CVS\s6866)
D 2009-07-08T18:50:55 D 2009-07-09T02:24:35
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in df9359da7a726ccb67a45db905c5447d5c00c6ef F Makefile.in df9359da7a726ccb67a45db905c5447d5c00c6ef
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -106,7 +106,7 @@ F src/auth.c 802a9439dfa0b8c208b10055cba400e82ef18025
F src/backup.c 6f1c2d9862c8a3feb7739dfcca02c1f5352e37f3 F src/backup.c 6f1c2d9862c8a3feb7739dfcca02c1f5352e37f3
F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119 F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119
F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c
F src/btree.c 92c2f9f56945f99689c192835b6b9798c288a8d0 F src/btree.c 3a97e228379449fcba6a18e88e425bcf433b1fe5
F src/btree.h e761619e76a1125d2d82bd3613b5a7ac7d1ee6f7 F src/btree.h e761619e76a1125d2d82bd3613b5a7ac7d1ee6f7
F src/btreeInt.h b31e5ac04181c7e2892c33ab06228c551df6233c F src/btreeInt.h b31e5ac04181c7e2892c33ab06228c551df6233c
F src/build.c 867028ee9f63f7bc8eb8d4a720bb98cf9b9a12b4 F src/build.c 867028ee9f63f7bc8eb8d4a720bb98cf9b9a12b4
@@ -740,7 +740,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
P 11e295ccd28fe669ee74c846db507040895a5e5b P 890dbab28c3a1af4a1e01221318c9200574139e7
R 803ee0767a7dc1fdc299bc39b74c00c2 R ecc6dc57b5c33bedd235ae3d99ecd320
U danielk1977 U drh
Z a4c2be0dc958ea0cc1e9ee2a49c75ee8 Z 320c447326253cde8031c4d1800cda60

View File

@@ -1 +1 @@
890dbab28c3a1af4a1e01221318c9200574139e7 1b8c3a8246a5d8b8f5607014f68483735a403249

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.665 2009/07/08 18:50:55 danielk1977 Exp $ ** $Id: btree.c,v 1.666 2009/07/09 02:24:35 drh Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -4561,7 +4561,8 @@ static int allocateBtreePage(
pPage1 = pBt->pPage1; pPage1 = pBt->pPage1;
mxPage = pagerPagecount(pBt); mxPage = pagerPagecount(pBt);
n = get4byte(&pPage1->aData[36]); n = get4byte(&pPage1->aData[36]);
if( n>mxPage ){ testcase( n==mxPage-1 );
if( n>=mxPage ){
return SQLITE_CORRUPT_BKPT; return SQLITE_CORRUPT_BKPT;
} }
if( n>0 ){ if( n>0 ){
@@ -4605,6 +4606,7 @@ static int allocateBtreePage(
}else{ }else{
iTrunk = get4byte(&pPage1->aData[32]); iTrunk = get4byte(&pPage1->aData[32]);
} }
testcase( iTrunk==mxPage );
if( iTrunk>mxPage ){ if( iTrunk>mxPage ){
rc = SQLITE_CORRUPT_BKPT; rc = SQLITE_CORRUPT_BKPT;
}else{ }else{
@@ -4616,6 +4618,7 @@ static int allocateBtreePage(
} }
k = get4byte(&pTrunk->aData[4]); k = get4byte(&pTrunk->aData[4]);
testcase( k==(u32)(pBt->usableSize/4 - 2) );
if( k==0 && !searchList ){ if( k==0 && !searchList ){
/* The trunk has no leaves and the list is not being searched. /* The trunk has no leaves and the list is not being searched.
** So extract the trunk page itself and use it as the newly ** So extract the trunk page itself and use it as the newly
@@ -4663,6 +4666,7 @@ static int allocateBtreePage(
rc = SQLITE_CORRUPT_BKPT; rc = SQLITE_CORRUPT_BKPT;
goto end_allocate_page; goto end_allocate_page;
} }
testcase( iNewTrunk==mxPage );
rc = sqlite3BtreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0); rc = sqlite3BtreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
goto end_allocate_page; goto end_allocate_page;
@@ -4718,20 +4722,15 @@ static int allocateBtreePage(
} }
iPage = get4byte(&aData[8+closest*4]); iPage = get4byte(&aData[8+closest*4]);
testcase( iPage==mxPage );
if( iPage>mxPage ){ if( iPage>mxPage ){
rc = SQLITE_CORRUPT_BKPT; rc = SQLITE_CORRUPT_BKPT;
goto end_allocate_page; goto end_allocate_page;
} }
testcase( iPage==mxPage );
if( !searchList || iPage==nearby ){ if( !searchList || iPage==nearby ){
int noContent; int noContent;
Pgno nPage;
*pPgno = iPage; *pPgno = iPage;
nPage = pagerPagecount(pBt);
if( iPage>nPage ){
/* Free page off the end of the file */
rc = SQLITE_CORRUPT_BKPT;
goto end_allocate_page;
}
TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d" TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d"
": %d more free pages\n", ": %d more free pages\n",
*pPgno, closest+1, k, pTrunk->pgno, n-1)); *pPgno, closest+1, k, pTrunk->pgno, n-1));