From cd07de219f794a857ee287260d35b1956a56870e Mon Sep 17 00:00:00 2001 From: cecille Date: Mon, 2 Oct 2023 13:34:21 -0400 Subject: [PATCH] CastingDiscovery: fix snprintf warning snprintf appends a null terminator, as does strcat, so both buffers need to be upsized by 1 to accommodate that. --- examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h | 2 +- .../tv-casting-common/core/CastingPlayerDiscovery.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h index c523fb111b0b48..3f33b69e526c0e 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h @@ -45,7 +45,7 @@ const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength; class CastingPlayerAttributes { public: - char id[kIdMaxLength] = {}; + char id[kIdMaxLength + 1] = {}; char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {}; char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {}; char instanceName[chip::Dnssd::kHostNameMaxLength + 1] = {}; diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp index 65a589932c1a4b..e391116c0ef1f7 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -81,7 +81,7 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover CastingPlayerAttributes attributes; strcpy(attributes.id, nodeData.resolutionData.hostName); - char port[kPortMaxLength] = {}; + char port[kPortMaxLength + 1] = {}; snprintf(port, sizeof(port), "%u", nodeData.resolutionData.port); strcat(attributes.id, port);