nvs: check value size before writing, document limitations
Writing values longer than half of the page size (with header taken into account) causes fragmentation issues. Previously it was suggested on the forum that using long values may cause issues, but this wasn’t checked in the library itself, and wasn’t documented. This change adds necessary checks and introduces the new error code. Documentation is also fixed to reflect the fact that the maximum length of the key is 15 characters, not 16.
This commit is contained in:
@@ -175,6 +175,10 @@ esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, c
|
||||
if (keySize > Item::MAX_KEY_LENGTH) {
|
||||
return ESP_ERR_NVS_KEY_TOO_LONG;
|
||||
}
|
||||
|
||||
if (dataSize > Page::BLOB_MAX_SIZE) {
|
||||
return ESP_ERR_NVS_VALUE_TOO_LONG;
|
||||
}
|
||||
|
||||
size_t totalSize = ENTRY_SIZE;
|
||||
size_t entriesCount = 1;
|
||||
|
||||
Reference in New Issue
Block a user