mirror of
https://github.com/armink/FlashDB.git
synced 2025-01-29 04:32:53 +08:00
[kvdb] fix the issue when get next kv may be out of bound
Merge pull request !1 from timchen/N/A
This commit is contained in:
commit
e2e373028b
@ -252,7 +252,7 @@ static uint32_t find_next_kv_addr(fdb_kvdb_t db, uint32_t start, uint32_t end)
|
|||||||
}
|
}
|
||||||
#endif /* FDB_KV_USING_CACHE */
|
#endif /* FDB_KV_USING_CACHE */
|
||||||
|
|
||||||
for (; start < end; start += (sizeof(buf) - sizeof(uint32_t))) {
|
for (; start < end && start + sizeof(buf) < end; start += (sizeof(buf) - sizeof(uint32_t))) {
|
||||||
_fdb_flash_read((fdb_db_t)db, start, (uint32_t *) buf, sizeof(buf));
|
_fdb_flash_read((fdb_db_t)db, start, (uint32_t *) buf, sizeof(buf));
|
||||||
for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) {
|
for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) {
|
||||||
#ifndef FDB_BIG_ENDIAN /* Little Endian Order */
|
#ifndef FDB_BIG_ENDIAN /* Little Endian Order */
|
||||||
@ -293,7 +293,7 @@ static uint32_t get_next_kv_addr(fdb_kvdb_t db, kv_sec_info_t sector, fdb_kv_t p
|
|||||||
addr = find_next_kv_addr(db, addr, sector->addr + db_sec_size(db) - SECTOR_HDR_DATA_SIZE);
|
addr = find_next_kv_addr(db, addr, sector->addr + db_sec_size(db) - SECTOR_HDR_DATA_SIZE);
|
||||||
|
|
||||||
if (addr > sector->addr + db_sec_size(db) || pre_kv->len == 0) {
|
if (addr > sector->addr + db_sec_size(db) || pre_kv->len == 0) {
|
||||||
//TODO <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
//TODO 扇区连续模式
|
||||||
return FAILED_ADDR;
|
return FAILED_ADDR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -328,7 +328,7 @@ static fdb_err_t read_kv(fdb_kvdb_t db, fdb_kv_t kv)
|
|||||||
kv->crc_is_ok = false;
|
kv->crc_is_ok = false;
|
||||||
return FDB_READ_ERR;
|
return FDB_READ_ERR;
|
||||||
} else if (kv->len > db_sec_size(db) - SECTOR_HDR_DATA_SIZE && kv->len < db_part_size(db)) {
|
} else if (kv->len > db_sec_size(db) - SECTOR_HDR_DATA_SIZE && kv->len < db_part_size(db)) {
|
||||||
//TODO <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>볤<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//TODO 扇区连续模式,或者写入长度没有写入完整
|
||||||
FDB_ASSERT(0);
|
FDB_ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1468,7 +1468,7 @@ static bool check_and_recovery_kv_cb(fdb_kv_t kv, void *arg1, void *arg2)
|
|||||||
} else if (kv->status == FDB_KV_PRE_WRITE) {
|
} else if (kv->status == FDB_KV_PRE_WRITE) {
|
||||||
uint8_t status_table[KV_STATUS_TABLE_SIZE];
|
uint8_t status_table[KV_STATUS_TABLE_SIZE];
|
||||||
/* the KV has not write finish, change the status to error */
|
/* the KV has not write finish, change the status to error */
|
||||||
//TODO <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬װ<EFBFBD><EFBFBD>ͼ
|
//TODO 绘制异常处理的状态装换图
|
||||||
_fdb_write_status((fdb_db_t)db, kv->addr.start, status_table, FDB_KV_STATUS_NUM, FDB_KV_ERR_HDR);
|
_fdb_write_status((fdb_db_t)db, kv->addr.start, status_table, FDB_KV_STATUS_NUM, FDB_KV_ERR_HDR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user