From 2be4b9fb362d7b329d025fcb9f0b171cd13a5ecd Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 17 Nov 2021 16:59:07 -0500 Subject: [PATCH] Enable asan for unit tests on Darwin when compiling with clang. (#11824) This immediately caught two bugs in things that were being unit-tested. The Linux version fails to link for some reason, hence this is Darwin-only. --- .github/workflows/build.yaml | 2 +- src/access/tests/TestAccessControl.cpp | 2 +- src/protocols/bdx/BdxMessages.cpp | 2 +- .../user_directed_commissioning/UserDirectedCommissioning.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index be95ea628f683b..9e248813cd2855 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -301,7 +301,7 @@ jobs: run: | for BUILD_TYPE in clang python_lib; do case $BUILD_TYPE in - "clang") GN_ARGS='is_clang=true target_os="all"';; + "clang") GN_ARGS='is_clang=true target_os="all" is_asan=true';; "python_lib") GN_ARGS='enable_rtti=true enable_pylib=true';; esac scripts/build/gn_gen.sh --args="$GN_ARGS" diff --git a/src/access/tests/TestAccessControl.cpp b/src/access/tests/TestAccessControl.cpp index 98dfec1ece65d2..1d693104d4aa00 100644 --- a/src/access/tests/TestAccessControl.cpp +++ b/src/access/tests/TestAccessControl.cpp @@ -671,7 +671,7 @@ void TestDeleteEntry(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, ClearAccessControl(accessControl) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, LoadAccessControl(accessControl, data, ArraySize(data)) == CHIP_NO_ERROR); - memcpy(&data[pos], &data[pos + count], (ArraySize(data) - count - pos) * sizeof(data[0])); + memmove(&data[pos], &data[pos + count], (ArraySize(data) - count - pos) * sizeof(data[0])); for (size_t i = 0; i < count; ++i) { diff --git a/src/protocols/bdx/BdxMessages.cpp b/src/protocols/bdx/BdxMessages.cpp index 9c0e24c273f07e..32e5db4b4534d0 100644 --- a/src/protocols/bdx/BdxMessages.cpp +++ b/src/protocols/bdx/BdxMessages.cpp @@ -170,7 +170,7 @@ size_t TransferInit::MessageSize() const void TransferInit::LogMessage(bdx::MessageType messageType) const { char fd[kMaxFileDesignatorLen]; - snprintf(fd, sizeof(fd), "%s", FileDesignator); + snprintf(fd, sizeof(fd), "%.*s", static_cast(FileDesLength), FileDesignator); switch (messageType) { diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h b/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h index e946b9acdb5370..c4a9874742ccae 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioning.h @@ -183,7 +183,7 @@ class DLL_EXPORT UserDirectedCommissioningServer : public TransportMgrDelegate * Get the cache of UDC Clients * */ - UDCClients GetUDCClients() { return mUdcClients; } + UDCClients & GetUDCClients() { return mUdcClients; } /** * Print the cache of UDC Clients