diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp index 8c1dbdaeb36147..7a8bc6a7a212ff 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp @@ -162,7 +162,7 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe jfieldID getInstanceNameField = env->GetFieldID(jVideoPlayerClass, "instanceName", "Ljava/lang/String;"); jstring jInstanceName = static_cast(env->GetObjectField(videoPlayer, getInstanceNameField)); const char * instanceName = {}; - if(jInstanceName != nullptr) + if (jInstanceName != nullptr) { instanceName = env->GetStringUTFChars(jInstanceName, 0); } @@ -182,7 +182,7 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe if (MACAddress != nullptr) { - chip::CharSpan MACAddressSpan(MACAddress, strlen(MACAddress) - 1); + chip::CharSpan MACAddressSpan(MACAddress, 2 * 2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength); outTargetVideoPlayerInfo.SetMACAddress(MACAddressSpan); } @@ -256,9 +256,9 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta jstring MACAddress = nullptr; if (targetVideoPlayerInfo->GetMACAddress() != nullptr && targetVideoPlayerInfo->GetMACAddress()->data() != nullptr) { - char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength + 1]; - strncpy(MACAddressWithNil, targetVideoPlayerInfo->GetMACAddress()->data(), - targetVideoPlayerInfo->GetMACAddress()->size()); + char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength + 1]; + memcpy(MACAddressWithNil, targetVideoPlayerInfo->GetMACAddress()->data(), + targetVideoPlayerInfo->GetMACAddress()->size()); MACAddressWithNil[targetVideoPlayerInfo->GetMACAddress()->size()] = '\0'; MACAddress = env->NewStringUTF(MACAddressWithNil); } diff --git a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h index cfcd2c6a5c45ca..ff1b4dfc692f3f 100644 --- a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h +++ b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h @@ -209,7 +209,7 @@ class TargetVideoPlayerInfo char mInstanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1]; uint16_t mPort; chip::CharSpan mMACAddress; - char mMACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength]; + char mMACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength]; chip::System::Clock::Timestamp mLastDiscovered; bool mIsAsleep = false; bool mInitialized = false; diff --git a/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp b/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp index 4ee718963159c4..9feacd503f6a9a 100644 --- a/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/PersistenceManager.cpp @@ -267,11 +267,11 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {}; size_t numIPs = 0; Inet::IPAddress ipAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses]; - uint64_t lastDiscoveredMs = 0; - char MACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength] = {}; - uint32_t MACAddressLength = 0; - char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {}; - uint16_t port = 0; + uint64_t lastDiscoveredMs = 0; + char MACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength] = {}; + uint32_t MACAddressLength = 0; + char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {}; + uint16_t port = 0; CHIP_ERROR err; while ((err = reader.Next()) == CHIP_NO_ERROR) @@ -349,7 +349,7 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide { MACAddressLength = reader.GetLength(); ReturnErrorOnFailure(reader.GetBytes(reinterpret_cast(MACAddressBuf), - 2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength)); + 2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength)); continue; }