From 96862072b843e2431f7723b972618982e7d395d5 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 31 Aug 2011 23:57:22 +0000 Subject: [PATCH] Avoid using uninitialized variables after failures in the merge sort code. FossilOrigin-Name: 2869ed28299b1c9f355ecc24635830f7f1249126 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbesort.c | 43 ++++++++++++++++++++++--------------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index cff029dee2..cf95f75fde 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Formerly,\swe\senabled\sfdatasync()\son\slinux\sonly.\s\sBut\snow\swe\slearn\sthat\nfdatasync()\sis\snot\ssupported\son\sAndroid.\s\sSo\swe\sdisable\sfdatasync()\son\nLinux\stoo.\s\sIt\scan\sbe\sreenabled\sat\scompile-time\sfor\sthose\swho\sreally\sneed\sit. -D 2011-08-31T21:01:55.686 +C Avoid\susing\suninitialized\svariables\safter\sfailures\sin\sthe\smerge\ssort\scode. +D 2011-08-31T23:57:22.695 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in d314143fa6be24828021d3f583ad37d9afdce505 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -245,7 +245,7 @@ F src/vdbeapi.c 11dc47987abacb76ad016dcf5abc0dc422482a98 F src/vdbeaux.c de1e4cab060a45df9ebee68dd63543d14559f0e7 F src/vdbeblob.c f024f0bf420f36b070143c32b15cc7287341ffd3 F src/vdbemem.c 5e6effb96dd53d233361cbfaa3f0a43b9af689e9 -F src/vdbesort.c 8a61a6d731cbe612217edf9eece6197f37c9489e +F src/vdbesort.c f3d043a1bab7409d4a23cd7a35287c3ac440a167 F src/vdbetrace.c 5d0dc3d5fd54878cc8d6d28eb41deb8d5885b114 F src/vtab.c 901791a47318c0562cd0c676a2c6ff1bc530e582 F src/wal.c 3154756177d6219e233d84291d5b05f4e06ff5e9 @@ -961,7 +961,7 @@ F tool/symbols.sh caaf6ccc7300fd43353318b44524853e222557d5 F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings.sh b7fdb2cc525f5ef4fa43c80e771636dd3690f9d2 -P 1b124af40a8fa4d3094f24a9213096b66411b8f9 -R e3c435a6ba2306a2d838c8b23577f672 +P 70b5b309568ac55565558d5456aca1e431cfd26b +R 09e04eb9163c46e529a61f2438cff2a1 U drh -Z 9e7ae74ddd5128c7f3fb2205f914d095 +Z bdb2832352809bf647849d42b7aa6060 diff --git a/manifest.uuid b/manifest.uuid index 5cdc6053a0..67e9d42efe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -70b5b309568ac55565558d5456aca1e431cfd26b \ No newline at end of file +2869ed28299b1c9f355ecc24635830f7f1249126 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index be99d397d3..c3214b3afe 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -142,8 +142,8 @@ static int vdbeSorterIterNext( ){ int rc; /* Return Code */ int nRead; /* Number of bytes read */ - int nRec; /* Size of record in bytes */ - int iOff; /* Size of serialized size varint in bytes */ + int nRec = 0; /* Size of record in bytes */ + int iOff = 0; /* Size of serialized size varint in bytes */ nRead = pIter->iEof - pIter->iReadOff; if( nRead>5 ) nRead = 5; @@ -154,25 +154,26 @@ static int vdbeSorterIterNext( } rc = sqlite3OsRead(pIter->pFile, pIter->aAlloc, nRead, pIter->iReadOff); - iOff = getVarint32(pIter->aAlloc, nRec); - - if( rc==SQLITE_OK && (iOff+nRec)>nRead ){ - int nRead2; /* Number of extra bytes to read */ - if( (iOff+nRec)>pIter->nAlloc ){ - int nNew = pIter->nAlloc*2; - while( (iOff+nRec)>nNew ) nNew = nNew*2; - pIter->aAlloc = sqlite3DbReallocOrFree(db, pIter->aAlloc, nNew); - if( !pIter->aAlloc ) return SQLITE_NOMEM; - pIter->nAlloc = nNew; + if( rc==SQLITE_OK ){ + iOff = getVarint32(pIter->aAlloc, nRec); + if( (iOff+nRec)>nRead ){ + int nRead2; /* Number of extra bytes to read */ + if( (iOff+nRec)>pIter->nAlloc ){ + int nNew = pIter->nAlloc*2; + while( (iOff+nRec)>nNew ) nNew = nNew*2; + pIter->aAlloc = sqlite3DbReallocOrFree(db, pIter->aAlloc, nNew); + if( !pIter->aAlloc ) return SQLITE_NOMEM; + pIter->nAlloc = nNew; + } + + nRead2 = iOff + nRec - nRead; + rc = sqlite3OsRead( + pIter->pFile, &pIter->aAlloc[nRead], nRead2, pIter->iReadOff+nRead + ); } - - nRead2 = iOff + nRec - nRead; - rc = sqlite3OsRead( - pIter->pFile, &pIter->aAlloc[nRead], nRead2, pIter->iReadOff+nRead - ); } - assert( nRec>0 || rc!=SQLITE_OK ); + assert( rc!=SQLITE_OK || nRec>0 ); pIter->iReadOff += iOff+nRec; pIter->nKey = nRec; pIter->aKey = &pIter->aAlloc[iOff]; @@ -543,12 +544,12 @@ static int vdbeSorterInitMerge( i64 nByte = 0; /* Total bytes in all opened PMAs */ /* Initialize the iterators. */ - for(i=0; rc==SQLITE_OK && iaIter[i]; rc = vdbeSorterIterInit(db, pSorter, pSorter->iReadOff, pIter, &nByte); pSorter->iReadOff = pIter->iEof; - assert( pSorter->iReadOff<=pSorter->iWriteOff || rc!=SQLITE_OK ); - if( pSorter->iReadOff>=pSorter->iWriteOff ) break; + assert( rc!=SQLITE_OK || pSorter->iReadOff<=pSorter->iWriteOff ); + if( rc!=SQLITE_OK || pSorter->iReadOff>=pSorter->iWriteOff ) break; } /* Initialize the aTree[] array. */ -- 2.47.2