Skip to content

Commit

Permalink
CastingDiscovery: fix snprintf warning
Browse files Browse the repository at this point in the history
snprintf appends a null terminator, as does strcat, so both buffers
need to be upsized by 1 to accommodate that.
  • Loading branch information
cecille committed Oct 2, 2023
1 parent 6047fbb commit cd07de2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {};
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

0 comments on commit cd07de2

Please sign in to comment.