From 5d43d3f1ba737bd15f07f58dfed99694e0945e97 Mon Sep 17 00:00:00 2001 From: liuchao Date: Tue, 6 Aug 2024 13:03:16 +0800 Subject: [PATCH] align down possible 0 --- src/fdb_kvdb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fdb_kvdb.c b/src/fdb_kvdb.c index 00cf557..51634ba 100644 --- a/src/fdb_kvdb.c +++ b/src/fdb_kvdb.c @@ -1179,9 +1179,13 @@ static fdb_err_t align_write(fdb_kvdb_t db, uint32_t addr, const uint32_t *buf, #endif memset(align_data, FDB_BYTE_ERASED, align_data_size); - result = _fdb_flash_write((fdb_db_t) db, addr, buf, FDB_WG_ALIGN_DOWN(size), false); - + size_t align_down = FDB_WG_ALIGN_DOWN(size); align_remain = size - FDB_WG_ALIGN_DOWN(size); + + if (align_down > 0) { + result = _fdb_flash_write((fdb_db_t) db, addr, buf, FDB_WG_ALIGN_DOWN(size), false); + } + if (result == FDB_NO_ERR && align_remain) { memcpy(align_data, (uint8_t *) buf + FDB_WG_ALIGN_DOWN(size), align_remain); result = _fdb_flash_write((fdb_db_t) db, addr + FDB_WG_ALIGN_DOWN(size), (uint32_t *) align_data,