summaryrefslogtreecommitdiff
path: root/src/test6.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test6.c')
-rw-r--r--src/test6.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/test6.c b/src/test6.c
index c151ea4..306482d 100644
--- a/src/test6.c
+++ b/src/test6.c
@@ -133,9 +133,9 @@ struct CrashFile {
** OsFileSize() calls. Although both could be done by traversing the
** write-list, in practice this is impractically slow.
*/
- int iSize; /* Size of file in bytes */
- int nData; /* Size of buffer allocated at zData */
u8 *zData; /* Buffer containing file contents */
+ int nData; /* Size of buffer allocated at zData */
+ i64 iSize; /* Size of file in bytes */
};
struct CrashGlobal {
@@ -173,9 +173,6 @@ static void *crash_realloc(void *p, int n){
static int writeDbFile(CrashFile *p, u8 *z, i64 iAmt, i64 iOff){
int rc = SQLITE_OK;
int iSkip = 0;
- if( iOff==PENDING_BYTE && (p->flags&SQLITE_OPEN_MAIN_DB) ){
- iSkip = 512;
- }
if( (iAmt-iSkip)>0 ){
rc = sqlite3OsWrite(p->pRealFile, &z[iSkip], (int)(iAmt-iSkip), iOff+iSkip);
}
@@ -409,13 +406,17 @@ static int cfRead(
sqlite_int64 iOfst
){
CrashFile *pCrash = (CrashFile *)pFile;
+ int nCopy = (int)MIN((i64)iAmt, (pCrash->iSize - iOfst));
+
+ if( nCopy>0 ){
+ memcpy(zBuf, &pCrash->zData[iOfst], nCopy);
+ }
/* Check the file-size to see if this is a short-read */
- if( pCrash->iSize<(iOfst+iAmt) ){
+ if( nCopy<iAmt ){
return SQLITE_IOERR_SHORT_READ;
}
- memcpy(zBuf, &pCrash->zData[iOfst], iAmt);
return SQLITE_OK;
}
@@ -621,7 +622,7 @@ static int cfOpen(
pWrapper->flags = flags;
}
if( rc==SQLITE_OK ){
- pWrapper->nData = (4096 + pWrapper->iSize);
+ pWrapper->nData = (int)(4096 + pWrapper->iSize);
pWrapper->zData = crash_malloc(pWrapper->nData);
if( pWrapper->zData ){
/* os_unix.c contains an assert() that fails if the caller attempts
@@ -632,14 +633,12 @@ static int cfOpen(
** UPDATE: It also contains an assert() verifying that each call
** to the xRead() method reads less than 128KB of data.
*/
- const int isDb = (flags&SQLITE_OPEN_MAIN_DB);
i64 iOff;
memset(pWrapper->zData, 0, pWrapper->nData);
for(iOff=0; iOff<pWrapper->iSize; iOff += 512){
- int nRead = pWrapper->iSize - (int)iOff;
+ int nRead = (int)(pWrapper->iSize - iOff);
if( nRead>512 ) nRead = 512;
- if( isDb && iOff==PENDING_BYTE ) continue;
rc = sqlite3OsRead(pReal, &pWrapper->zData[iOff], nRead, iOff);
}
}else{