NVS: Changed all new to new (nothrow)
This commit is contained in:
@@ -49,7 +49,10 @@ esp_err_t Page::load(uint32_t sectorNumber)
|
||||
// check if the whole page is really empty
|
||||
// reading the whole page takes ~40 times less than erasing it
|
||||
const int BLOCK_SIZE = 128;
|
||||
uint32_t* block = new uint32_t[BLOCK_SIZE];
|
||||
uint32_t* block = new (std::nothrow) uint32_t[BLOCK_SIZE];
|
||||
|
||||
if (!block) return ESP_ERR_NO_MEM;
|
||||
|
||||
for (uint32_t i = 0; i < SPI_FLASH_SEC_SIZE; i += 4 * BLOCK_SIZE) {
|
||||
rc = spi_flash_read(mBaseAddress + i, block, 4 * BLOCK_SIZE);
|
||||
if (rc != ESP_OK) {
|
||||
@@ -215,7 +218,11 @@ esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, c
|
||||
// write first item
|
||||
size_t span = (totalSize + ENTRY_SIZE - 1) / ENTRY_SIZE;
|
||||
item = Item(nsIndex, datatype, span, key, chunkIdx);
|
||||
mHashList.insert(item, mNextFreeEntry);
|
||||
err = mHashList.insert(item, mNextFreeEntry);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!isVariableLengthType(datatype)) {
|
||||
memcpy(item.data, data, dataSize);
|
||||
@@ -478,7 +485,11 @@ esp_err_t Page::copyItems(Page& other)
|
||||
return err;
|
||||
}
|
||||
|
||||
other.mHashList.insert(entry, other.mNextFreeEntry);
|
||||
err = other.mHashList.insert(entry, other.mNextFreeEntry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = other.writeEntry(entry);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
@@ -601,7 +612,11 @@ esp_err_t Page::mLoadEntryTable()
|
||||
continue;
|
||||
}
|
||||
|
||||
mHashList.insert(item, i);
|
||||
err = mHashList.insert(item, i);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
|
||||
// search for potential duplicate item
|
||||
size_t duplicateIndex = mHashList.find(0, item);
|
||||
@@ -671,7 +686,11 @@ esp_err_t Page::mLoadEntryTable()
|
||||
|
||||
assert(item.span > 0);
|
||||
|
||||
mHashList.insert(item, i);
|
||||
err = mHashList.insert(item, i);
|
||||
if (err != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return err;
|
||||
}
|
||||
|
||||
size_t span = item.span;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user