From 09e686cd11ca14cc0321f4f1fb4c0a298cb7f4fb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 25 Jun 2021 15:29:20 -0400 Subject: [PATCH] Add -Wconversion to various things in src/app (#7902) * Add -Wconversion to various things in src/app. * Regenerate generated files --- .../gen/attribute-size.cpp | 18 +++++++--- examples/lighting-app/k32w/main/AppTask.cpp | 2 +- examples/lighting-app/qpg6100/src/AppTask.cpp | 4 +-- examples/lock-app/k32w/main/AppTask.cpp | 2 +- examples/lock-app/qpg6100/src/AppTask.cpp | 2 +- .../tv-app/tv-common/gen/attribute-size.cpp | 9 +++-- src/app/chip_data_model.gni | 6 ++++ .../color-control-server.cpp | 8 ++--- .../door-lock-server-user.cpp | 4 +-- .../operational-credentials-server.cpp | 2 +- src/app/clusters/scenes/scenes.cpp | 8 ++--- src/app/server/BUILD.gn | 2 ++ src/app/server/OnboardingCodesUtil.cpp | 7 ++-- src/app/tests/integration/BUILD.gn | 2 ++ src/app/tests/integration/MockEvents.cpp | 2 +- src/app/tests/integration/MockEvents.h | 18 +++++----- src/app/util/af-enums.h | 2 +- src/app/util/af.h | 8 +++++ src/app/util/attribute-storage.cpp | 10 +++--- src/app/util/attribute-table.cpp | 2 +- .../util/ember-compatibility-functions.cpp | 3 +- src/app/util/message.cpp | 5 +++ src/app/util/process-global-message.cpp | 6 ++-- src/app/util/util.cpp | 2 +- src/app/util/util.h | 1 + .../app/CHIPClientCallbacks-src.zapt | 4 +-- .../templates/app/attribute-size-src.zapt | 9 +++-- src/app/zap-templates/templates/app/helper.js | 5 +++ .../data_model/gen/CHIPClientCallbacks.cpp | 34 +++++++++---------- 29 files changed, 120 insertions(+), 67 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/gen/attribute-size.cpp b/examples/all-clusters-app/all-clusters-common/gen/attribute-size.cpp index cff2cebbffe20e..96172ed05f4f66 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/attribute-size.cpp +++ b/examples/all-clusters-app/all-clusters-common/gen/attribute-size.cpp @@ -138,7 +138,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo { case 0x0000: // accepts header list { - entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, index - 1); + entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, static_cast(index - 1)); if (entryOffset == 0) { ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index); @@ -155,7 +155,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo return 0; } - entryLength = acceptsHeaderListSpan->size(); + if (!CanCastTo(acceptsHeaderListSpan->size())) + { + ChipLogError(Zcl, "Span size %zu is too large", acceptsHeaderListSpan->size()); + return 0; + } + entryLength = static_cast(acceptsHeaderListSpan->size()); break; } case 0x0001: // supported streaming types @@ -548,7 +553,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo } case 0x001B: // list_octet_string { - entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, index - 1); + entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, static_cast(index - 1)); if (entryOffset == 0) { ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index); @@ -565,7 +570,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo return 0; } - entryLength = listOctetStringSpan->size(); + if (!CanCastTo(listOctetStringSpan->size())) + { + ChipLogError(Zcl, "Span size %zu is too large", listOctetStringSpan->size()); + return 0; + } + entryLength = static_cast(listOctetStringSpan->size()); break; } case 0x001C: // list_struct_octet_string diff --git a/examples/lighting-app/k32w/main/AppTask.cpp b/examples/lighting-app/k32w/main/AppTask.cpp index 5e908ef88839a9..b533022336331d 100644 --- a/examples/lighting-app/k32w/main/AppTask.cpp +++ b/examples/lighting-app/k32w/main/AppTask.cpp @@ -627,6 +627,6 @@ void AppTask::UpdateClusterState(void) (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx32, status); + ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status); } } diff --git a/examples/lighting-app/qpg6100/src/AppTask.cpp b/examples/lighting-app/qpg6100/src/AppTask.cpp index 69d1168ffec8a5..6a61b79167e82e 100644 --- a/examples/lighting-app/qpg6100/src/AppTask.cpp +++ b/examples/lighting-app/qpg6100/src/AppTask.cpp @@ -457,7 +457,7 @@ void AppTask::UpdateClusterState(void) (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx32, status); + ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status); } newValue = LightingMgr().GetLevel(); @@ -466,6 +466,6 @@ void AppTask::UpdateClusterState(void) if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogError(NotSpecified, "ERR: updating level %" PRIx32, status); + ChipLogError(NotSpecified, "ERR: updating level %" PRIx8, status); } } diff --git a/examples/lock-app/k32w/main/AppTask.cpp b/examples/lock-app/k32w/main/AppTask.cpp index f313eea609104e..c43ea7364bc1c9 100644 --- a/examples/lock-app/k32w/main/AppTask.cpp +++ b/examples/lock-app/k32w/main/AppTask.cpp @@ -635,6 +635,6 @@ void AppTask::UpdateClusterState(void) (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx32, status); + ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status); } } diff --git a/examples/lock-app/qpg6100/src/AppTask.cpp b/examples/lock-app/qpg6100/src/AppTask.cpp index 6a406f7c44575e..aa6d7738dbe1a2 100644 --- a/examples/lock-app/qpg6100/src/AppTask.cpp +++ b/examples/lock-app/qpg6100/src/AppTask.cpp @@ -490,6 +490,6 @@ void AppTask::UpdateClusterState(void) (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx32, status); + ChipLogError(NotSpecified, "ERR: updating on/off %" PRIx8, status); } } diff --git a/examples/tv-app/tv-common/gen/attribute-size.cpp b/examples/tv-app/tv-common/gen/attribute-size.cpp index 1a8c6cc4d78fd3..d2cd645eb78ab6 100644 --- a/examples/tv-app/tv-common/gen/attribute-size.cpp +++ b/examples/tv-app/tv-common/gen/attribute-size.cpp @@ -138,7 +138,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo { case 0x0000: // accepts header list { - entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, index - 1); + entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, static_cast(index - 1)); if (entryOffset == 0) { ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index); @@ -155,7 +155,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo return 0; } - entryLength = acceptsHeaderListSpan->size(); + if (!CanCastTo(acceptsHeaderListSpan->size())) + { + ChipLogError(Zcl, "Span size %zu is too large", acceptsHeaderListSpan->size()); + return 0; + } + entryLength = static_cast(acceptsHeaderListSpan->size()); break; } case 0x0001: // supported streaming types diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index d35a180ef8845a..a0ae28d2d653e3 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -183,6 +183,12 @@ template("chip_data_model") { public_deps += [ "${chip_root}/src/app/server" ] } + if (!defined(cflags)) { + cflags = [] + } + + cflags += [ "-Wconversion" ] + if (!defined(public_configs)) { public_configs = [] } diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index eedefb8d105bcf..2522cb35839aa5 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -196,7 +196,7 @@ static uint16_t readColorTemperature(EndpointId endpoint) static uint16_t readColorTemperatureMin(EndpointId endpoint) { uint16_t colorTemperatureMin; - EmberStatus status; + EmberAfStatus status; status = emberAfReadServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_ATTRIBUTE_ID, @@ -213,7 +213,7 @@ static uint16_t readColorTemperatureMin(EndpointId endpoint) static uint16_t readColorTemperatureMax(EndpointId endpoint) { uint16_t colorTemperatureMax; - EmberStatus status; + EmberAfStatus status; status = emberAfReadServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_ATTRIBUTE_ID, @@ -230,7 +230,7 @@ static uint16_t readColorTemperatureMax(EndpointId endpoint) static uint16_t readColorTemperatureCoupleToLevelMin(EndpointId endpoint) { uint16_t colorTemperatureCoupleToLevelMin; - EmberStatus status; + EmberAfStatus status; status = emberAfReadServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_TEMPERATURE_LEVEL_MIN_MIREDS_ATTRIBUTE_ID, @@ -248,7 +248,7 @@ static uint16_t readColorTemperatureCoupleToLevelMin(EndpointId endpoint) static uint8_t readLevelControlCurrentLevel(EndpointId endpoint) { uint8_t currentLevel; - EmberStatus status; + EmberAfStatus status; status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, (uint8_t *) ¤tLevel, sizeof(uint8_t)); diff --git a/src/app/clusters/door-lock-server/door-lock-server-user.cpp b/src/app/clusters/door-lock-server/door-lock-server-user.cpp index 7026ca4dcc9ea3..39e1aa380c5142 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-user.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-user.cpp @@ -595,13 +595,13 @@ static void printSuccessOrFailure(bool success) static bool verifyPin(uint8_t * pin, uint8_t * userId) { bool pinRequired = false; - EmberStatus status; + EmberAfStatus status; uint8_t i; status = emberAfReadServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, ZCL_REQUIRE_PIN_FOR_RF_OPERATION_ATTRIBUTE_ID, (uint8_t *) &pinRequired, sizeof(pinRequired)); - if (EMBER_SUCCESS != status || !pinRequired) + if (EMBER_ZCL_STATUS_SUCCESS != status || !pinRequired) { return true; } diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index fc53d00ea1c853..0e91851a9f2cb2 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -108,7 +108,7 @@ CHIP_ERROR writeAdminsIntoFabricsListAttribute() CHIP_ERROR err = CHIP_NO_ERROR; // Loop through admins - uint32_t fabricIndex = 0; + int32_t fabricIndex = 0; for (auto & pairing : GetGlobalAdminPairingTable()) { NodeId nodeId = pairing.GetNodeId(); diff --git a/src/app/clusters/scenes/scenes.cpp b/src/app/clusters/scenes/scenes.cpp index f50ea9ee0fc42a..72393ff7f42b61 100644 --- a/src/app/clusters/scenes/scenes.cpp +++ b/src/app/clusters/scenes/scenes.cpp @@ -857,8 +857,8 @@ bool emberAfPluginScenesServerParseAddScene(chip::app::Command * commandObj, con entry.hasOccupiedCoolingSetpointValue = true; entry.occupiedCoolingSetpointValue = (int16_t) emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length -= 2; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = static_cast(length - 2); if (length < 2) { break; @@ -866,8 +866,8 @@ bool emberAfPluginScenesServerParseAddScene(chip::app::Command * commandObj, con entry.hasOccupiedHeatingSetpointValue = true; entry.occupiedHeatingSetpointValue = (int16_t) emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length -= 2; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = static_cast(length - 2); if (length < 1) { break; diff --git a/src/app/server/BUILD.gn b/src/app/server/BUILD.gn index a7eace451aa171..4207850fcdb21d 100644 --- a/src/app/server/BUILD.gn +++ b/src/app/server/BUILD.gn @@ -43,6 +43,8 @@ static_library("server") { public_configs = [ ":server_config" ] + cflags = [ "-Wconversion" ] + public_deps = [ "${chip_root}/src/app", "${chip_root}/src/lib/mdns", diff --git a/src/app/server/OnboardingCodesUtil.cpp b/src/app/server/OnboardingCodesUtil.cpp index dd82b30c32bc26..99f6a3dc3f8888 100644 --- a/src/app/server/OnboardingCodesUtil.cpp +++ b/src/app/server/OnboardingCodesUtil.cpp @@ -145,10 +145,11 @@ CHIP_ERROR GetQRCodeUrl(char * aQRCodeUrl, size_t aUrlMaxSize, const std::string CHIP_ERROR_BUFFER_TOO_SMALL); const int writtenDataSize = snprintf(aQRCodeUrl, aUrlMaxSize, "%s%s", kQrCodeBaseUrl, kUrlDataAssignmentPhrase); - VerifyOrReturnError((writtenDataSize > 0) && (writtenDataSize < static_cast(aUrlMaxSize)), + VerifyOrReturnError((writtenDataSize > 0) && (static_cast(writtenDataSize) < aUrlMaxSize), CHIP_ERROR_INVALID_STRING_LENGTH); - return EncodeQRCodeToUrl(aQRCode.c_str(), aQRCode.size(), aQRCodeUrl + writtenDataSize, aUrlMaxSize - writtenDataSize); + return EncodeQRCodeToUrl(aQRCode.c_str(), aQRCode.size(), aQRCodeUrl + writtenDataSize, + aUrlMaxSize - static_cast(writtenDataSize)); } CHIP_ERROR GetManualPairingCode(std::string & aManualPairingCode, chip::RendezvousInformationFlags aRendezvousFlags) @@ -186,7 +187,7 @@ CHIP_ERROR EncodeQRCodeToUrl(const char * aQRCode, size_t aLen, char * aUrl, siz for (i = 0; i < aLen; ++i) { - unsigned char c = aQRCode[i]; + char c = aQRCode[i]; if (isCharUnreservedInRfc3986(c)) { diff --git a/src/app/tests/integration/BUILD.gn b/src/app/tests/integration/BUILD.gn index 90db83c5a794e6..5c0088f8470645 100644 --- a/src/app/tests/integration/BUILD.gn +++ b/src/app/tests/integration/BUILD.gn @@ -53,6 +53,8 @@ executable("chip-im-responder") { "${chip_root}/src/system", ] + cflags = [ "-Wconversion" ] + output_dir = root_out_dir } diff --git a/src/app/tests/integration/MockEvents.cpp b/src/app/tests/integration/MockEvents.cpp index 98a270377d229c..1836814c9632ab 100644 --- a/src/app/tests/integration/MockEvents.cpp +++ b/src/app/tests/integration/MockEvents.cpp @@ -132,7 +132,7 @@ MockEventGeneratorImpl::MockEventGeneratorImpl(void) : {} CHIP_ERROR MockEventGeneratorImpl::Init(chip::Messaging::ExchangeManager * apExchangeMgr, EventGenerator * apEventGenerator, - int aDelayBetweenEvents, bool aWraparound) + uint32_t aDelayBetweenEvents, bool aWraparound) { CHIP_ERROR err = CHIP_NO_ERROR; mpExchangeMgr = apExchangeMgr; diff --git a/src/app/tests/integration/MockEvents.h b/src/app/tests/integration/MockEvents.h index 864ba6c6e28dff..e79d05e6fc52fc 100644 --- a/src/app/tests/integration/MockEvents.h +++ b/src/app/tests/integration/MockEvents.h @@ -50,28 +50,28 @@ class MockEventGenerator public: static MockEventGenerator * GetInstance(void); virtual CHIP_ERROR Init(chip::Messaging::ExchangeManager * apExchangeMgr, EventGenerator * apEventGenerator, - int aDelayBetweenEvents, bool aWraparound) = 0; - virtual void SetEventGeneratorStop() = 0; - virtual bool IsEventGeneratorStopped() = 0; - virtual ~MockEventGenerator() = default; + uint32_t aDelayBetweenEvents, bool aWraparound) = 0; + virtual void SetEventGeneratorStop() = 0; + virtual bool IsEventGeneratorStopped() = 0; + virtual ~MockEventGenerator() = default; }; class MockEventGeneratorImpl : public MockEventGenerator { public: MockEventGeneratorImpl(void); - CHIP_ERROR Init(chip::Messaging::ExchangeManager * apExchangeMgr, EventGenerator * apEventGenerator, int aDelayBetweenEvents, - bool aWraparound); + CHIP_ERROR Init(chip::Messaging::ExchangeManager * apExchangeMgr, EventGenerator * apEventGenerator, + uint32_t aDelayBetweenEvents, bool aWraparound); void SetEventGeneratorStop(); bool IsEventGeneratorStopped(); private: static void HandleNextEvent(chip::System::Layer * apSystemLayer, void * apAppState, chip::System::Error aErr); chip::Messaging::ExchangeManager * mpExchangeMgr; - int mTimeBetweenEvents; //< delay, in miliseconds, between events. - bool mEventWraparound; //< does the event generator run indefinitely, or does it stop after iterating through its states + uint32_t mTimeBetweenEvents; //< delay, in miliseconds, between events. + bool mEventWraparound; //< does the event generator run indefinitely, or does it stop after iterating through its states EventGenerator * mpEventGenerator; //< the event generator to use - int32_t mEventsLeft; + size_t mEventsLeft; }; enum LivenessDeviceStatus diff --git a/src/app/util/af-enums.h b/src/app/util/af-enums.h index 1c299246cf7696..ed864325a445f2 100644 --- a/src/app/util/af-enums.h +++ b/src/app/util/af-enums.h @@ -22,7 +22,7 @@ #include -enum EmberAfStatus : uint32_t +enum EmberAfStatus : uint8_t { EMBER_ZCL_STATUS_SUCCESS = 0x00, EMBER_ZCL_STATUS_FAILURE = 0x01, diff --git a/src/app/util/af.h b/src/app/util/af.h index ae8128aa0cf54d..5a993041c6b7da 100644 --- a/src/app/util/af.h +++ b/src/app/util/af.h @@ -72,6 +72,8 @@ #include #include +#include + /** @name Attribute Storage */ // @{ @@ -496,21 +498,26 @@ bool emberAfIsTypeSigned(EmberAfAttributeType dataType); * @brief Function that extracts a 64-bit integer from the message buffer */ uint64_t emberAfGetInt64u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen); +#define emberAfGetInt64s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt64u(message, currentIndex, msgLen)) /** * @brief Function that extracts a 32-bit integer from the message buffer */ uint32_t emberAfGetInt32u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen); +#define emberAfGetInt32s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt32u(message, currentIndex, msgLen)) /** * @brief Function that extracts a 24-bit integer from the message buffer */ uint32_t emberAfGetInt24u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen); +#define emberAfGetInt24s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt24u(message, currentIndex, msgLen)) /** * @brief Function that extracts a 16-bit integer from the message buffer */ uint16_t emberAfGetInt16u(const uint8_t * message, uint16_t currentIndex, uint16_t msgLen); +#define emberAfGetInt16s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt16u(message, currentIndex, msgLen)) + /** * @brief Function that extracts a ZCL string from the message buffer */ @@ -529,6 +536,7 @@ uint8_t emberAfGetDate(uint8_t * message, uint16_t currentIndex, uint16_t msgLen * @brief Macro for consistency, that extracts single byte out of the message */ #define emberAfGetInt8u(message, currentIndex, msgLen) message[currentIndex] +#define emberAfGetInt8s(message, currentIndex, msgLen) chip::CastToSigned(emberAfGetInt8u(message, currentIndex, msgLen)) /** * @brief Macro for consistency that copies a uint8_t from variable into buffer. diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index ff1e102de4a0c1..58130c1cfb0e0f 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -167,7 +167,7 @@ uint8_t emberAfGetDynamicIndexFromEndpoint(EndpointId id) { if (emAfEndpoints[index].endpoint == id) { - return index - FIXED_ENDPOINT_COUNT; + return static_cast(index - FIXED_ENDPOINT_COUNT); } } return 0xFF; @@ -176,13 +176,15 @@ uint8_t emberAfGetDynamicIndexFromEndpoint(EndpointId id) EmberAfStatus emberAfSetDynamicEndpoint(uint8_t index, EndpointId id, EmberAfEndpointType * ep, uint16_t deviceId, uint8_t deviceVersion) { - index += FIXED_ENDPOINT_COUNT; + auto realIndex = index + FIXED_ENDPOINT_COUNT; - if (index >= MAX_ENDPOINT_COUNT) + if (realIndex >= MAX_ENDPOINT_COUNT) { return EMBER_ZCL_STATUS_INSUFFICIENT_SPACE; } + index = static_cast(realIndex); + for (uint8_t i = FIXED_ENDPOINT_COUNT; i < MAX_ENDPOINT_COUNT; i++) { if (emAfEndpoints[i].endpoint == id) @@ -213,7 +215,7 @@ EndpointId emberAfClearDynamicEndpoint(uint8_t index) { EndpointId ep = 0; - index += FIXED_ENDPOINT_COUNT; + index = static_cast(index + FIXED_ENDPOINT_COUNT); if ((index < MAX_ENDPOINT_COUNT) && (emAfEndpoints[index].endpoint != 0) && (emberAfEndpointIndexIsEnabled(index))) { diff --git a/src/app/util/attribute-table.cpp b/src/app/util/attribute-table.cpp index c581ab5656be8e..866052379894d7 100644 --- a/src/app/util/attribute-table.cpp +++ b/src/app/util/attribute-table.cpp @@ -366,7 +366,7 @@ void emberAfRetrieveAttributeAndCraftResponse(EndpointId endpoint, ClusterId clu else { emberAfPutInt16uInResp(attrId); - emberAfPutInt8uInResp(status); + emberAfPutStatusInResp(status); emberAfAttributesPrintln("READ: clus %2x, attr %2x failed %x", clusterId, attrId, status); emberAfAttributesFlush(); return; diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index d5d3eb488aa07d..663d002c3ebd2e 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -46,7 +46,8 @@ void SetupEmberAfObjects(Command * command, ClusterId clusterId, CommandId comma imCompatibilityEmberApsFrame.clusterId = clusterId; imCompatibilityEmberApsFrame.destinationEndpoint = endpointId; imCompatibilityEmberApsFrame.sourceEndpoint = 1; // source endpoint is fixed to 1 for now. - imCompatibilityEmberApsFrame.sequence = (commandExchangeCtx != nullptr ? commandExchangeCtx->GetExchangeId() & 0xFF : 0); + imCompatibilityEmberApsFrame.sequence = + (commandExchangeCtx != nullptr ? static_cast(commandExchangeCtx->GetExchangeId() & 0xFF) : 0); imCompatibilityEmberAfCluster.commandId = commandId; imCompatibilityEmberAfCluster.apsFrame = &imCompatibilityEmberApsFrame; diff --git a/src/app/util/message.cpp b/src/app/util/message.cpp index 8bec8a8c055ca2..a5ecf4c9ab24da 100644 --- a/src/app/util/message.cpp +++ b/src/app/util/message.cpp @@ -182,6 +182,11 @@ void emberAfPutInt16sInResp(int16_t value) emberAfPutInt16uInResp(static_cast(value)); } +void emberAfPutStatusInResp(EmberAfStatus value) +{ + emberAfPutInt8uInResp(static_cast>(value)); +} + // ------------------------------------ // Utilities for reading from RAM buffers (reading from incoming message // buffer) diff --git a/src/app/util/process-global-message.cpp b/src/app/util/process-global-message.cpp index c8d7a98a9a8484..d3ac1268ac3f29 100644 --- a/src/app/util/process-global-message.cpp +++ b/src/app/util/process-global-message.cpp @@ -267,7 +267,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) { numFailures++; // Write to the response buffer - status and then attrID - emberAfPutInt8uInResp(status); + emberAfPutStatusInResp(status); emberAfPutInt16uInResp(attrId); emberAfAttributesPrintln("WRITE: clus %2x attr %2x ", clusterId, attrId); @@ -375,7 +375,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) { numFailures++; // write to the response buffer - status and then attrID - emberAfPutInt8uInResp(status); + emberAfPutStatusInResp(status); emberAfPutInt16uInResp(attrId); emberAfAttributesPrintln("FAIL %x", status); } @@ -390,7 +390,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) numFailures++; status = EMBER_ZCL_STATUS_INVALID_VALUE; // write to the response buffer - status and then attrID - emberAfPutInt8uInResp(status); + emberAfPutStatusInResp(status); emberAfPutInt16uInResp(attrId); emberAfAttributesPrintln("FAIL %x", status); // size exceeds buffer, terminate loop diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 1101e44177a744..09d7e767759195 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -846,7 +846,7 @@ EmberStatus emberAfSendDefaultResponseWithCallback(const EmberAfClusterCommand * emberAfPutInt8uInResp(cmd->seqNum); emberAfPutInt8uInResp(ZCL_DEFAULT_RESPONSE_COMMAND_ID); emberAfPutInt8uInResp(cmd->commandId); - emberAfPutInt8uInResp(status); + emberAfPutStatusInResp(status); prepareForResponse(cmd); return emberAfSendResponseWithCallback(callback); diff --git a/src/app/util/util.h b/src/app/util/util.h index 20ab0f3cb081e8..5145a6de0c04a2 100644 --- a/src/app/util/util.h +++ b/src/app/util/util.h @@ -189,6 +189,7 @@ uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length); uint8_t * emberAfPutStringInResp(const uint8_t * buffer); uint8_t * emberAfPutDateInResp(EmberAfDate * value); void emberAfPutInt16sInResp(int16_t value); +void emberAfPutStatusInResp(EmberAfStatus value); bool emberAfIsThisMyEui64(EmberEUI64 eui64); diff --git a/src/app/zap-templates/templates/app/CHIPClientCallbacks-src.zapt b/src/app/zap-templates/templates/app/CHIPClientCallbacks-src.zapt index 00b08aabfb5019..0984d3cad7fbef 100644 --- a/src/app/zap-templates/templates/app/CHIPClientCallbacks-src.zapt +++ b/src/app/zap-templates/templates/app/CHIPClientCallbacks-src.zapt @@ -413,7 +413,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag {{#chip_attribute_list_entryTypes}} {{#if (isString type)}} CHECK_STATUS(ReadByteSpan(message, {{size}}, &data[i].{{name}})); - messageLen -= {{size}}; + messageLen = static_cast(messageLen - {{size}}); {{else}} CHECK_MESSAGE_LENGTH({{size}}); data[i].{{name}} = emberAfGet{{asReadType type}}(message, 0, {{size}}); @@ -424,7 +424,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag {{#if (isString type)}} CHECK_STATUS(ReadByteSpan(message, messageLen, &data[i])); uint16_t entryLength = static_cast(data[i].size() + kByteSpanSizeLengthInBytes); - messageLen -= entryLength; + messageLen = static_cast(messageLen - entryLength); message += entryLength; {{else}} CHECK_MESSAGE_LENGTH({{size}}); diff --git a/src/app/zap-templates/templates/app/attribute-size-src.zapt b/src/app/zap-templates/templates/app/attribute-size-src.zapt index 47a3ac6820d00b..c96b93e8eb5a5b 100644 --- a/src/app/zap-templates/templates/app/attribute-size-src.zapt +++ b/src/app/zap-templates/templates/app/attribute-size-src.zapt @@ -98,7 +98,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo {{/chip_attribute_list_entryTypes}} {{else}} {{#if (isString type)}} - entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, index - 1); + entryOffset = GetByteSpanOffsetFromIndex(write ? dest : src, am->size, static_cast(index - 1)); if (entryOffset == 0) { ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index); @@ -113,7 +113,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo return 0; } - entryLength = {{asCamelCased name}}Span->size(); + if (!CanCastTo({{asCamelCased name}}Span->size())) + { + ChipLogError(Zcl, "Span size %zu is too large", {{asCamelCased name}}Span->size()); + return 0; + } + entryLength = static_cast({{asCamelCased name}}Span->size()); {{else}} copyListMember(dest, src, write, &entryOffset, entryLength); // {{type}} {{/if}} diff --git a/src/app/zap-templates/templates/app/helper.js b/src/app/zap-templates/templates/app/helper.js index 1dbcc6cb77cf97..96565fdac7fcf2 100644 --- a/src/app/zap-templates/templates/app/helper.js +++ b/src/app/zap-templates/templates/app/helper.js @@ -132,18 +132,23 @@ function asReadType(type) const basicType = ChipTypesHelper.asBasicType(zclType); switch (basicType) { case 'int8_t': + return 'Int8s'; case 'uint8_t': return 'Int8u'; case 'int16_t': + return 'Int16s'; case 'uint16_t': return 'Int16u'; case 'int24_t': + return 'Int24s'; case 'uint24_t': return 'Int24u'; case 'int32_t': + return 'Int32s'; case 'uint32_t': return 'Int32u'; case 'int64_t': + return 'Int64s'; case 'uint64_t': return 'Int64u'; default: diff --git a/src/controller/data_model/gen/CHIPClientCallbacks.cpp b/src/controller/data_model/gen/CHIPClientCallbacks.cpp index 49752b1f185c40..4ad1aaaca4b3a2 100644 --- a/src/controller/data_model/gen/CHIPClientCallbacks.cpp +++ b/src/controller/data_model/gen/CHIPClientCallbacks.cpp @@ -455,7 +455,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].outputType = emberAfGetInt8u(message, 0, 1); message += 1; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].name)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; } @@ -476,7 +476,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag { CHECK_STATUS(ReadByteSpan(message, messageLen, &data[i])); uint16_t entryLength = static_cast(data[i].size() + kByteSpanSizeLengthInBytes); - messageLen -= entryLength; + messageLen = static_cast(messageLen - entryLength); message += entryLength; } @@ -581,10 +581,10 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag for (size_t i = 0; i < count; i++) { CHECK_STATUS(ReadByteSpan(message, 18, &data[i].label)); - messageLen -= 18; + messageLen = static_cast(messageLen - 18); message += 18; CHECK_STATUS(ReadByteSpan(message, 18, &data[i].value)); - messageLen -= 18; + messageLen = static_cast(messageLen - 18); message += 18; } @@ -604,7 +604,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag for (size_t i = 0; i < count; i++) { CHECK_STATUS(ReadByteSpan(message, 34, &data[i].Name)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; CHECK_MESSAGE_LENGTH(1); data[i].FabricConnected = emberAfGetInt8u(message, 0, 1); @@ -667,7 +667,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].GroupKeyIndex = emberAfGetInt16u(message, 0, 2); message += 2; CHECK_STATUS(ReadByteSpan(message, 18, &data[i].GroupKeyRoot)); - messageLen -= 18; + messageLen = static_cast(messageLen - 18); message += 18; CHECK_MESSAGE_LENGTH(8); data[i].GroupKeyEpochStartTime = emberAfGetInt64u(message, 0, 8); @@ -699,10 +699,10 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].inputType = emberAfGetInt8u(message, 0, 1); message += 1; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].name)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].description)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; } @@ -731,7 +731,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].NodeId = emberAfGetInt64u(message, 0, 8); message += 8; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].Label)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; } @@ -758,13 +758,13 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].minorNumber = emberAfGetInt16u(message, 0, 2); message += 2; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].name)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].callSign)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].affiliateCallSign)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; } @@ -787,7 +787,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].identifier = emberAfGetInt8u(message, 0, 1); message += 1; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].name)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; } @@ -824,7 +824,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag { CHECK_STATUS(ReadByteSpan(message, messageLen, &data[i])); uint16_t entryLength = static_cast(data[i].size() + kByteSpanSizeLengthInBytes); - messageLen -= entryLength; + messageLen = static_cast(messageLen - entryLength); message += entryLength; } @@ -842,7 +842,7 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].fabricIndex = emberAfGetInt64u(message, 0, 8); message += 8; CHECK_STATUS(ReadByteSpan(message, 34, &data[i].operationalCert)); - messageLen -= 34; + messageLen = static_cast(messageLen - 34); message += 34; } @@ -881,10 +881,10 @@ bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * messag data[i].LQI = emberAfGetInt8u(message, 0, 1); message += 1; CHECK_MESSAGE_LENGTH(1); - data[i].AverageRssi = emberAfGetInt8u(message, 0, 1); + data[i].AverageRssi = emberAfGetInt8s(message, 0, 1); message += 1; CHECK_MESSAGE_LENGTH(1); - data[i].LastRssi = emberAfGetInt8u(message, 0, 1); + data[i].LastRssi = emberAfGetInt8s(message, 0, 1); message += 1; CHECK_MESSAGE_LENGTH(1); data[i].FrameErrorRate = emberAfGetInt8u(message, 0, 1);