Skip to content

Commit 559328c

Browse files
committed
fix: alignment for riscv64 and armhf architectures
Signed-off-by: Anatoliy Bilenko <[email protected]>
1 parent 1b78c9e commit 559328c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/vfs.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct vfsShm
266266
/* Lock array. Each of these lock has the following semantics:
267267
* - 0 means unlocked;
268268
* - -1 means exclusive locked;
269-
* - >0 means shared locked and the value is the count of
269+
* - >0 means shared locked and the value is the count of
270270
* shared locks taken.
271271
*/
272272
int lock[SQLITE_SHM_NLOCK];
@@ -668,7 +668,7 @@ static void vfsAmendWalIndexHeader(struct vfsDatabase *d)
668668
{
669669
struct vfsShm *shm = &d->shm;
670670
struct vfsWal *wal = &d->wal;
671-
_Alignas(8) uint8_t index[VFS__WAL_INDEX_HEADER_SIZE * 2];
671+
uint8_t index[VFS__WAL_INDEX_HEADER_SIZE * 2];
672672
uint32_t frame_checksum[2] = { 0, 0 };
673673
uint32_t n_pages = (uint32_t)d->n_pages;
674674
uint32_t checksum[2] = { 0, 0 };
@@ -687,19 +687,21 @@ static void vfsAmendWalIndexHeader(struct vfsDatabase *d)
687687
/* index is an alias for shm->regions[0] which is a void* that points to
688688
* memory allocated by `sqlite3_malloc64` and has the required alignment
689689
*/
690-
assert(*(uint32_t *)(&index[0]) == VFS__WAL_VERSION); /* iVersion */
691-
assert(index[12] == 1); /* isInit */
692-
assert(index[13] == VFS__BIGENDIAN); /* bigEndCksum */
690+
uint32_t index0;
691+
memcpy(&index0, &index[0], sizeof(uint32_t));
692+
assert(index0 == VFS__WAL_VERSION); /* iVersion */
693+
assert(index[12] == 1); /* isInit */
694+
assert(index[13] == VFS__BIGENDIAN); /* bigEndCksum */
693695

694-
*(uint32_t *)(&index[16]) = wal->n_frames;
695-
*(uint32_t *)(&index[20]) = n_pages;
696-
*(uint32_t *)(&index[24]) = frame_checksum[0];
697-
*(uint32_t *)(&index[28]) = frame_checksum[1];
696+
memcpy(&index[16], &wal->n_frames, sizeof(uint32_t));
697+
memcpy(&index[20], &n_pages, sizeof(uint32_t));
698+
memcpy(&index[24], &frame_checksum[0], sizeof(uint32_t));
699+
memcpy(&index[28], &frame_checksum[1], sizeof(uint32_t));
698700

699701
vfsChecksum(index, 40, checksum, checksum);
700702

701-
*(uint32_t *)(&index[40]) = checksum[0];
702-
*(uint32_t *)(&index[44]) = checksum[1];
703+
memcpy(&index[40], &checksum[0], sizeof(uint32_t));
704+
memcpy(&index[44], &checksum[1], sizeof(uint32_t));
703705

704706
/* Update the second copy of the first part of the WAL index header. */
705707
memcpy(index + VFS__WAL_INDEX_HEADER_SIZE, index,
@@ -1745,7 +1747,7 @@ static int vfsDiskFileWrite(sqlite3_file *file,
17451747
sqlite_int64 offset)
17461748
{
17471749
struct vfsDiskMainFile *f = (struct vfsDiskMainFile *)file;
1748-
1750+
17491751
/* Write to the actual database file. */
17501752
vfsDiskDatabaseTrackNumPages(f->base.database, offset);
17511753
int rv = f->underlying->pMethods->xWrite(f->underlying, buf, amount, offset);
@@ -2362,7 +2364,7 @@ static int vfsWalAppend(struct vfsDatabase *d,
23622364
goto oom_after_frames_alloc;
23632365
}
23642366

2365-
/* When writing the SQLite database header, make sure to sync
2367+
/* When writing the SQLite database header, make sure to sync
23662368
* the file size to the logical database size. */
23672369
if (page_number == 1) {
23682370
database_size = ByteGetBe32(&page[VFS__IN_HEADER_DATABASE_SIZE_OFFSET]);

0 commit comments

Comments
 (0)