1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Use 64-bit arithmetic in the xRead() method of asyncRead. Fix for [94c04eaadb].

FossilOrigin-Name: ca3e41b0574cfd8d971c2be2114e58273a531970
This commit is contained in:
dan
2009-10-19 07:50:25 +00:00
parent 1476a28470
commit fd3b22265e
4 changed files with 92 additions and 12 deletions

View File

@ -668,8 +668,8 @@ static int asyncRead(
AsyncFileData *p = ((AsyncFile *)pFile)->pData;
int rc = SQLITE_OK;
sqlite3_int64 filesize;
int nRead;
sqlite3_file *pBase = p->pBaseRead;
sqlite3_int64 iAmt64 = (sqlite3_int64)iAmt;
/* Grab the write queue mutex for the duration of the call */
async_mutex_enter(ASYNC_MUTEX_QUEUE);
@ -683,11 +683,12 @@ static int asyncRead(
}
if( pBase->pMethods ){
sqlite3_int64 nRead;
rc = pBase->pMethods->xFileSize(pBase, &filesize);
if( rc!=SQLITE_OK ){
goto asyncread_out;
}
nRead = (int)MIN(filesize - iOffset, iAmt);
nRead = MIN(filesize - iOffset, iAmt64);
if( nRead>0 ){
rc = pBase->pMethods->xRead(pBase, zOut, nRead, iOffset);
ASYNC_TRACE(("READ %s %d bytes at %d\n", p->zName, nRead, iOffset));
@ -703,14 +704,20 @@ static int asyncRead(
(pWrite->pFileData==p) ||
(zName && pWrite->pFileData->zName==zName)
)){
sqlite3_int64 nCopy;
sqlite3_int64 nByte64 = (sqlite3_int64)pWrite->nByte;
/* Set variable iBeginIn to the offset in buffer pWrite->zBuf[] from
** which data should be copied. Set iBeginOut to the offset within
** the output buffer to which data should be copied. If either of
** these offsets is a negative number, set them to 0.
*/
sqlite3_int64 iBeginOut = (pWrite->iOffset-iOffset);
sqlite3_int64 iBeginIn = -iBeginOut;
int nCopy;
if( iBeginIn<0 ) iBeginIn = 0;
if( iBeginOut<0 ) iBeginOut = 0;
nCopy = (int)MIN(pWrite->nByte-iBeginIn, iAmt-iBeginOut);
nCopy = MIN(nByte64-iBeginIn, iAmt64-iBeginOut);
if( nCopy>0 ){
memcpy(&((char *)zOut)[iBeginOut], &pWrite->zBuf[iBeginIn], nCopy);
ASYNC_TRACE(("OVERREAD %d bytes at %d\n", nCopy, iBeginOut+iOffset));