diff --git a/examples/common/tracing/BUILD.gn b/examples/common/tracing/BUILD.gn index d63a4ae84e043c..86ea5a1f63b4ff 100644 --- a/examples/common/tracing/BUILD.gn +++ b/examples/common/tracing/BUILD.gn @@ -26,6 +26,8 @@ source_set("trace_handlers") { deps = [ "${chip_root}/src/lib" ] public_configs = [ ":default_config" ] + + cflags = [ "-Wconversion" ] } source_set("trace_handlers_decoder") { @@ -47,6 +49,8 @@ source_set("trace_handlers_decoder") { deps = [ "${chip_root}/src/lib" ] public_deps = [ "${chip_root}/third_party/jsoncpp" ] + + cflags = [ "-Wconversion" ] } executable("chip-trace-decoder") { @@ -73,4 +77,6 @@ executable("chip-trace-decoder") { "${chip_root}/src/lib", "${chip_root}/third_party/jsoncpp", ] + + cflags = [ "-Wconversion" ] } diff --git a/examples/common/tracing/TraceDecoder.cpp b/examples/common/tracing/TraceDecoder.cpp index eedfd73fb748fd..2bb3c5ee213ce0 100644 --- a/examples/common/tracing/TraceDecoder.cpp +++ b/examples/common/tracing/TraceDecoder.cpp @@ -131,7 +131,7 @@ CHIP_ERROR TraceDecoder::ReadString(const char * str) CHIP_ERROR TraceDecoder::LogJSON(Json::Value & json) { auto protocol = json[kProtocolIdKey].asLargestUInt(); - uint16_t vendorId = protocol >> 16; + uint16_t vendorId = static_cast(protocol >> 16); uint16_t protocolId = protocol & 0xFFFF; if (!mOptions.IsProtocolEnabled(chip::Protocols::Id(chip::VendorId(vendorId), protocolId))) { @@ -213,7 +213,7 @@ CHIP_ERROR TraceDecoder::LogAndConsumeProtocol(Json::Value & json) auto id = json[kProtocolIdKey].asLargestUInt(); auto opcode = static_cast(json[kProtocolCodeKey].asLargestUInt()); - uint16_t vendorId = (id >> 16); + uint16_t vendorId = static_cast(id >> 16); uint16_t protocolId = (id & 0xFFFF); chip::StringBuilderBase builder(protocolInfo, sizeof(protocolInfo)); @@ -228,7 +228,7 @@ CHIP_ERROR TraceDecoder::LogAndConsumeProtocol(Json::Value & json) builder.Add(protocolDetail); builder.Add(" ["); - builder.Add(ToProtocolName(id)); + builder.Add(ToProtocolName(vendorId, protocolId)); builder.Add(" "); memset(protocolDetail, '\0', sizeof(protocolDetail)); @@ -236,7 +236,7 @@ CHIP_ERROR TraceDecoder::LogAndConsumeProtocol(Json::Value & json) builder.Add(protocolDetail); builder.Add(" / "); - builder.Add(ToProtocolMessageTypeName(id, opcode)); + builder.Add(ToProtocolMessageTypeName(vendorId, protocolId, opcode)); builder.Add(" "); memset(protocolDetail, '\0', sizeof(protocolDetail)); @@ -278,11 +278,14 @@ CHIP_ERROR TraceDecoder::MaybeLogAndConsumePayload(Json::Value & json, bool isRe Log("data", payload.c_str()); } - bool shouldDecode = !isResponse || mOptions.mEnableProtocolInteractionModelResponse; - auto payload = json[kPayloadDataKey].asString(); - auto protocolId = json[kProtocolIdKey].asLargestUInt(); - auto protocolCode = json[kProtocolCodeKey].asLargestUInt(); - ReturnErrorOnFailure(LogAsProtocolMessage(protocolId, protocolCode, payload.c_str(), payload.size(), shouldDecode)); + bool shouldDecode = !isResponse || mOptions.mEnableProtocolInteractionModelResponse; + auto payload = json[kPayloadDataKey].asString(); + auto id = json[kProtocolIdKey].asLargestUInt(); + uint16_t vendorId = static_cast(id >> 16); + uint16_t protocolId = (id & 0xFFFF); + auto protocolCode = static_cast(json[kProtocolCodeKey].asLargestUInt()); + ReturnErrorOnFailure( + LogAsProtocolMessage(vendorId, protocolId, protocolCode, payload.c_str(), payload.size(), shouldDecode)); Log(" "); } diff --git a/examples/common/tracing/decoder/TraceDecoderProtocols.cpp b/examples/common/tracing/decoder/TraceDecoderProtocols.cpp index d50ccd77147b8f..e6881bd4361c8c 100644 --- a/examples/common/tracing/decoder/TraceDecoderProtocols.cpp +++ b/examples/common/tracing/decoder/TraceDecoderProtocols.cpp @@ -44,11 +44,11 @@ void ENFORCE_FORMAT(1, 2) TLVPrettyPrinter(const char * aFormat, ...) namespace chip { namespace trace { -const char * ToProtocolName(uint16_t protocolId) +const char * ToProtocolName(uint16_t vendorId, uint16_t protocolId) { const char * name = nullptr; - auto protocol = Protocols::Id(VendorId::Common, protocolId); + auto protocol = Protocols::Id(static_cast(vendorId), protocolId); if (protocol == Protocols::SecureChannel::Id) { name = secure_channel::ToProtocolName(); @@ -77,11 +77,11 @@ const char * ToProtocolName(uint16_t protocolId) return name; } -const char * ToProtocolMessageTypeName(uint16_t protocolId, uint8_t protocolCode) +const char * ToProtocolMessageTypeName(uint16_t vendorId, uint16_t protocolId, uint8_t protocolCode) { const char * name = nullptr; - auto protocol = Protocols::Id(VendorId::Common, protocolId); + auto protocol = Protocols::Id(static_cast(vendorId), protocolId); if (protocol == Protocols::SecureChannel::Id) { name = secure_channel::ToProtocolMessageTypeName(protocolCode); @@ -110,7 +110,7 @@ const char * ToProtocolMessageTypeName(uint16_t protocolId, uint8_t protocolCode return name; } -CHIP_ERROR LogAsProtocolMessage(uint16_t protocolId, uint8_t protocolCode, const char * payload, size_t len, +CHIP_ERROR LogAsProtocolMessage(uint16_t vendorId, uint16_t protocolId, uint8_t protocolCode, const char * payload, size_t len, bool interactionModelResponse) { constexpr uint16_t kMaxPayloadLen = 2048; @@ -120,7 +120,7 @@ CHIP_ERROR LogAsProtocolMessage(uint16_t protocolId, uint8_t protocolCode, const CHIP_ERROR err = CHIP_NO_ERROR; - auto protocol = Protocols::Id(VendorId::Common, protocolId); + auto protocol = Protocols::Id(static_cast(vendorId), protocolId); if (protocol == Protocols::SecureChannel::Id) { err = secure_channel::LogAsProtocolMessage(protocolCode, data, dataLen); diff --git a/examples/common/tracing/decoder/TraceDecoderProtocols.h b/examples/common/tracing/decoder/TraceDecoderProtocols.h index ae387c82e007df..3c9a49234f7a4d 100644 --- a/examples/common/tracing/decoder/TraceDecoderProtocols.h +++ b/examples/common/tracing/decoder/TraceDecoderProtocols.h @@ -26,11 +26,11 @@ namespace chip { namespace trace { -const char * ToProtocolName(uint16_t protocolId); +const char * ToProtocolName(uint16_t vendorId, uint16_t protocolId); -const char * ToProtocolMessageTypeName(uint16_t protocolId, uint8_t protocolCode); +const char * ToProtocolMessageTypeName(uint16_t vendorId, uint16_t protocolId, uint8_t protocolCode); -CHIP_ERROR LogAsProtocolMessage(uint16_t protocolId, uint8_t protocolCode, const char * payload, size_t len, +CHIP_ERROR LogAsProtocolMessage(uint16_t vendorId, uint16_t protocolId, uint8_t protocolCode, const char * payload, size_t len, bool interactionModelResponse); } // namespace trace diff --git a/examples/common/tracing/decoder/logging/Log.cpp b/examples/common/tracing/decoder/logging/Log.cpp index bc3cb74d82f117..4fa5d9dfeb8bfc 100644 --- a/examples/common/tracing/decoder/logging/Log.cpp +++ b/examples/common/tracing/decoder/logging/Log.cpp @@ -36,12 +36,12 @@ void ENFORCE_FORMAT(1, 2) LogFormatted(const char * format, ...) { char buffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE] = {}; - uint8_t indentation = gIndentLevel * kSpacePerIndent; + int indentation = gIndentLevel * kSpacePerIndent; snprintf(buffer, sizeof(buffer), "%*s", indentation, ""); va_list args; va_start(args, format); - vsnprintf(&buffer[indentation], sizeof(buffer) - indentation, format, args); + vsnprintf(&buffer[indentation], sizeof(buffer) - static_cast(indentation), format, args); va_end(args); ChipLogDetail(DataManagement, "%s", buffer); diff --git a/examples/common/tracing/decoder/logging/ToCertificateString.cpp b/examples/common/tracing/decoder/logging/ToCertificateString.cpp index fcc56d9ab50a37..ee2dfe30a9bc10 100644 --- a/examples/common/tracing/decoder/logging/ToCertificateString.cpp +++ b/examples/common/tracing/decoder/logging/ToCertificateString.cpp @@ -19,6 +19,7 @@ #include "ToCertificateString.h" #include +#include #include namespace { @@ -40,6 +41,12 @@ const char * ToCertificate(const chip::ByteSpan & source, chip::MutableCharSpan return destination.data(); } + if (!chip::CanCastTo(source.size())) + { + ChipLogError(DataManagement, "The certificate is too large to do base64 conversion on"); + return destination.data(); + } + size_t base64DataLen = BASE64_ENCODED_LEN(source.size()); size_t bufferLen = base64DataLen + 1; // add one character for null-terminator if (bufferLen + strlen(header) + strlen(footer) > destination.size()) @@ -51,7 +58,7 @@ const char * ToCertificate(const chip::ByteSpan & source, chip::MutableCharSpan chip::Platform::ScopedMemoryBuffer str; str.Alloc(bufferLen); - auto encodedLen = chip::Base64Encode(source.data(), source.size(), str.Get()); + auto encodedLen = chip::Base64Encode(source.data(), static_cast(source.size()), str.Get()); str.Get()[encodedLen] = '\0'; if (IsChipCertificate(source)) @@ -79,7 +86,8 @@ const char * ToCertificate(const chip::ByteSpan & source, chip::MutableCharSpan snprintf(destination.data(), destination.size(), "%s\n", header); for (; inIndex < base64DataLen; inIndex += 64) { - outIndex += snprintf(&destination.data()[outIndex], destination.size() - outIndex, "%.64s\n", &str[inIndex]); + auto charsPrinted = snprintf(&destination.data()[outIndex], destination.size() - outIndex, "%.64s\n", &str[inIndex]); + outIndex += static_cast(charsPrinted); } snprintf(&destination.data()[outIndex], destination.size() - outIndex, "%s", footer); } diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index 1bee06f8773b3b..44c03c784c4ab9 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -165,7 +165,7 @@ class ReplyDelegate : public mdns::Minimal::ServerDelegate, public mdns::Minimal mdns::Minimal::ResponseSender * mResponder; const Inet::IPPacketInfo * mCurrentSource = nullptr; - uint32_t mMessageId = 0; + uint16_t mMessageId = 0; }; mdns::Minimal::Server<10 /* endpoints */> gMdnsServer; diff --git a/examples/platform/linux/Options.h b/examples/platform/linux/Options.h index 3f15872f0f190d..258ea826bb5c22 100644 --- a/examples/platform/linux/Options.h +++ b/examples/platform/linux/Options.h @@ -48,11 +48,11 @@ struct LinuxDeviceOptions bool mWiFi = false; bool mThread = false; #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS - uint32_t securedDevicePort = CHIP_PORT; - uint32_t unsecuredCommissionerPort = CHIP_UDC_PORT; + uint16_t securedDevicePort = CHIP_PORT; + uint16_t unsecuredCommissionerPort = CHIP_UDC_PORT; #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE - uint32_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12? + uint16_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12? #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE const char * command = nullptr; const char * PICS = nullptr; diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index d601f0b54764b8..efd5d74944a4e6 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -76,4 +76,6 @@ static_library("shell_common") { } public_configs = [ ":shell_common_config" ] + + cflags = [ "-Wconversion" ] } diff --git a/examples/shell/shell_common/cmd_server.cpp b/examples/shell/shell_common/cmd_server.cpp index 46f95de11b2127..d18eb88cf7a1b0 100644 --- a/examples/shell/shell_common/cmd_server.cpp +++ b/examples/shell/shell_common/cmd_server.cpp @@ -170,7 +170,7 @@ static CHIP_ERROR CmdAppServerClusters(int argc, char ** argv) { bool server = true; - for (int i = 0; i < emberAfEndpointCount(); i++) + for (uint16_t i = 0; i < emberAfEndpointCount(); i++) { EndpointId endpoint = emberAfEndpointFromIndex(i); @@ -190,7 +190,7 @@ static CHIP_ERROR CmdAppServerClusters(int argc, char ** argv) static CHIP_ERROR CmdAppServerEndpoints(int argc, char ** argv) { - for (int i = 0; i < emberAfEndpointCount(); i++) + for (uint16_t i = 0; i < emberAfEndpointCount(); i++) { EndpointId endpoint = emberAfEndpointFromIndex(i); diff --git a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h index f67b4d9df93456..60aea4867d18f2 100644 --- a/examples/tv-casting-app/tv-casting-common/include/CastingServer.h +++ b/examples/tv-casting-app/tv-casting-common/include/CastingServer.h @@ -436,7 +436,7 @@ class CastingServer TargetVideoPlayerInfo mCachedTargetVideoPlayerInfo[kMaxCachedVideoPlayers]; uint16_t mTargetVideoPlayerVendorId = 0; uint16_t mTargetVideoPlayerProductId = 0; - uint16_t mTargetVideoPlayerDeviceType = 0; + chip::DeviceTypeId mTargetVideoPlayerDeviceType = 0; char mTargetVideoPlayerDeviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {}; size_t mTargetVideoPlayerNumIPs = 0; // number of valid IP addresses chip::Inet::IPAddress mTargetVideoPlayerIpAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses]; 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 f98116f3c7ca27..35a9e22f97ec5a 100644 --- a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h +++ b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h @@ -37,7 +37,7 @@ class TargetVideoPlayerInfo bool IsInitialized() { return mInitialized; } uint16_t GetVendorId() const { return mVendorId; } uint16_t GetProductId() const { return mProductId; } - uint16_t GetDeviceType() const { return mDeviceType; } + chip::DeviceTypeId GetDeviceType() const { return mDeviceType; } chip::NodeId GetNodeId() const { return mNodeId; } chip::FabricIndex GetFabricIndex() const { return mFabricIndex; } const char * GetDeviceName() const { return mDeviceName; } @@ -58,7 +58,7 @@ class TargetVideoPlayerInfo CHIP_ERROR Initialize(chip::NodeId nodeId, chip::FabricIndex fabricIndex, std::function onConnectionSuccess, std::function onConnectionFailure, uint16_t vendorId = 0, uint16_t productId = 0, - uint16_t deviceType = 0, const char * deviceName = {}, size_t numIPs = 0, + chip::DeviceTypeId deviceType = 0, const char * deviceName = {}, size_t numIPs = 0, chip::Inet::IPAddress * ipAddressList = nullptr); CHIP_ERROR FindOrEstablishCASESession(std::function onConnectionSuccess, std::function onConnectionFailure); diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp index f21fde3883256a..bff3bb2fa8380b 100644 --- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp @@ -26,7 +26,7 @@ CASEClientPool gCASEClientPool; CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIndex, std::function onConnectionSuccess, std::function onConnectionFailure, uint16_t vendorId, - uint16_t productId, uint16_t deviceType, const char * deviceName, size_t numIPs, + uint16_t productId, DeviceTypeId deviceType, const char * deviceName, size_t numIPs, chip::Inet::IPAddress * ipAddress) { ChipLogProgress(NotSpecified, "TargetVideoPlayerInfo nodeId=0x" ChipLogFormatX64 " fabricIndex=%d", ChipLogValueX64(nodeId), diff --git a/src/lib/dnssd/Advertiser.h b/src/lib/dnssd/Advertiser.h index 710fc64bc4596f..45cd072c1db11c 100644 --- a/src/lib/dnssd/Advertiser.h +++ b/src/lib/dnssd/Advertiser.h @@ -63,7 +63,7 @@ class BaseAdvertisingParams mPort = port; return *reinterpret_cast(this); } - uint64_t GetPort() const { return mPort; } + uint16_t GetPort() const { return mPort; } Derived & SetInterfaceId(Inet::InterfaceId interfaceId) { diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index 47ee3b10e7d073..679c8bae7d3e48 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -236,8 +236,9 @@ class AdvertiserMinMdns : public ServiceAdvertiser, "MRP retry interval idle value exceeds allowed range of 1 hour, using maximum available"); mrp.mIdleRetransTimeout = kMaxRetryInterval; } - size_t writtenCharactersNumber = snprintf(storage.sleepyIdleIntervalBuf, sizeof(storage.sleepyIdleIntervalBuf), - "SII=%" PRIu32, mrp.mIdleRetransTimeout.count()); + size_t writtenCharactersNumber = + static_cast(snprintf(storage.sleepyIdleIntervalBuf, sizeof(storage.sleepyIdleIntervalBuf), + "SII=%" PRIu32, mrp.mIdleRetransTimeout.count())); VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < sizeof(storage.sleepyIdleIntervalBuf)), CHIP_ERROR_INVALID_STRING_LENGTH); @@ -252,8 +253,9 @@ class AdvertiserMinMdns : public ServiceAdvertiser, "MRP retry interval active value exceeds allowed range of 1 hour, using maximum available"); mrp.mActiveRetransTimeout = kMaxRetryInterval; } - size_t writtenCharactersNumber = snprintf(storage.sleepyActiveIntervalBuf, sizeof(storage.sleepyActiveIntervalBuf), - "SAI=%" PRIu32, mrp.mActiveRetransTimeout.count()); + size_t writtenCharactersNumber = + static_cast(snprintf(storage.sleepyActiveIntervalBuf, sizeof(storage.sleepyActiveIntervalBuf), + "SAI=%" PRIu32, mrp.mActiveRetransTimeout.count())); VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < sizeof(storage.sleepyActiveIntervalBuf)), CHIP_ERROR_INVALID_STRING_LENGTH); @@ -262,8 +264,8 @@ class AdvertiserMinMdns : public ServiceAdvertiser, } if (params.GetTcpSupported().HasValue()) { - size_t writtenCharactersNumber = - snprintf(storage.tcpSupportedBuf, sizeof(storage.tcpSupportedBuf), "T=%d", params.GetTcpSupported().Value()); + size_t writtenCharactersNumber = static_cast( + snprintf(storage.tcpSupportedBuf, sizeof(storage.tcpSupportedBuf), "T=%d", params.GetTcpSupported().Value())); VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < sizeof(storage.tcpSupportedBuf)), CHIP_ERROR_INVALID_STRING_LENGTH); txtFields[numTxtFields++] = storage.tcpSupportedBuf; @@ -290,7 +292,7 @@ class AdvertiserMinMdns : public ServiceAdvertiser, // current request handling const chip::Inet::IPPacketInfo * mCurrentSource = nullptr; - uint32_t mMessageId = 0; + uint16_t mMessageId = 0; const char * mEmptyTextEntries[1] = { "=", diff --git a/src/lib/dnssd/BUILD.gn b/src/lib/dnssd/BUILD.gn index e723dd54466600..b33b304f195df6 100644 --- a/src/lib/dnssd/BUILD.gn +++ b/src/lib/dnssd/BUILD.gn @@ -69,4 +69,6 @@ static_library("dnssd") { } else { assert(false, "Unknown Dnssd advertiser implementation.") } + + cflags = [ "-Wconversion" ] } diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index 9f4698a40db563..5f48378bd01d4e 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -149,13 +149,12 @@ struct CommissionNodeData uint16_t vendorId = 0; uint16_t productId = 0; uint8_t commissioningMode = 0; - // TODO: possibly 32-bit - see spec issue #3226 - uint16_t deviceType = 0; - char deviceName[kMaxDeviceNameLen + 1] = {}; - uint8_t rotatingId[kMaxRotatingIdLen] = {}; - size_t rotatingIdLen = 0; - uint16_t pairingHint = 0; - char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; + uint32_t deviceType = 0; + char deviceName[kMaxDeviceNameLen + 1] = {}; + uint8_t rotatingId[kMaxRotatingIdLen] = {}; + size_t rotatingIdLen = 0; + uint16_t pairingHint = 0; + char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; CommissionNodeData() {} @@ -190,7 +189,7 @@ struct CommissionNodeData } if (deviceType > 0) { - ChipLogDetail(Discovery, "\tDevice Type: %u", deviceType); + ChipLogDetail(Discovery, "\tDevice Type: %" PRIu32, deviceType); } if (longDiscriminator > 0) { diff --git a/src/lib/dnssd/ServiceNaming.cpp b/src/lib/dnssd/ServiceNaming.cpp index 16aedd8211707a..25bdfbf2cbf341 100644 --- a/src/lib/dnssd/ServiceNaming.cpp +++ b/src/lib/dnssd/ServiceNaming.cpp @@ -84,7 +84,7 @@ CHIP_ERROR MakeHostName(char * buffer, size_t bufferLen, const chip::ByteSpan & { ReturnErrorCodeIf(bufferLen < macOrEui64.size() * 2 + 1, CHIP_ERROR_BUFFER_TOO_SMALL); - size_t idx = 0; + int idx = 0; for (size_t i = 0; i < macOrEui64.size(); ++i) { idx += snprintf(buffer + idx, 3, "%02X", macOrEui64.data()[i]); @@ -94,7 +94,7 @@ CHIP_ERROR MakeHostName(char * buffer, size_t bufferLen, const chip::ByteSpan & CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter subtype) { - size_t requiredSize; + int requiredSize; switch (subtype.type) { case DiscoveryFilterType::kShortDiscriminator: @@ -135,7 +135,7 @@ CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter s break; case DiscoveryFilterType::kCompressedFabricId: requiredSize = snprintf(buffer, bufferLen, "_I"); - return Encoding::Uint64ToHex(subtype.code, &buffer[requiredSize], bufferLen - requiredSize, + return Encoding::Uint64ToHex(subtype.code, &buffer[requiredSize], bufferLen - static_cast(requiredSize), Encoding::HexFlags::kUppercaseAndNullTerminate); break; case DiscoveryFilterType::kInstanceName: @@ -146,12 +146,12 @@ CHIP_ERROR MakeServiceSubtype(char * buffer, size_t bufferLen, DiscoveryFilter s buffer[0] = '\0'; break; } - return (requiredSize <= (bufferLen - 1)) ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; + return (static_cast(requiredSize) <= (bufferLen - 1)) ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; } CHIP_ERROR MakeServiceTypeName(char * buffer, size_t bufferLen, DiscoveryFilter nameDesc, DiscoveryType type) { - size_t requiredSize; + int requiredSize; if (nameDesc.type == DiscoveryFilterType::kNone) { if (type == DiscoveryType::kCommissionableNode) @@ -192,7 +192,7 @@ CHIP_ERROR MakeServiceTypeName(char * buffer, size_t bufferLen, DiscoveryFilter } } - return (requiredSize <= (bufferLen - 1)) ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; + return (static_cast(requiredSize) <= (bufferLen - 1)) ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; } } // namespace Dnssd diff --git a/src/lib/dnssd/TxtFields.cpp b/src/lib/dnssd/TxtFields.cpp index 33840b9cd2ced5..a09efaaf5aa4b9 100644 --- a/src/lib/dnssd/TxtFields.cpp +++ b/src/lib/dnssd/TxtFields.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -49,9 +50,11 @@ bool IsKey(const ByteSpan & key, const char * desired) { return false; } + + auto desired_bytes = Uint8::from_const_char(desired); for (size_t i = 0; i < key.size(); ++i) { - if (SafeToLower(key.data()[i]) != SafeToLower(desired[i])) + if (SafeToLower(key.data()[i]) != SafeToLower(desired_bytes[i])) { return false; } @@ -104,8 +107,8 @@ bool MakeBoolFromAsciiDecimal(const ByteSpan & val) size_t GetPlusSignIdx(const ByteSpan & value) { - // Fist value is the vendor id, second (after the +) is the product. - for (int i = 0; i < static_cast(value.size()); ++i) + // First value is the vendor id, second (after the +) is the product. + for (size_t i = 0; i < value.size(); ++i) { if (static_cast(value.data()[i]) == '+') { diff --git a/src/lib/dnssd/minimal_mdns/BUILD.gn b/src/lib/dnssd/minimal_mdns/BUILD.gn index 927b881f2aabfc..bf0ae8abef3ae4 100644 --- a/src/lib/dnssd/minimal_mdns/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/BUILD.gn @@ -92,6 +92,8 @@ static_library("default_policy") { ":address_policy", "${chip_root}/src/inet", ] + + cflags = [ "-Wconversion" ] } if (current_os == "linux" && chip_minmdns_default_policy == "libnl") { @@ -156,4 +158,6 @@ static_library("minimal_mdns") { } public_configs = [ ":config" ] + + cflags = [ "-Wconversion" ] } diff --git a/src/lib/dnssd/minimal_mdns/Parser.cpp b/src/lib/dnssd/minimal_mdns/Parser.cpp index 8bc3e9e1af3bb4..4cd341da977677 100644 --- a/src/lib/dnssd/minimal_mdns/Parser.cpp +++ b/src/lib/dnssd/minimal_mdns/Parser.cpp @@ -75,7 +75,7 @@ bool QueryData::Append(HeaderRef & hdr, RecordWriter & out) const out.WriteQName(GetName()) .Put16(static_cast(mType)) - .Put16(static_cast(mClass) | (mAnswerViaUnicast ? kQClassUnicastAnswerFlag : 0)); + .Put16(static_cast(static_cast(mClass) | (mAnswerViaUnicast ? kQClassUnicastAnswerFlag : 0))); if (!out.Fit()) { diff --git a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp index ef530355c02ed3..722ca973902fb3 100644 --- a/src/lib/dnssd/minimal_mdns/ResponseSender.cpp +++ b/src/lib/dnssd/minimal_mdns/ResponseSender.cpp @@ -100,7 +100,7 @@ bool ResponseSender::HasQueryResponders() const return false; } -CHIP_ERROR ResponseSender::Respond(uint32_t messageId, const QueryData & query, const chip::Inet::IPPacketInfo * querySource, +CHIP_ERROR ResponseSender::Respond(uint16_t messageId, const QueryData & query, const chip::Inet::IPPacketInfo * querySource, const ResponseConfiguration & configuration) { mSendState.Reset(messageId, query, querySource); diff --git a/src/lib/dnssd/minimal_mdns/ResponseSender.h b/src/lib/dnssd/minimal_mdns/ResponseSender.h index cf1b80f5d97f65..636acaaf7acf14 100644 --- a/src/lib/dnssd/minimal_mdns/ResponseSender.h +++ b/src/lib/dnssd/minimal_mdns/ResponseSender.h @@ -53,7 +53,7 @@ class ResponseSendingState public: ResponseSendingState() {} - void Reset(uint32_t messageId, const QueryData & query, const chip::Inet::IPPacketInfo * packet) + void Reset(uint16_t messageId, const QueryData & query, const chip::Inet::IPPacketInfo * packet) { mMessageId = messageId; mQuery = &query; @@ -72,7 +72,7 @@ class ResponseSendingState } CHIP_ERROR GetError() const { return mSendError; } - uint32_t GetMessageId() const { return mMessageId; } + uint16_t GetMessageId() const { return mMessageId; } const QueryData * GetQuery() const { return mQuery; } @@ -91,7 +91,7 @@ class ResponseSendingState private: const QueryData * mQuery = nullptr; // query being replied to const chip::Inet::IPPacketInfo * mSource = nullptr; // Where to send the reply (if unicast) - uint32_t mMessageId = 0; // message id for the reply + uint16_t mMessageId = 0; // message id for the reply ResourceType mResourceType = ResourceType::kAnswer; // what is being sent right now CHIP_ERROR mSendError = CHIP_NO_ERROR; }; @@ -112,7 +112,7 @@ class ResponseSender : public ResponderDelegate bool HasQueryResponders() const; /// Send back the response to a particular query - CHIP_ERROR Respond(uint32_t messageId, const QueryData & query, const chip::Inet::IPPacketInfo * querySource, + CHIP_ERROR Respond(uint16_t messageId, const QueryData & query, const chip::Inet::IPPacketInfo * querySource, const ResponseConfiguration & configuration); // Implementation of ResponderDelegate diff --git a/src/lib/dnssd/minimal_mdns/core/QName.cpp b/src/lib/dnssd/minimal_mdns/core/QName.cpp index 94a15bb4e8bba8..2cc6488cfb1503 100644 --- a/src/lib/dnssd/minimal_mdns/core/QName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/QName.cpp @@ -60,7 +60,7 @@ bool SerializedQNameIterator::Next(bool followIndirectPointers) return false; } - size_t offset = ((*mCurrentPosition & 0x3F) << 8) | *(mCurrentPosition + 1); + size_t offset = static_cast(((*mCurrentPosition & 0x3F) << 8) | *(mCurrentPosition + 1)); if (offset > mLookBehindMax) { // Potential infinite recursion. diff --git a/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp b/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp index c03bb32990506f..0249d80d6e35ff 100644 --- a/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp +++ b/src/lib/dnssd/minimal_mdns/core/RecordWriter.cpp @@ -135,7 +135,7 @@ void RecordWriter::RememberWrittenQnameOffset(size_t offset) { if (previousName == kInvalidOffset) { - previousName = offset; + previousName = static_cast(offset); return; } } diff --git a/src/lib/dnssd/minimal_mdns/core/RecordWriter.h b/src/lib/dnssd/minimal_mdns/core/RecordWriter.h index 0356f7e4b2643e..35e563fe870ec2 100644 --- a/src/lib/dnssd/minimal_mdns/core/RecordWriter.h +++ b/src/lib/dnssd/minimal_mdns/core/RecordWriter.h @@ -110,7 +110,7 @@ class RecordWriter { if (previous == name) { - return chip::Optional::Value(previous.OffsetInCurrentValidData()); + return chip::MakeOptional(static_cast(previous.OffsetInCurrentValidData())); } if (!previous.Next())