1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Provide an alternative "guaranteed-safe" method for overwriting the WAL index

on recovery, in case some platform is found for which memcpy() cannot do this
safely.

FossilOrigin-Name: 168cccbabbd4807bdb04953f395cd1a245c46e9d4816a09c9d024ecd5432759d
This commit is contained in:
drh
2020-07-30 22:33:36 +00:00
parent 013e7bb749
commit e592c18c1c
3 changed files with 34 additions and 7 deletions

View File

@@ -1282,7 +1282,34 @@ static int walIndexRecover(Wal *pWal){
pWal->apWiData[iPg] = aShare;
nHdr = (iPg==0 ? WALINDEX_HDR_SIZE : 0);
nHdr32 = nHdr / sizeof(u32);
#ifndef SQLITE_SAFER_WALINDEX_RECOVERY
/* Memcpy() should work fine here, on all reasonable implementations.
** Technically, memcpy() might change the destination to some
** intermediate value before setting to the final value, and that might
** cause a concurrent reader to malfunction. Memcpy() is allowed to
** do that, according to the spec, but no memcpy() implementation that
** we know of actually does that, which is why we say that memcpy()
** is safe for this. Memcpy() is certainly a lot faster.
*/
memcpy(&aShare[nHdr32], &aPrivate[nHdr32], WALINDEX_PGSZ-nHdr);
#else
/* In the event that some platform is found for which memcpy()
** changes the destination to some intermediate value before
** setting the final value, this alternative copy routine is
** provided.
*/
{
int i;
for(i=nHdr32; i<WALINDEX_PGSZ/sizeof(u32); i++){
if( aShare[i]!=aPrivate[i] ){
/* Atomic memory operations are not required here because if
** the value needs to be changed, that means it is not being
** accessed concurrently. */
aShare[i] = aPrivate[i];
}
}
}
#endif
if( iFrame<=iLast ) break;
}