Skip to content

Commit

Permalink
allow for nullptr in KVS write
Browse files Browse the repository at this point in the history
  • Loading branch information
srickardti committed Aug 17, 2022
1 parent 6c08a9e commit 07ddad4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
5 changes: 2 additions & 3 deletions examples/persistent-storage/KeyValueStorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ CHIP_ERROR TestMultiRead()
CHIP_ERROR TestZeroLength()
{
const char * kTestKey = "zero_key";
const char kTestValue[] = "not used";
char read_value[sizeof(kTestValue)];
char read_value[10] = {0};
size_t read_size;
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue, 0U));
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, NULL, 0U));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, read_value, sizeof(read_value), &read_size));
ReturnErrorCodeIf(read_size != 0U, CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
Expand Down
6 changes: 6 additions & 0 deletions examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var AESECB2 = AESECB.addInstance();
var Button1 = Button.addInstance();
var Button2 = Button.addInstance();
var NVS1 = NVS.addInstance();
var NVS2 = NVS.addInstance();
var SHA21 = SHA2.addInstance();
var LED1 = LED.addInstance();
var LED2 = LED.addInstance();
Expand Down Expand Up @@ -93,9 +94,14 @@ CCFG.enableCodeGeneration = false;

/* NVS */
NVS1.$name = "CONFIG_NVSINTERNAL";

NVS1.internalFlash.regionBase = 0xAA000;
NVS1.internalFlash.regionSize = 0x4000;

NVS2.$name = "CONFIG_NVSEXTERNAL";
NVS2.nvsType = "External"; // NVS Region Type
NVS2.$hardware = system.deviceData.board.components.MX25R8035F;

/* RF */
/* if an antenna component exists, assign it to the rf instance */
if (system.deviceData.board && system.deviceData.board.components.RF) {
Expand Down
9 changes: 8 additions & 1 deletion src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
{
VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);
if (0U == value_size)
{
VerifyOrReturnError(nullptr == value, CHIP_ERROR_INVALID_ARGUMENT);
}
else
{
VerifyOrReturnError(nullptr != value, CHIP_ERROR_INVALID_ARGUMENT);
}

return CC13X2_26X2Config::WriteKVS(key, value, value_size);
}
Expand Down
9 changes: 8 additions & 1 deletion src/platform/cc32xx/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
{
VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);
if (0U == value_size)
{
VerifyOrReturnError(nullptr == value, CHIP_ERROR_INVALID_ARGUMENT);
}
else
{
VerifyOrReturnError(nullptr != value, CHIP_ERROR_INVALID_ARGUMENT);
}

return CC32XXConfig::WriteKVS(key, value, value_size);
}
Expand Down

0 comments on commit 07ddad4

Please sign in to comment.