Skip to content

Commit 56b3314

Browse files
committed
use memmove instead of memcpy, rename index used to retrieve credentials attached to user
1 parent 64e96bc commit 56b3314

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

examples/lock-app/silabs/src/LockManager.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip:
448448
return false;
449449
}
450450

451-
memcpy(mUserInStorage.userName, userName.data(), userName.size());
451+
memmove(mUserInStorage.userName, userName.data(), userName.size());
452452
mUserInStorage.userNameSize = userName.size();
453453
mUserInStorage.userUniqueId = uniqueId;
454454
mUserInStorage.userStatus = userStatus;
@@ -586,7 +586,7 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
586586
mCredentialInStorage.lastModifiedBy = modifier;
587587
mCredentialInStorage.credentialDataSize = credentialData.size();
588588

589-
memcpy(mCredentialInStorage.credentialData, credentialData.data(), mCredentialInStorage.credentialDataSize);
589+
memmove(mCredentialInStorage.credentialData, credentialData.data(), mCredentialInStorage.credentialDataSize);
590590

591591
chip::StorageKeyName key = LockCredentialEndpoint(credentialIndex, credentialType, endpointId);
592592

@@ -952,16 +952,17 @@ bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip:
952952
continue;
953953
}
954954

955-
for (int j = 0; j < mUserInStorage.currentCredentialCount; j++)
955+
// Loop through each credential attached to the user
956+
for (int userCredentialIndex = 0; userCredentialIndex < mUserInStorage.currentCredentialCount; userCredentialIndex++)
956957
{
957958
// If the current credential is a pin type, then check it against pin input. Otherwise ignore
958-
if (mCredentials[j].credentialType == CredentialTypeEnum::kPin)
959+
if (mCredentials[userCredentialIndex].credentialType == CredentialTypeEnum::kPin)
959960
{
960961
// Read the individual credential at credentialIndex j
961962
uint16_t credentialSize = static_cast<uint16_t>(sizeof(LockCredentialInfo));
962963

963964
chip::StorageKeyName key =
964-
LockCredentialEndpoint(mCredentials[j].credentialIndex, mCredentials[j].credentialType, endpointId);
965+
LockCredentialEndpoint(mCredentials[userCredentialIndex].credentialIndex, mCredentials[userCredentialIndex].credentialType, endpointId);
965966

966967
error = mStorage->SyncGetKeyValue(key.KeyName(), &mCredentialInStorage, credentialSize);
967968

@@ -986,7 +987,7 @@ bool LockManager::setLockState(chip::EndpointId endpointId, const Nullable<chip:
986987
Zcl, "Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]",
987988
lockStateToString(lockState), endpointId);
988989

989-
LockOpCredentials userCredential[] = { { CredentialTypeEnum::kPin, mCredentials[j].credentialIndex } };
990+
LockOpCredentials userCredential[] = { { CredentialTypeEnum::kPin, mCredentials[userCredentialIndex].credentialIndex } };
990991
auto userCredentials = MakeNullable<List<const LockOpCredentials>>(userCredential);
991992

992993
DoorLockServer::Instance().SetLockState(endpointId, lockState, OperationSourceEnum::kRemote, userIndex,

0 commit comments

Comments
 (0)