From: drh Date: Fri, 3 Jan 2020 17:40:30 +0000 (+0000) Subject: Add NEVER macros to error-detection branches that were made unreachable X-Git-Tag: version-3.31.0~78 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b76c45a7fdfe80a13f8fec1d05afb008d79fc26;p=thirdparty%2Fsqlite.git Add NEVER macros to error-detection branches that were made unreachable (as far as I can tell) by check-in [ceacc28b03580334]. FossilOrigin-Name: 7b62555e285f32d354df7746ef8dce16856c6d9d53a02d895b74ba02362d2968 --- diff --git a/manifest b/manifest index d168aa34fa..5b6e4d66c3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvement\sto\scheck-in\s[7405e98225761180]\sso\sthat\smissing\sor\snull\sfilenames\ngiven\sto\sthe\szipfile\sextension\sthrow\san\simmediate\serror. -D 2020-01-03T16:38:54.215 +C Add\sNEVER\smacros\sto\serror-detection\sbranches\sthat\swere\smade\sunreachable\n(as\sfar\sas\sI\scan\stell)\sby\scheck-in\s[ceacc28b03580334]. +D 2020-01-03T17:40:30.845 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -469,7 +469,7 @@ F src/auth.c a3d5bfdba83d25abed1013a8c7a5f204e2e29b0c25242a56bc02bb0c07bf1e06 F src/backup.c f70077d40c08b7787bfe934e4d1da8030cb0cc57d46b345fba2294b7d1be23ab F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 0eb5d02aac9a6f6029904060db1986550bc99b40c5f8d9374d9bbcca0543164d +F src/btree.c df0ec5541fa5662a90082faea44322c5143db61f2e806375f4e3f5ab35d6cc41 F src/btree.h 6111552f19ed7a40f029cf4b33badc6fef9880314fffd80a945f0b7f43ab7471 F src/btreeInt.h 6794084fad08c9750b45145743c0e3e5c27c94dee89f26dd8df7073314934fd2 F src/build.c 67b1a8d3ac700747687dbdc49ded847a3c17fef450a8c919ac0399b44cbd4215 @@ -1853,7 +1853,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ceacc28b035803342764f9b696c1e80edcd259b87ea4fb46f92963d6cb33de3e -R b1b114b0553a0e4f445e7455b465ab9e +P 523e09bd228750fb7be1d4e68d18f6c1bf9db19293d66fbf30b86409321e9814 +R 9db325677ae78118554163eac3ed2eae U drh -Z 0a4493657ad671889aa7ad8712c9a995 +Z e0ea28a1a8dedd28fad05208e3f0151a diff --git a/manifest.uuid b/manifest.uuid index 66e080cf25..e4bdd27cd6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -523e09bd228750fb7be1d4e68d18f6c1bf9db19293d66fbf30b86409321e9814 \ No newline at end of file +7b62555e285f32d354df7746ef8dce16856c6d9d53a02d895b74ba02362d2968 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a3d9800f9e..67b91c5962 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1449,7 +1449,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ int sz2 = 0; int sz = get2byte(&data[iFree+2]); int top = get2byte(&data[hdr+5]); - if( top>=iFree ){ + if( NEVER(top>=iFree) ){ return SQLITE_CORRUPT_PAGE(pPage); } if( iFree2 ){ @@ -1458,7 +1458,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage); memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); sz += sz2; - }else if( iFree+sz>usableSize ){ + }else if( NEVER(iFree+sz>usableSize) ){ return SQLITE_CORRUPT_PAGE(pPage); } @@ -1650,8 +1650,10 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){ u8 *pSpace = pageFindSlot(pPage, nByte, &rc); if( pSpace ){ + int g2; assert( pSpace+nByte<=data+pPage->pBt->usableSize ); - if( (*pIdx = (int)(pSpace-data))<=gap ){ + *pIdx = g2 = (int)(pSpace-data); + if( NEVER(g2<=gap) ){ return SQLITE_CORRUPT_PAGE(pPage); }else{ return SQLITE_OK; @@ -1729,12 +1731,12 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ }else{ while( (iFreeBlk = get2byte(&data[iPtr]))pPage->pBt->usableSize-4 ){ + if( NEVER(iFreeBlk>pPage->pBt->usableSize-4) ){ return SQLITE_CORRUPT_PAGE(pPage); } assert( iFreeBlk>iPtr || iFreeBlk==0 ); @@ -1749,7 +1751,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ nFrag = iFreeBlk - iEnd; if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage); iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); - if( iEnd > pPage->pBt->usableSize ){ + if( NEVER(iEnd > pPage->pBt->usableSize) ){ return SQLITE_CORRUPT_PAGE(pPage); } iSize = iEnd - iStart; @@ -1777,7 +1779,8 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ /* The new freeblock is at the beginning of the cell content area, ** so just extend the cell content area rather than create another ** freelist entry */ - if( iStart(u32)usableSize ){ j = 0; } + if( NEVER(j>(u32)usableSize) ){ j = 0; } memcpy(&pTmp[j], &aData[j], usableSize - j); for(k=0; pCArray->ixNx[k]<=i && ALWAYS(kszCell[i]; assert( sz>0 ); if( SQLITE_WITHIN(pCell,aData,pEnd) ){ - if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT; + if( NEVER(((uptr)(pCell+sz))>(uptr)pEnd) ) return SQLITE_CORRUPT_BKPT; pCell = &pTmp[pCell - aData]; }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd && (uptr)(pCell)<(uptr)pSrcEnd @@ -6959,10 +6962,9 @@ static int rebuildPage( pData -= sz; put2byte(pCellptr, (pData - aData)); pCellptr += 2; - if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT; + if( NEVER(pData < pCellptr) ) return SQLITE_CORRUPT_BKPT; memcpy(pData, pCell, sz); - assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB ); - testcase( sz!=pPg->xCellSize(pPg,pCell) ); + assert( sz==pPg->xCellSize(pPg, pCell) ); i++; if( i>=iEnd ) break; if( pCArray->ixNx[k]<=i ){ @@ -7101,7 +7103,7 @@ static int pageFreeArray( } pFree = pCell; szFree = sz; - if( pFree+sz>pEnd ) return 0; + if( NEVER(pFree+sz>pEnd) ) return 0; }else{ pFree = pCell; szFree += sz;