| Index: third_party/sqlite/src/ext/async/sqlite3async.c
|
| diff --git a/third_party/sqlite/src/ext/async/sqlite3async.c b/third_party/sqlite/src/ext/async/sqlite3async.c
|
| index 11a4761298cffd4c4c9510a0aecc25bccfd75083..a351eaa92261ebc48177fe716713f2207edae419 100644
|
| --- a/third_party/sqlite/src/ext/async/sqlite3async.c
|
| +++ b/third_party/sqlite/src/ext/async/sqlite3async.c
|
| @@ -667,9 +667,9 @@ static int asyncRead(
|
| ){
|
| AsyncFileData *p = ((AsyncFile *)pFile)->pData;
|
| int rc = SQLITE_OK;
|
| - sqlite3_int64 filesize;
|
| - int nRead;
|
| + sqlite3_int64 filesize = 0;
|
| 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,13 +683,14 @@ 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);
|
| + rc = pBase->pMethods->xRead(pBase, zOut, (int)nRead, iOffset);
|
| ASYNC_TRACE(("READ %s %d bytes at %d\n", p->zName, nRead, iOffset));
|
| }
|
| }
|
| @@ -703,16 +704,24 @@ 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);
|
|
|
| + filesize = MAX(filesize, pWrite->iOffset+nByte64);
|
| +
|
| + nCopy = MIN(nByte64-iBeginIn, iAmt64-iBeginOut);
|
| if( nCopy>0 ){
|
| - memcpy(&((char *)zOut)[iBeginOut], &pWrite->zBuf[iBeginIn], nCopy);
|
| + memcpy(&((char *)zOut)[iBeginOut], &pWrite->zBuf[iBeginIn], (size_t)nCopy);
|
| ASYNC_TRACE(("OVERREAD %d bytes at %d\n", nCopy, iBeginOut+iOffset));
|
| }
|
| }
|
| @@ -721,6 +730,9 @@ static int asyncRead(
|
|
|
| asyncread_out:
|
| async_mutex_leave(ASYNC_MUTEX_QUEUE);
|
| + if( rc==SQLITE_OK && filesize<(iOffset+iAmt) ){
|
| + rc = SQLITE_IOERR_SHORT_READ;
|
| + }
|
| return rc;
|
| }
|
|
|
| @@ -1131,7 +1143,6 @@ static int asyncOpen(
|
| async_mutex_leave(ASYNC_MUTEX_LOCK);
|
|
|
| if( rc==SQLITE_OK ){
|
| - incrOpenFileCount();
|
| pData->pLock = pLock;
|
| }
|
|
|
| @@ -1148,7 +1159,10 @@ static int asyncOpen(
|
| }
|
| if( rc!=SQLITE_OK ){
|
| p->pMethod = 0;
|
| + }else{
|
| + incrOpenFileCount();
|
| }
|
| +
|
| return rc;
|
| }
|
|
|
| @@ -1224,8 +1238,8 @@ static int asyncFullPathname(
|
| */
|
| if( rc==SQLITE_OK ){
|
| int i, j;
|
| - int n = nPathOut;
|
| char *z = zPathOut;
|
| + int n = (int)strlen(z);
|
| while( n>1 && z[n-1]=='/' ){ n--; }
|
| for(i=j=0; i<n; i++){
|
| if( z[i]=='/' ){
|
|
|