Skip to content

Commit

Permalink
Update length calculation for NVS
Browse files Browse the repository at this point in the history
  • Loading branch information
srickardti committed Mar 23, 2022
1 parent 20ba104 commit 488c813
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ CHIP_ERROR CC13X2_26X2Config::ReadKVS(const char * key, void * value, size_t val
NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID;
uint16_t subID;
size_t len;
uint16_t read_len;

VerifyOrExit(FindKVSSubID(key, subID) == NVINTF_SUCCESS, err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND);

Expand All @@ -220,19 +221,23 @@ CHIP_ERROR CC13X2_26X2Config::ReadKVS(const char * key, void * value, size_t val
len = sNvoctpFps.getItemLen(val_item);
VerifyOrExit(len > 0, err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // key not found

VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, (uint16_t) value_size, value) == NVINTF_SUCCESS,
if ((offset_bytes + value_size) > len)
{
// trying to read up to the end of the element
read_len = len - offset_bytes;
}
else
{
read_len = value_size;
}


VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, read_len, value) == NVINTF_SUCCESS,
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

if (read_bytes_size)
{
if (len - offset_bytes > value_size)
{
*read_bytes_size = value_size;
}
else
{
*read_bytes_size = len - offset_bytes;
}
*read_bytes_size = read_len;
}

exit:
Expand Down

0 comments on commit 488c813

Please sign in to comment.