mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
NVS: BUGFIX non-matching type iterator works
Closes IDFGH-2229
This commit is contained in:
@ -864,6 +864,7 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si
|
||||
if (key == nullptr && nsIndex == NS_ANY && chunkIdx == CHUNK_ANY) {
|
||||
continue; // continue for bruteforce search on blob indices.
|
||||
}
|
||||
itemIndex = i;
|
||||
return ESP_ERR_NVS_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
|
@ -772,6 +772,39 @@ TEST_CASE("nvs iterators tests", "[nvs]")
|
||||
nvs_close(handle_2);
|
||||
}
|
||||
|
||||
TEST_CASE("Iterator with not matching type iterates correctly", "[nvs]")
|
||||
{
|
||||
SpiFlashEmulator emu(5);
|
||||
nvs_iterator_t it;
|
||||
nvs_handle_t my_handle;
|
||||
const char* NAMESPACE = "test_ns_4";
|
||||
|
||||
const uint32_t NVS_FLASH_SECTOR = 0;
|
||||
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 5;
|
||||
emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
|
||||
|
||||
for (uint16_t i = NVS_FLASH_SECTOR; i < NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN; ++i) {
|
||||
spi_flash_erase_sector(i);
|
||||
}
|
||||
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
||||
|
||||
// writing string to namespace (a type which spans multiple entries)
|
||||
TEST_ESP_OK(nvs_open(NAMESPACE, NVS_READWRITE, &my_handle));
|
||||
TEST_ESP_OK(nvs_set_str(my_handle, "test-string", "InitString0"));
|
||||
TEST_ESP_OK(nvs_commit(my_handle));
|
||||
nvs_close(my_handle);
|
||||
|
||||
it = nvs_entry_find(NVS_DEFAULT_PART_NAME, NAMESPACE, NVS_TYPE_I32);
|
||||
CHECK(it == NULL);
|
||||
|
||||
// re-init to trigger cleaning up of broken items -> a corrupted string will be erased
|
||||
nvs_flash_deinit();
|
||||
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
||||
|
||||
it = nvs_entry_find(NVS_DEFAULT_PART_NAME, NAMESPACE, NVS_TYPE_STR);
|
||||
CHECK(it != NULL);
|
||||
nvs_release_iterator(it);
|
||||
}
|
||||
|
||||
TEST_CASE("wifi test", "[nvs]")
|
||||
{
|
||||
|
Reference in New Issue
Block a user