Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CastingDiscovery: fix snprintf warning #29534

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ using ConnectCallback = std::function<void(ConnectionError)>;
using DisconnectCallback = std::function<void(void)>;

const int kPortMaxLength = 5; // port is uint16_t
const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength;
// +1 for the : between the hostname and the port.
const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength + 1;

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] = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down