diff options
author | drh <drh@noemail.net> | 2010-05-31 18:24:19 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2010-05-31 18:24:19 +0000 |
commit | 4b82c387c99dee9e230737d66967086811dbdec5 (patch) | |
tree | 34c7ee27e1308d6187794fec8fbed0771185a06e /src | |
parent | 15d6809222b8f4b2619b8c56452aad21cc180958 (diff) | |
download | sqlite-4b82c387c99dee9e230737d66967086811dbdec5.tar.gz sqlite-4b82c387c99dee9e230737d66967086811dbdec5.zip |
Add an "isInit" field in the wal-index header that must be non-zero for
a valid header. Use this to detect an uninitialized wal-index.
FossilOrigin-Name: a16fde190183d1ae252d1aa305b23fdb88c603dc
Diffstat (limited to 'src')
-rw-r--r-- | src/wal.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -260,7 +260,8 @@ typedef struct WalCkptInfo WalCkptInfo; */ struct WalIndexHdr { u32 iChange; /* Counter incremented each transaction */ - u16 bigEndCksum; /* True if checksums in WAL are big-endian */ + u8 isInit; /* 1 when initialized */ + u8 bigEndCksum; /* True if checksums in WAL are big-endian */ u16 szPage; /* Database page size in bytes */ u32 mxFrame; /* Index of last valid frame in the WAL */ u32 nPage; /* Size of database in pages */ @@ -481,6 +482,7 @@ static void walIndexWriteHdr(Wal *pWal){ WalIndexHdr *aHdr; assert( pWal->writeLock ); + pWal->hdr.isInit = 1; walChecksumBytes(1, (u8*)&pWal->hdr, offsetof(WalIndexHdr, aCksum), 0, pWal->hdr.aCksum); aHdr = (WalIndexHdr*)pWal->pWiData; @@ -1563,11 +1565,9 @@ int walIndexTryHdr(Wal *pWal, int *pChanged){ if( memcmp(&h1, &h2, sizeof(h1))!=0 ){ return 1; /* Dirty read */ } -#if 0 - if( h1.szPage==0 ){ + if( h1.isInit==0 ){ return 1; /* Malformed header - probably all zeros */ } -#endif walChecksumBytes(1, (u8*)&h1, sizeof(h1)-sizeof(h1.aCksum), 0, aCksum); if( aCksum[0]!=h1.aCksum[0] || aCksum[1]!=h1.aCksum[1] ){ return 1; /* Checksum does not match */ |