From 4d0037b358da4e26735fbad5f2ffcccb1b57c7de Mon Sep 17 00:00:00 2001 From: Sid Hsu Date: Tue, 18 Oct 2022 04:25:08 +0800 Subject: [PATCH] [Infineon] Fix CYW30739 KVS. (#23145) --- .../Infineon/CYW30739/KeyValueStoreManagerImpl.cpp | 3 ++- src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.h | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.cpp b/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.cpp index f139f6bb9c62d3..f78d6397823317 100644 --- a/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.cpp +++ b/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.cpp @@ -46,6 +46,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::Init(void) { KeyStorage keyStorage; size_t keyStorageLength; + memset(keyStorage.mKey, 0, sizeof(keyStorage.mKey)); err = CYW30739Config::ReadConfigValueBin(CYW30739ConfigKey(Config::kChipKvsKey_KeyBase, configID), &keyStorage, sizeof(keyStorage), keyStorageLength); if (err != CHIP_NO_ERROR) @@ -188,7 +189,7 @@ KeyValueStoreManagerImpl::KeyStorage::KeyStorage(const char * key) : mValueSize( bool KeyValueStoreManagerImpl::KeyStorage::IsMatchKey(const char * key) const { - return strncmp(mKey, key, sizeof(mKey)) == 0; + return strcmp(mKey, key) == 0; } KeyValueStoreManagerImpl::KeyConfigIdEntry * KeyValueStoreManagerImpl::AllocateEntry(const char * key) diff --git a/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.h b/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.h index 7c9045574d03a4..9d16dd4ce1e6cd 100644 --- a/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.h +++ b/src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.h @@ -61,16 +61,16 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager { KeyStorage(const char * key = nullptr); - constexpr size_t GetSize() const { return sizeof(mValueSize) + strnlen(mKey, sizeof(mKey)); } + constexpr size_t GetSize() const { return sizeof(mValueSize) + strlen(mKey); } bool IsMatchKey(const char * key) const; uint16_t mValueSize; - char mKey[PersistentStorageDelegate::kKeyLengthMax]; + char mKey[PersistentStorageDelegate::kKeyLengthMax + 1]; }; struct KeyConfigIdEntry : public slist_node_t { - KeyConfigIdEntry(uint8_t configID, const KeyStorage & keyStorage) : mConfigID(configID), mStorage(keyStorage) {} + KeyConfigIdEntry(uint8_t configID, const KeyStorage & keyStorage) : mStorage(keyStorage), mConfigID(configID) {} constexpr Config::Key GetValueConfigKey() const { @@ -85,8 +85,8 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager constexpr uint16_t GetValueSize() const { return mStorage.mValueSize; } constexpr void SetValueSize(uint16_t valueSize) { mStorage.mValueSize = valueSize; } - uint8_t mConfigID; KeyStorage mStorage; + uint8_t mConfigID; }; KeyConfigIdEntry * AllocateEntry(const char * key);