From e2d95d4108ac6f1c2c061d88ee0640b3a9d7f6fc Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 2 Nov 2020 14:02:18 -0500 Subject: [PATCH] Make various src/app code compile with -Wconversion We don't actually enable -Wconversion for this code yet, because it's compiled directly into example apps, so we would need to enable -Wconversion for those, and they aren't quite there. --- .../server/esp32/main/gen/callback.h | 2 +- .../barrier-control-server.cpp | 21 +++---- .../color-control-server.cpp | 22 +++---- .../door-lock-server-logging.cpp | 2 +- .../door-lock-server-user.cpp | 2 +- .../door-lock-server/door-lock-server.h | 2 +- .../clusters/groups-server/groups-server.cpp | 4 +- .../ias-zone-server/ias-zone-server.cpp | 2 +- src/app/clusters/identify/identify.cpp | 2 +- .../clusters/level-control/level-control.cpp | 14 ++--- .../clusters/scenes-client/scenes-client.cpp | 15 ++--- src/app/clusters/scenes/scenes.cpp | 50 ++++++++-------- .../temperature-measurement-server.cpp | 6 +- src/app/reporting/reporting.cpp | 37 ++++++------ src/app/reporting/reporting.h | 3 + src/app/util/af-main-common.cpp | 8 ++- src/app/util/af-types.h | 4 +- src/app/util/attribute-size.cpp | 4 +- src/app/util/attribute-storage.cpp | 33 +++++------ src/app/util/attribute-storage.h | 2 +- src/app/util/attribute-table.cpp | 9 +-- src/app/util/chip-message-send.cpp | 7 ++- src/app/util/client-api.cpp | 10 ++-- src/app/util/esi-management.h | 2 +- src/app/util/message.cpp | 4 +- src/app/util/process-global-message.cpp | 57 +++++++++++-------- src/app/util/util.cpp | 49 ++++++++-------- 27 files changed, 202 insertions(+), 171 deletions(-) diff --git a/examples/wifi-echo/server/esp32/main/gen/callback.h b/examples/wifi-echo/server/esp32/main/gen/callback.h index aed4de67a17855..335ab321e29473 100644 --- a/examples/wifi-echo/server/esp32/main/gen/callback.h +++ b/examples/wifi-echo/server/esp32/main/gen/callback.h @@ -14601,7 +14601,7 @@ void emberAfIasZoneClusterServerManufacturerSpecificAttributeChangedCallback(uin * @param message The message that was sent Ver.: always * @param status The status of the sent message Ver.: always */ -void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, +void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status); /** @brief IAS Zone Cluster Server Pre Attribute Changed diff --git a/src/app/clusters/barrier-control-server/barrier-control-server.cpp b/src/app/clusters/barrier-control-server/barrier-control-server.cpp index 48502602cb1a7f..e1dd3a1038ceb4 100644 --- a/src/app/clusters/barrier-control-server/barrier-control-server.cpp +++ b/src/app/clusters/barrier-control-server/barrier-control-server.cpp @@ -172,7 +172,7 @@ void emAfPluginBarrierControlServerIncrementEvents(uint8_t endpoint, bool open, { if (READBIT(mask, bit)) { - EmberAfAttributeId attributeId = baseEventAttributeId + bit; + EmberAfAttributeId attributeId = static_cast(baseEventAttributeId + bit); uint16_t events; EmberAfStatus status = emberAfReadServerAttribute(endpoint, ZCL_BARRIER_CONTROL_CLUSTER_ID, attributeId, (uint8_t *) &events, sizeof(events)); @@ -203,15 +203,15 @@ static uint8_t getCurrentPosition(uint8_t endpoint) // open so that we don't leave the barrier open when it should be closed. uint8_t currentPositionFromAttribute = emAfPluginBarrierControlServerGetBarrierPosition(endpoint); return ((currentPositionFromAttribute == EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN) - ? EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN + ? static_cast(EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN) : currentPositionFromAttribute); } static uint32_t calculateDelayMs(uint8_t endpoint, uint8_t targetPosition, bool * opening) { - uint8_t currentPosition = emAfPluginBarrierControlServerGetBarrierPosition(endpoint); - *opening = targetPosition > currentPosition; - uint8_t positionDelta = (*opening ? targetPosition - currentPosition : currentPosition - targetPosition); + uint8_t currentPosition = emAfPluginBarrierControlServerGetBarrierPosition(endpoint); + *opening = targetPosition > currentPosition; + uint8_t positionDelta = static_cast(*opening ? targetPosition - currentPosition : currentPosition - targetPosition); uint16_t openOrClosePeriodDs = getOpenOrClosePeriod(endpoint, *opening); uint32_t openOrClosePeriodMs = openOrClosePeriodDs * MILLISECOND_TICKS_PER_DECISECOND; @@ -228,7 +228,7 @@ static uint32_t calculateDelayMs(uint8_t endpoint, uint8_t targetPosition, bool } } -void emberAfBarrierControlClusterServerTickCallback(uint8_t endpoint) +void emberAfBarrierControlClusterServerTickCallback(CHIPEndpointId endpoint) { if (state.currentPosition == state.targetPosition) { @@ -254,10 +254,11 @@ void emberAfBarrierControlClusterServerTickCallback(uint8_t endpoint) emAfPluginBarrierControlServerIncrementEvents(endpoint, false, false); } } - emAfPluginBarrierControlServerSetBarrierPosition(endpoint, - (emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint) - ? state.currentPosition - : EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN)); + emAfPluginBarrierControlServerSetBarrierPosition( + endpoint, + (emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint) + ? state.currentPosition + : static_cast(EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN))); setMovingState( endpoint, (state.increasing ? EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_OPENING : EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_CLOSING)); 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 c161a4d9bee9f7..2fc6266c82b153 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -777,7 +777,7 @@ static uint8_t addSaturation(uint8_t saturation1, uint8_t saturation2) uint16_t saturation16; saturation16 = ((uint16_t) saturation1); - saturation16 += ((uint16_t) saturation2); + saturation16 = static_cast(saturation16 + static_cast(saturation2)); if (saturation16 > MAX_SATURATION_VALUE) { @@ -794,7 +794,7 @@ static uint8_t subtractSaturation(uint8_t saturation1, uint8_t saturation2) return 0; } - return saturation1 - saturation2; + return static_cast(saturation1 - saturation2); } // any time we call a hue or saturation transition, we need to assume certain @@ -1256,11 +1256,11 @@ bool emberAfColorControlClusterStepColorTemperatureCallback(uint8_t stepMode, ui colorTempTransitionState.currentValue = readColorTemperature(endpoint); if (stepMode == MOVE_MODE_UP) { - colorTempTransitionState.finalValue = readColorTemperature(endpoint) + stepSize; + colorTempTransitionState.finalValue = static_cast(readColorTemperature(endpoint) + stepSize); } else { - colorTempTransitionState.finalValue = readColorTemperature(endpoint) - stepSize; + colorTempTransitionState.finalValue = static_cast(readColorTemperature(endpoint) - stepSize); } colorTempTransitionState.stepsRemaining = transitionTime; colorTempTransitionState.stepsTotal = transitionTime; @@ -1395,7 +1395,7 @@ static void handleModeSwitch(uint8_t endpoint, uint8_t newColorMode) writeColorMode(endpoint, newColorMode); } - colorModeTransition = (newColorMode << 4) + oldColorMode; + colorModeTransition = static_cast((newColorMode << 4) + oldColorMode); // Note: It may be OK to not do anything here. switch (colorModeTransition) @@ -1433,11 +1433,11 @@ static uint8_t addHue(uint8_t hue1, uint8_t hue2) uint16_t hue16; hue16 = ((uint16_t) hue1); - hue16 += ((uint16_t) hue2); + hue16 = static_cast(hue16 + static_cast(hue2)); if (hue16 > MAX_HUE_VALUE) { - hue16 -= MAX_HUE_VALUE; + hue16 = static_cast(hue16 - MAX_HUE_VALUE); } return ((uint8_t) hue16); @@ -1450,10 +1450,10 @@ static uint8_t subtractHue(uint8_t hue1, uint8_t hue2) hue16 = ((uint16_t) hue1); if (hue2 > hue1) { - hue16 += MAX_HUE_VALUE; + hue16 = static_cast(hue16 + MAX_HUE_VALUE); } - hue16 -= ((uint16_t) hue2); + hue16 = static_cast(hue16 - static_cast(hue2)); return ((uint8_t) hue16); } @@ -1580,14 +1580,14 @@ static bool computeNewColor16uValue(Color16uTransitionState * p) newValue32u = ((uint32_t)(p->finalValue - p->initialValue)); newValue32u *= ((uint32_t)(p->stepsRemaining)); newValue32u /= ((uint32_t)(p->stepsTotal)); - p->currentValue = p->finalValue - ((uint16_t)(newValue32u)); + p->currentValue = static_cast(p->finalValue - static_cast(newValue32u)); } else { newValue32u = ((uint32_t)(p->initialValue - p->finalValue)); newValue32u *= ((uint32_t)(p->stepsRemaining)); newValue32u /= ((uint32_t)(p->stepsTotal)); - p->currentValue = p->finalValue + ((uint16_t)(newValue32u)); + p->currentValue = static_cast(p->finalValue + static_cast(newValue32u)); } if (p->stepsRemaining == 0) diff --git a/src/app/clusters/door-lock-server/door-lock-server-logging.cpp b/src/app/clusters/door-lock-server/door-lock-server-logging.cpp index 2f129d7c13314d..acacab409d81b2 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-logging.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-logging.cpp @@ -101,7 +101,7 @@ bool emberAfPluginDoorLockServerGetLogEntry(uint16_t * entryId, EmberAfPluginDoo if (!ENTRY_ID_IS_VALID(*entryId)) { - *entryId = MOST_RECENT_ENTRY_ID(); + *entryId = static_cast(MOST_RECENT_ENTRY_ID()); } assert(ENTRY_ID_IS_VALID(*entryId)); 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 e9ec8294532787..f7a96743c1d593 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 @@ -55,7 +55,7 @@ static EmberAfPluginDoorLockServerUser rfidUserTable[EMBER_AF_PLUGIN_DOOR_LOCK_S // This is the current number of invalid PIN/RFID's in a row. static uint8_t wrongCodeEntryCount = 0; -bool emAfPluginDoorLockServerCheckForSufficientSpace(uint8_t spaceReq, uint8_t spaceAvail) +bool emAfPluginDoorLockServerCheckForSufficientSpace(uint16_t spaceReq, uint8_t spaceAvail) { if (spaceReq > spaceAvail) { diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index 9ecdb1efa7775d..ca147b1b239082 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -228,7 +228,7 @@ typedef struct // space available (spaceAvail) and if so it will send a DefaultResponse // command with the status of EMBER_ZCL_STATUS_INSUFFICIENT_SPACE and return // false. Otherwise, it will return true. -bool emAfPluginDoorLockServerCheckForSufficientSpace(uint8_t spaceReq, uint8_t spaceAvail); +bool emAfPluginDoorLockServerCheckForSufficientSpace(uint16_t spaceReq, uint8_t spaceAvail); #endif // Critical Message Queue diff --git a/src/app/clusters/groups-server/groups-server.cpp b/src/app/clusters/groups-server/groups-server.cpp index f850b29aa85245..d742659c52e057 100644 --- a/src/app/clusters/groups-server/groups-server.cpp +++ b/src/app/clusters/groups-server/groups-server.cpp @@ -225,7 +225,7 @@ bool emberAfGroupsClusterGetGroupMembershipCallback(uint8_t groupCount, uint8_t { list[listLen] = LOW_BYTE(entry.groupId); list[listLen + 1] = HIGH_BYTE(entry.groupId); - listLen += 2; + listLen = static_cast(listLen + 2); count++; } } @@ -245,7 +245,7 @@ bool emberAfGroupsClusterGetGroupMembershipCallback(uint8_t groupCount, uint8_t { list[listLen] = LOW_BYTE(groupId); list[listLen + 1] = HIGH_BYTE(groupId); - listLen += 2; + listLen = static_cast(listLen + 2); count++; } } diff --git a/src/app/clusters/ias-zone-server/ias-zone-server.cpp b/src/app/clusters/ias-zone-server/ias-zone-server.cpp index cbbe57c8bf9300..11a8822e70eec5 100644 --- a/src/app/clusters/ias-zone-server/ias-zone-server.cpp +++ b/src/app/clusters/ias-zone-server/ias-zone-server.cpp @@ -752,7 +752,7 @@ void emberAfPluginIasZoneServerPrintQueueConfig(void) // destination when the destination is the only router the node is joined to. // In that case, the command will never have been sent, as the device will have // had no router by which to send the command. -void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, +void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status) { diff --git a/src/app/clusters/identify/identify.cpp b/src/app/clusters/identify/identify.cpp index 7d72d41045b1ba..ec1f2c7b808f3c 100644 --- a/src/app/clusters/identify/identify.cpp +++ b/src/app/clusters/identify/identify.cpp @@ -83,7 +83,7 @@ void emberAfIdentifyClusterServerTickCallback(uint8_t endpoint) // This tick writes the new attribute, which will trigger the Attribute // Changed callback below, which in turn will schedule or cancel the tick. // Because of this, the tick does not have to be scheduled here. - writeIdentifyTime(endpoint, (identifyTime == 0 ? 0 : identifyTime - 1)); + writeIdentifyTime(endpoint, static_cast(identifyTime == 0 ? 0 : identifyTime - 1)); } } diff --git a/src/app/clusters/level-control/level-control.cpp b/src/app/clusters/level-control/level-control.cpp index 2e1e9695240e77..0216cf311b0d54 100644 --- a/src/app/clusters/level-control/level-control.cpp +++ b/src/app/clusters/level-control/level-control.cpp @@ -260,7 +260,7 @@ extern "C" void emberAfLevelControlClusterServerTickCallback(uint8_t endpoint) } else { - writeRemainingTime(endpoint, state->transitionTimeMs - state->elapsedTimeMs); + writeRemainingTime(endpoint, static_cast(state->transitionTimeMs - state->elapsedTimeMs)); schedule(endpoint, state->eventDurationMs); } } @@ -514,12 +514,12 @@ static void moveToLevelHandler(uint8_t commandId, uint8_t level, uint16_t transi goto send_default_response; } state->increasing = true; - actualStepSize = state->moveToLevel - currentLevel; + actualStepSize = static_cast(state->moveToLevel - currentLevel); } else { state->increasing = false; - actualStepSize = currentLevel - state->moveToLevel; + actualStepSize = static_cast(currentLevel - state->moveToLevel); } // If the Transition time field takes the value 0xFFFF, then the time taken @@ -623,7 +623,7 @@ static void moveHandler(uint8_t commandId, uint8_t moveMode, uint8_t rate, uint8 case EMBER_ZCL_MOVE_MODE_UP: state->increasing = true; state->moveToLevel = MAX_LEVEL; - difference = MAX_LEVEL - currentLevel; + difference = static_cast(MAX_LEVEL - currentLevel); break; case EMBER_ZCL_MOVE_MODE_DOWN: state->increasing = false; @@ -737,11 +737,11 @@ static void stepHandler(uint8_t commandId, uint8_t stepMode, uint8_t stepSize, u if (MAX_LEVEL - currentLevel < stepSize) { state->moveToLevel = MAX_LEVEL; - actualStepSize = (MAX_LEVEL - currentLevel); + actualStepSize = static_cast(MAX_LEVEL - currentLevel); } else { - state->moveToLevel = currentLevel + stepSize; + state->moveToLevel = static_cast(currentLevel + stepSize); } break; case EMBER_ZCL_STEP_MODE_DOWN: @@ -753,7 +753,7 @@ static void stepHandler(uint8_t commandId, uint8_t stepMode, uint8_t stepSize, u } else { - state->moveToLevel = currentLevel - stepSize; + state->moveToLevel = static_cast(currentLevel - stepSize); } break; default: diff --git a/src/app/clusters/scenes-client/scenes-client.cpp b/src/app/clusters/scenes-client/scenes-client.cpp index e6eb1f3d4c9625..8092983e267911 100644 --- a/src/app/clusters/scenes-client/scenes-client.cpp +++ b/src/app/clusters/scenes-client/scenes-client.cpp @@ -119,9 +119,10 @@ bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand // the payload if the status is SUCCESS. if (status == EMBER_ZCL_STATUS_SUCCESS) { - uint16_t extensionFieldSetsLen = (emberAfCurrentCommand()->bufLen - - (emberAfCurrentCommand()->payloadStartIndex + sizeof(status) + sizeof(groupId) + - sizeof(sceneId) + sizeof(transitionTime) + emberAfStringLength(sceneName) + 1)); + uint16_t extensionFieldSetsLen = + static_cast(emberAfCurrentCommand()->bufLen - + (emberAfCurrentCommand()->payloadStartIndex + sizeof(status) + sizeof(groupId) + sizeof(sceneId) + + sizeof(transitionTime) + emberAfStringLength(sceneName) + 1)); uint16_t extensionFieldSetsIndex = 0; emberAfScenesClusterPrint(", 0x%2x, \"", transitionTime); @@ -134,9 +135,9 @@ bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand { EmberAfClusterId clusterId; uint8_t length; - clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); + clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); extensionFieldSetsIndex++; emberAfScenesClusterPrint(" [0x%2x 0x%x ", clusterId, length); if (extensionFieldSetsIndex + length <= extensionFieldSetsLen) @@ -145,7 +146,7 @@ bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand } emberAfScenesClusterPrint("]"); emberAfScenesClusterFlush(); - extensionFieldSetsIndex += length; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + length); } } diff --git a/src/app/clusters/scenes/scenes.cpp b/src/app/clusters/scenes/scenes.cpp index d8c001308860f7..551702616400db 100644 --- a/src/app/clusters/scenes/scenes.cpp +++ b/src/app/clusters/scenes/scenes.cpp @@ -684,10 +684,10 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G EmberAfSceneTableEntry entry; EmberAfStatus status; EmberStatus sendStatus; - bool enhanced = (cmd->commandId == ZCL_ENHANCED_ADD_SCENE_COMMAND_ID); - uint16_t extensionFieldSetsLen = (cmd->bufLen - - (cmd->payloadStartIndex + sizeof(groupId) + sizeof(sceneId) + sizeof(transitionTime) + - emberAfStringLength(sceneName) + 1)); + bool enhanced = (cmd->commandId == ZCL_ENHANCED_ADD_SCENE_COMMAND_ID); + uint16_t extensionFieldSetsLen = static_cast( + cmd->bufLen - + (cmd->payloadStartIndex + sizeof(groupId) + sizeof(sceneId) + sizeof(transitionTime) + emberAfStringLength(sceneName) + 1)); uint16_t extensionFieldSetsIndex = 0; uint8_t endpoint = cmd->apsFrame->destinationEndpoint; uint8_t i, index = EMBER_AF_SCENE_TABLE_NULL_INDEX; @@ -793,9 +793,9 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G goto kickout; } - clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); + clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); extensionFieldSetsIndex++; // If the length is off, the command is also malformed. @@ -866,10 +866,10 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G { break; } - entry.hasCurrentXValue = true; - entry.currentXValue = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length -= 2; + entry.hasCurrentXValue = true; + entry.currentXValue = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = static_cast(length - 2); if (length < 2) { break; @@ -878,8 +878,9 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G entry.currentYValue = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); if (enhanced) { - extensionFieldSetsIndex += 2; - length -= 2; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = static_cast(length - 2); + ; if (length < 2) { break; @@ -887,8 +888,8 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G entry.hasEnhancedCurrentHueValue = true; entry.enhancedCurrentHueValue = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length -= 2; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = static_cast(length - 2); if (length < 1) { break; @@ -919,8 +920,8 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G } entry.hasColorLoopTimeValue = true; entry.colorLoopTimeValue = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen); - extensionFieldSetsIndex += 2; - length -= 2; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + 2); + length = static_cast(length - 2); if (length < 2) { break; @@ -967,7 +968,7 @@ bool emberAfPluginScenesServerParseAddScene(const EmberAfClusterCommand * cmd, G break; } - extensionFieldSetsIndex += length; + extensionFieldSetsIndex = static_cast(extensionFieldSetsIndex + length); } // If we got this far, we either added a new entry or updated an existing one. @@ -1042,7 +1043,8 @@ bool emberAfPluginScenesServerParseViewScene(const EmberAfClusterCommand * cmd, { // The transition time is returned in seconds in the regular version of the // command and tenths of a second in the enhanced version. - emberAfPutInt16uInResp(enhanced ? entry.transitionTime * 10 + entry.transitionTime100ms : entry.transitionTime); + emberAfPutInt16uInResp( + static_cast(enhanced ? entry.transitionTime * 10 + entry.transitionTime100ms : entry.transitionTime)); #ifdef EMBER_AF_PLUGIN_SCENES_NAME_SUPPORT emberAfPutStringInResp(entry.name); #else @@ -1093,17 +1095,17 @@ bool emberAfPluginScenesServerParseViewScene(const EmberAfClusterCommand * cmd, length = &appResponseData[appResponseLength]; emberAfPutInt8uInResp(0); // temporary length emberAfPutInt16uInResp(entry.currentXValue); - *length += 2; + *length = static_cast(*length + 2); if (entry.hasCurrentYValue) { emberAfPutInt16uInResp(entry.currentYValue); - *length += 2; + *length = static_cast(*length + 2); if (enhanced) { if (entry.hasEnhancedCurrentHueValue) { emberAfPutInt16uInResp(entry.enhancedCurrentHueValue); - *length += 2; + *length = static_cast(*length + 2); if (entry.hasCurrentSaturationValue) { emberAfPutInt8uInResp(entry.currentSaturationValue); @@ -1119,11 +1121,11 @@ bool emberAfPluginScenesServerParseViewScene(const EmberAfClusterCommand * cmd, if (entry.hasColorLoopTimeValue) { emberAfPutInt16uInResp(entry.colorLoopTimeValue); - *length += 2; + *length = static_cast(*length + 2); if (entry.hasColorTemperatureMiredsValue) { emberAfPutInt16uInResp(entry.colorTemperatureMiredsValue); - *length += 2; + *length = static_cast(*length + 2); } } } diff --git a/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp b/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp index b3808a052fa399..27668ba26cdeed 100644 --- a/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp +++ b/src/app/clusters/temperature-measurement-server/temperature-measurement-server.cpp @@ -43,6 +43,8 @@ #include #include +using namespace chip; + EmberEventControl emberAfPluginTemperatureMeasurementServerReadEventControl; // TODO: There's no header that declares this event handler, and it's not 100% @@ -58,8 +60,8 @@ extern "C" void emberAfPluginTemperatureMeasurementServerInitCallback(void) EmberAfStatus status; // FIXME Use real values for the temperature sensor polling the sensor using the // EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER_MAX_MEASUREMENT_FREQUENCY_S macro - uint16_t endpointId = 1; // Hardcoded to 1 for now - int16_t newValue = 0x1234; + EndpointId endpointId = 1; // Hardcoded to 1 for now + int16_t newValue = 0x1234; status = emberAfWriteAttribute(endpointId, ZCL_TEMP_MEASUREMENT_CLUSTER_ID, ZCL_CURRENT_TEMPERATURE_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, (uint8_t *) &newValue, ZCL_INT16S_ATTRIBUTE_TYPE); diff --git a/src/app/reporting/reporting.cpp b/src/app/reporting/reporting.cpp index 542c8b777f401a..fc007c5322cc1b 100644 --- a/src/app/reporting/reporting.cpp +++ b/src/app/reporting/reporting.cpp @@ -62,7 +62,7 @@ static void removeConfigurationAndScheduleTick(uint8_t index); static EmberAfStatus configureReceivedAttribute(const EmberAfClusterCommand * cmd, EmberAfAttributeId attributeId, uint8_t mask, uint16_t timeout); static void putReportableChangeInResp(const EmberAfPluginReportingEntry * entry, EmberAfAttributeType dataType); -static void retrySendReport(EmberOutgoingMessageType type, uint16_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, +static void retrySendReport(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status); static uint32_t computeStringHash(uint8_t * data, uint8_t length); @@ -88,7 +88,7 @@ EmberAfStatus emberAfPluginReportingConfiguredCallback(const EmberAfPluginReport return EMBER_ZCL_STATUS_SUCCESS; } -static void retrySendReport(EmberOutgoingMessageType type, uint16_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, +static void retrySendReport(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status) { // Retry once, and do so by unicasting without a pointer to this callback @@ -158,7 +158,7 @@ extern "C" void emberAfPluginReportingInitCallback(void) { // On device initialization, any attributes that have been set up to report // should generate an attribute report. - for (int i = 0; i < REPORT_TABLE_SIZE; i++) + for (uint8_t i = 0; i < REPORT_TABLE_SIZE; i++) { EmberAfPluginReportingEntry entry; emAfPluginReportingGetEntry(i, &entry); @@ -183,7 +183,10 @@ extern "C" void emberAfPluginReportingTickEventHandler(void) uint16_t dataSize; bool clientToServer = false; EmberBindingTableEntry bindingEntry; - uint8_t index, reportSize = 0, currentPayloadMaxLength = 0, smallestPayloadMaxLength = 0; + // reportSize needs to be able to fit a sum of dataSize and some other stuff + // without overflowing. + uint32_t reportSize; + uint8_t index, currentPayloadMaxLength = 0, smallestPayloadMaxLength = 0; for (i = 0; i < REPORT_TABLE_SIZE; i++) { @@ -306,15 +309,16 @@ extern "C" void emberAfPluginReportingTickEventHandler(void) // and changes. We only track changes for data types that are small enough // for us to compare. For CHAR and OCTET strings, we substitute a 32-bit hash. emAfPluginReportVolatileData[i].reportableChange = false; - emAfPluginReportVolatileData[i].lastReportTimeMs = chip::System::Layer::GetClock_MonotonicMS(); + emAfPluginReportVolatileData[i].lastReportTimeMs = static_cast(chip::System::Layer::GetClock_MonotonicMS()); uint32_t stringHash = 0; uint8_t * copyData = readData; - uint8_t copySize = dataSize; + uint16_t copySize = dataSize; if (dataType == ZCL_OCTET_STRING_ATTRIBUTE_TYPE || dataType == ZCL_CHAR_STRING_ATTRIBUTE_TYPE) { // dataSize was set above to count the string's length byte, in addition to string length. - // Compute hash on string value only. - stringHash = computeStringHash(readData + 1, dataSize - 1); + // Compute hash on string value only. Note that string length fits + // in one byte, so dataSize can't be larger than 256 right now. + stringHash = computeStringHash(readData + 1, static_cast(dataSize - 1)); copyData = (uint8_t *) &stringHash; copySize = sizeof(stringHash); } @@ -403,7 +407,7 @@ bool emberAfConfigureReportingCommandCallback(const EmberAfClusterCommand * cmd) direction = (EmberAfReportingDirection) emberAfGetInt8u(cmd->buffer, bufIndex, cmd->bufLen); bufIndex++; attributeId = (EmberAfAttributeId) emberAfGetInt16u(cmd->buffer, bufIndex, cmd->bufLen); - bufIndex += 2; + bufIndex = static_cast(bufIndex + 2); emberAfReportingPrintln(" - direction:%x, attr:%2x", direction, attributeId); @@ -419,9 +423,9 @@ bool emberAfConfigureReportingCommandCallback(const EmberAfClusterCommand * cmd) dataType = (EmberAfAttributeType) emberAfGetInt8u(cmd->buffer, bufIndex, cmd->bufLen); bufIndex++; minInterval = emberAfGetInt16u(cmd->buffer, bufIndex, cmd->bufLen); - bufIndex += 2; + bufIndex = static_cast(bufIndex + 2); maxInterval = emberAfGetInt16u(cmd->buffer, bufIndex, cmd->bufLen); - bufIndex += 2; + bufIndex = static_cast(bufIndex + 2); emberAfReportingPrintln(" type:%x, min:%2x, max:%2x", dataType, minInterval, maxInterval); emberAfReportingFlush(); @@ -435,7 +439,7 @@ bool emberAfConfigureReportingCommandCallback(const EmberAfClusterCommand * cmd) emberAfReportingPrintBuffer(cmd->buffer + bufIndex, dataSize, false); emberAfReportingPrintln(""); - bufIndex += dataSize; + bufIndex = static_cast(bufIndex + dataSize); } // emberAfPluginReportingConfigureReportedAttribute handles non- @@ -465,7 +469,7 @@ bool emberAfConfigureReportingCommandCallback(const EmberAfClusterCommand * cmd) } case EMBER_ZCL_REPORTING_DIRECTION_RECEIVED: { uint16_t timeout = emberAfGetInt16u(cmd->buffer, bufIndex, cmd->bufLen); - bufIndex += 2; + bufIndex = static_cast(bufIndex + 2); emberAfReportingPrintln(" timeout:%2x", timeout); @@ -555,7 +559,7 @@ bool emberAfReadReportingConfigurationCommandCallback(const EmberAfClusterComman direction = (EmberAfReportingDirection) emberAfGetInt8u(cmd->buffer, bufIndex, cmd->bufLen); bufIndex++; attributeId = (EmberAfAttributeId) emberAfGetInt16u(cmd->buffer, bufIndex, cmd->bufLen); - bufIndex += 2; + bufIndex = static_cast(bufIndex + 2); switch (direction) { @@ -909,8 +913,9 @@ EmberAfStatus emberAfPluginReportingConfigureReportedAttribute(const EmberAfPlug entry.manufacturerCode = newEntry->manufacturerCode; if (index < REPORT_TABLE_SIZE) { - emAfPluginReportVolatileData[index].lastReportTimeMs = chip::System::Layer::GetClock_MonotonicMS(); - emAfPluginReportVolatileData[index].lastReportValue = 0; + emAfPluginReportVolatileData[index].lastReportTimeMs = + static_cast(chip::System::Layer::GetClock_MonotonicMS()); + emAfPluginReportVolatileData[index].lastReportValue = 0; } } diff --git a/src/app/reporting/reporting.h b/src/app/reporting/reporting.h index 67b93ec6580157..aaba2f88401fb9 100644 --- a/src/app/reporting/reporting.h +++ b/src/app/reporting/reporting.h @@ -58,6 +58,9 @@ typedef struct { + // If the size of lastReportTimeMs changes (see + // https://github.com/project-chip/connectedhomeip/issues/3590) adjust the + // casts on assigning to it. uint32_t lastReportTimeMs; EmberAfDifferenceType lastReportValue; bool reportableChange; diff --git a/src/app/util/af-main-common.cpp b/src/app/util/af-main-common.cpp index 311f692b92e4b7..7b84350522e53c 100644 --- a/src/app/util/af-main-common.cpp +++ b/src/app/util/af-main-common.cpp @@ -479,7 +479,9 @@ EmberStatus emberAfSendUnicastWithCallback(EmberOutgoingMessageType type, uint64 // cluster in the binding is not used because bindings can be used to send // messages with any cluster id, not just the one set in the binding. EmberBindingTableEntry binding; - EmberStatus status = emberGetBinding(indexOrDestination, &binding); + // TODO: This cast should go away once + // https://github.com/project-chip/connectedhomeip/issues/3584 is fixed. + EmberStatus status = emberGetBinding(static_cast(indexOrDestination), &binding); if (status != EMBER_SUCCESS) { return status; @@ -678,7 +680,9 @@ EmberStatus emAfSend(EmberOutgoingMessageType type, uint64_t indexOrDestination, { case EMBER_OUTGOING_VIA_BINDING: { EmberBindingTableEntry binding; - status = emberGetBinding(indexOrDestination, &binding); + // TODO: This cast should go away once + // https://github.com/project-chip/connectedhomeip/issues/3584 is fixed. + status = emberGetBinding(static_cast(indexOrDestination), &binding); if (status != EMBER_SUCCESS) { break; diff --git a/src/app/util/af-types.h b/src/app/util/af-types.h index 80b9fdef9a5000..2fa736fda90a89 100644 --- a/src/app/util/af-types.h +++ b/src/app/util/af-types.h @@ -1106,7 +1106,7 @@ typedef struct struct { /** The node id of the source of the received reports. */ - EmberNodeId source; + ChipNodeId source; /** The remote endpoint from which the attribute is reported. */ uint8_t endpoint; /** The maximum expected time between reports, measured in seconds. */ @@ -1464,7 +1464,7 @@ typedef void (*EmberAfDefaultResponseFunction)(uint8_t endpoint, uint8_t command * * This function is called when a message is sent. */ -typedef void (*EmberAfMessageSentFunction)(EmberOutgoingMessageType type, uint16_t indexOrDestination, EmberApsFrame * apsFrame, +typedef void (*EmberAfMessageSentFunction)(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status); /** diff --git a/src/app/util/attribute-size.cpp b/src/app/util/attribute-size.cpp index 82d814442cf191..1f900d21ce22c6 100644 --- a/src/app/util/attribute-size.cpp +++ b/src/app/util/attribute-size.cpp @@ -78,12 +78,12 @@ uint16_t emberAfAttributeValueSize(EmberAfAttributeType dataType, const uint8_t if (emberAfIsStringAttributeType(dataType)) { // size is string length plus 1-byte length prefix - dataSize = ((uint16_t) emberAfStringLength(buffer)) + 1u; + dataSize = static_cast(static_cast(emberAfStringLength(buffer)) + 1u); } else { // size is long string length plus 2-byte length prefix - dataSize = emberAfLongStringLength(buffer) + 2u; + dataSize = static_cast(emberAfLongStringLength(buffer) + 2u); } } } diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 0fed0b59649323..30aea1bdc832cf 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -142,7 +142,7 @@ void emberAfEndpointConfigure(void) void emberAfSetEndpointCount(uint8_t dynamicEndpointCount) { - emberEndpointCount = FIXED_ENDPOINT_COUNT + dynamicEndpointCount; + emberEndpointCount = static_cast(FIXED_ENDPOINT_COUNT + dynamicEndpointCount); } uint8_t emberAfFixedEndpointCount(void) @@ -206,7 +206,7 @@ void emberAfClusterDefaultResponseCallback(uint8_t endpoint, EmberAfClusterId cl } // This function is used to call the per-cluster message sent callback -void emberAfClusterMessageSentWithMfgCodeCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, +void emberAfClusterMessageSentWithMfgCodeCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status, uint16_t mfgCode) { @@ -356,7 +356,7 @@ static uint8_t * singletonAttributeLocation(EmberAfAttributeMetadata * am) { if ((m->mask & ATTRIBUTE_MASK_SINGLETON) != 0U) { - index += m->size; + index = static_cast(index + m->size); } m++; } @@ -374,11 +374,11 @@ static EmberAfStatus typeSensitiveMemCopy(uint8_t * dest, uint8_t * src, EmberAf if (emberAfIsStringAttributeType(attributeType)) { - emberAfCopyString(dest, src, size - 1); + emberAfCopyString(dest, src, static_cast(size - 1)); } else if (emberAfIsLongStringAttributeType(attributeType)) { - emberAfCopyLongString(dest, src, size - 2); + emberAfCopyLongString(dest, src, static_cast(size - 2)); } else { @@ -419,7 +419,7 @@ static uint16_t getManufacturerCode(EmberAfManufacturerCodeEntry * codes, uint16 uint16_t emberAfGetMfgCode(EmberAfAttributeMetadata * metadata) { return getManufacturerCode((EmberAfManufacturerCodeEntry *) attributeManufacturerCodes, attributeManufacturerCodeCount, - (metadata - generatedAttributes)); + static_cast((metadata - generatedAttributes))); } uint16_t emAfGetManufacturerCodeForAttribute(EmberAfCluster * cluster, EmberAfAttributeMetadata * attMetaData) @@ -431,7 +431,7 @@ uint16_t emAfGetManufacturerCodeForAttribute(EmberAfCluster * cluster, EmberAfAt uint16_t emAfGetManufacturerCodeForCluster(EmberAfCluster * cluster) { return getManufacturerCode((EmberAfManufacturerCodeEntry *) clusterManufacturerCodes, clusterManufacturerCodeCount, - (cluster - generatedClusters)); + static_cast(cluster - generatedClusters)); } /** @@ -569,20 +569,20 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord, // Increase the index if attribute is not externally stored if (!(am->mask & ATTRIBUTE_MASK_EXTERNAL_STORAGE) && !(am->mask & ATTRIBUTE_MASK_SINGLETON)) { - attributeOffsetIndex += emberAfAttributeSize(am); + attributeOffsetIndex = static_cast(attributeOffsetIndex + emberAfAttributeSize(am)); } } } } else { // Not the cluster we are looking for - attributeOffsetIndex += cluster->clusterSize; + attributeOffsetIndex = static_cast(attributeOffsetIndex + cluster->clusterSize); } } } else { // Not the endpoint we are looking for - attributeOffsetIndex += emAfEndpoints[i].endpointType->endpointSize; + attributeOffsetIndex = static_cast(attributeOffsetIndex + emAfEndpoints[i].endpointType->endpointSize); } } return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE; // Sorry, attribute was not found. @@ -768,10 +768,11 @@ static uint8_t findClusterEndpointIndex(uint8_t endpoint, EmberAfClusterId clust { break; } - epi += (emberAfFindClusterIncludingDisabledEndpointsWithMfgCode(emAfEndpoints[i].endpoint, clusterId, mask, - manufacturerCode) != NULL) - ? 1 - : 0; + epi = static_cast(epi + + (emberAfFindClusterIncludingDisabledEndpointsWithMfgCode( + emAfEndpoints[i].endpoint, clusterId, mask, manufacturerCode) != NULL) + ? 1 + : 0); } return epi; @@ -1182,7 +1183,7 @@ EmberAfGenericClusterFunction emberAfFindClusterFunction(EmberAfCluster * cluste { functionIndex++; } - mask <<= 1; + mask = static_cast(mask << 1); } return cluster->functions[functionIndex]; } @@ -1192,7 +1193,7 @@ EmberAfGenericClusterFunction emberAfFindClusterFunction(EmberAfCluster * cluste uint16_t emAfGetManufacturerCodeForCommand(EmberAfCommandMetadata * command) { return getManufacturerCode((EmberAfManufacturerCodeEntry *) commandManufacturerCodes, commandManufacturerCodeCount, - (command - generatedCommands)); + static_cast(command - generatedCommands)); } /** diff --git a/src/app/util/attribute-storage.h b/src/app/util/attribute-storage.h index a18bf237674a21..783e34b72039d7 100644 --- a/src/app/util/attribute-storage.h +++ b/src/app/util/attribute-storage.h @@ -196,7 +196,7 @@ void emberAfClusterMessageSentCallback(EmberOutgoingMessageType type, uint16_t i uint16_t msgLen, uint8_t * message, EmberStatus status); // Calls the message sent callback for a specific cluster. -void emberAfClusterMessageSentWithMfgCodeCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination, +void emberAfClusterMessageSentWithMfgCodeCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message, EmberStatus status, uint16_t manufacturerCode); diff --git a/src/app/util/attribute-table.cpp b/src/app/util/attribute-table.cpp index 9bdf1f7b2c016f..62c636f43be828 100644 --- a/src/app/util/attribute-table.cpp +++ b/src/app/util/attribute-table.cpp @@ -309,11 +309,11 @@ void emberAfPrintAttributeTable(void) uint16_t length; if (emberAfIsStringAttributeType(metaData->attributeType)) { - length = emberAfStringLength(data) + 1; + length = static_cast(emberAfStringLength(data) + 1); } else if (emberAfIsLongStringAttributeType(metaData->attributeType)) { - length = emberAfLongStringLength(data) + 2; + length = static_cast(emberAfLongStringLength(data) + 2); } else { @@ -399,7 +399,8 @@ void emberAfRetrieveAttributeAndCraftResponse(uint8_t endpoint, EmberAfClusterId #else //(BIGENDIAN_CPU) memmove(&(appResponseData[appResponseLength]), data, dataLen); #endif //(BIGENDIAN_CPU) - appResponseLength += dataLen; + // TODO: How do we know this does not overflow? + appResponseLength = static_cast(appResponseLength + dataLen); } emberAfAttributesPrintln("READ: clus %2x, attr %2x, dataLen: %x, OK", clusterId, attrId, dataLen); @@ -448,7 +449,7 @@ EmberAfStatus emberAfAppendAttributeReportFields(uint8_t endpoint, EmberAfCluste #else memmove(buffer + *bufIndex, data, size); #endif - *bufIndex += size; + *bufIndex = static_cast(*bufIndex + size); kickout: emberAfAttributesPrintln("REPORT: clus 0x%2x, attr 0x%2x: 0x%x", clusterId, attributeId, status); diff --git a/src/app/util/chip-message-send.cpp b/src/app/util/chip-message-send.cpp index c920d5536c1aa1..69ec6ead85670a 100644 --- a/src/app/util/chip-message-send.cpp +++ b/src/app/util/chip-message-send.cpp @@ -42,13 +42,14 @@ extern "C" { EmberStatus chipSendUnicast(NodeId destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message) { - uint16_t frameSize = encodeApsFrame(nullptr, 0, apsFrame); - uint32_t dataLength = uint32_t(frameSize) + uint32_t(messageLength); - if (dataLength > UINT16_MAX) + uint16_t frameSize = encodeApsFrame(nullptr, 0, apsFrame); + uint32_t dataLengthUnchecked = uint32_t(frameSize) + uint32_t(messageLength); + if (dataLengthUnchecked > UINT16_MAX) { // Definitely too long for a packet! return EMBER_MESSAGE_TOO_LONG; } + uint16_t dataLength = static_cast(dataLengthUnchecked); if (frameSize == 0) { diff --git a/src/app/util/client-api.cpp b/src/app/util/client-api.cpp index bf4bb928d73b6c..c229956d8109ab 100644 --- a/src/app/util/client-api.cpp +++ b/src/app/util/client-api.cpp @@ -136,19 +136,19 @@ static uint16_t vFillBuffer(uint8_t * buffer, uint16_t bufferLen, uint8_t frameC } else if (cmd == 'l') { - dataLen = emberAfLongStringLength(data) + 2; + dataLen = static_cast(emberAfLongStringLength(data) + 2); } else if (cmd == 's') { - dataLen = emberAfStringLength(data) + 1; + dataLen = static_cast(emberAfStringLength(data) + 1); } else if ('0' <= cmd && cmd <= '9') { - dataLen = cmd - '0'; + dataLen = static_cast(cmd - '0'); } else if ('A' <= cmd && cmd <= 'G') { - dataLen = cmd - 'A' + 10; + dataLen = static_cast(cmd - 'A' + 10); } else { @@ -217,7 +217,7 @@ static uint16_t vFillBuffer(uint8_t * buffer, uint16_t bufferLen, uint8_t frameC return 0; } memcpy(buffer + bytes, data, dataLen); - bytes += dataLen; + bytes = static_cast(bytes + dataLen); } } diff --git a/src/app/util/esi-management.h b/src/app/util/esi-management.h index fdf7dd22a13682..d2b102b3614af0 100644 --- a/src/app/util/esi-management.h +++ b/src/app/util/esi-management.h @@ -59,7 +59,7 @@ typedef struct { EmberEUI64 eui64; - EmberNodeId nodeId; + ChipNodeId nodeId; uint8_t networkIndex; uint8_t endpoint; uint8_t age; // The number of discovery cycles the ESI has not been discovered. diff --git a/src/app/util/message.cpp b/src/app/util/message.cpp index a8b70f314391f9..c5c196bb4084f1 100644 --- a/src/app/util/message.cpp +++ b/src/app/util/message.cpp @@ -143,7 +143,7 @@ uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length) if ((appResponseLength + length) < EMBER_AF_RESPONSE_BUFFER_LEN) { memmove(appResponseData + appResponseLength, data, length); - appResponseLength += length; + appResponseLength = static_cast(appResponseLength + length); return &appResponseData[appResponseLength - length]; } else @@ -155,7 +155,7 @@ uint8_t * emberAfPutBlockInResp(const uint8_t * data, uint16_t length) uint8_t * emberAfPutStringInResp(const uint8_t * buffer) { uint8_t length = emberAfStringLength(buffer); - return emberAfPutBlockInResp(buffer, length + 1); + return emberAfPutBlockInResp(buffer, static_cast(length + 1)); } uint8_t * emberAfPutDateInResp(EmberAfDate * value) diff --git a/src/app/util/process-global-message.cpp b/src/app/util/process-global-message.cpp index e2c1748cfc32dd..c11a406534aabb 100644 --- a/src/app/util/process-global-message.cpp +++ b/src/app/util/process-global-message.cpp @@ -136,10 +136,10 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // Make the ZCL header for the response // note: cmd byte is set below - frameControl = (ZCL_GLOBAL_COMMAND | - (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER - ? ZCL_FRAME_CONTROL_SERVER_TO_CLIENT | EMBER_AF_DEFAULT_RESPONSE_POLICY_RESPONSES - : ZCL_FRAME_CONTROL_CLIENT_TO_SERVER | EMBER_AF_DEFAULT_RESPONSE_POLICY_RESPONSES)); + frameControl = static_cast(ZCL_GLOBAL_COMMAND | + (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER + ? ZCL_FRAME_CONTROL_SERVER_TO_CLIENT | EMBER_AF_DEFAULT_RESPONSE_POLICY_RESPONSES + : ZCL_FRAME_CONTROL_CLIENT_TO_SERVER | EMBER_AF_DEFAULT_RESPONSE_POLICY_RESPONSES)); if (cmd->mfgSpecific) { frameControl |= ZCL_MANUFACTURER_SPECIFIC_MASK; @@ -219,9 +219,10 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // This function reads the attribute and creates the correct response // in the response buffer emberAfRetrieveAttributeAndCraftResponse(cmd->apsFrame->destinationEndpoint, clusterId, attrId, clientServerMask, - cmd->mfgCode, (EMBER_AF_RESPONSE_BUFFER_LEN - appResponseLength)); + cmd->mfgCode, + static_cast(EMBER_AF_RESPONSE_BUFFER_LEN - appResponseLength)); // Go to next attrID - msgIndex += 2; + msgIndex = static_cast(msgIndex + 2); } } @@ -279,7 +280,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // Increment past the attribute id (two bytes), the type (one byte), and // the data (N bytes, including the length byte for strings). - msgIndex += 3 + dataSize; + msgIndex = static_cast(msgIndex + 3 + dataSize); } // If there are any failures, send the response and exit if (numFailures > 0) @@ -379,7 +380,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // Increment past the attribute id (two bytes), the type (one byte), and // the data (N bytes, including the length byte for strings). - msgIndex += 3 + dataSize; + msgIndex = static_cast(msgIndex + 3 + dataSize); } else { @@ -536,14 +537,16 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) #endif #if defined(EMBER_AF_PLUGIN_IAS_ZONE_CLIENT) - emberAfPluginIasZoneClientReadAttributesResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex); + emberAfPluginIasZoneClientReadAttributesResponseCallback(clusterId, message + msgIndex, + static_cast(msgLen - msgIndex)); #endif #if defined(EMBER_AF_PLUGIN_SIMPLE_METERING_SERVER) - emberAfPluginSimpleMeteringClusterReadAttributesResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex); + emberAfPluginSimpleMeteringClusterReadAttributesResponseCallback(clusterId, message + msgIndex, + static_cast(msgLen - msgIndex)); #endif - if (!emberAfReadAttributesResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex)) + if (!emberAfReadAttributesResponseCallback(clusterId, message + msgIndex, static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } @@ -553,14 +556,16 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) case ZCL_WRITE_ATTRIBUTES_RESPONSE_COMMAND_ID: #if defined(EMBER_AF_PLUGIN_TEST_HARNESS) - emberAfPluginTestHarnessWriteAttributesResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex); + emberAfPluginTestHarnessWriteAttributesResponseCallback(clusterId, message + msgIndex, + static_cast(msgLen - msgIndex)); #endif #if defined(EMBER_AF_PLUGIN_IAS_ZONE_CLIENT) - emberAfPluginIasZoneClientWriteAttributesResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex); + emberAfPluginIasZoneClientWriteAttributesResponseCallback(clusterId, message + msgIndex, + static_cast(msgLen - msgIndex)); #endif - if (!emberAfWriteAttributesResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex)) + if (!emberAfWriteAttributesResponseCallback(clusterId, message + msgIndex, static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } @@ -568,7 +573,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // ([status:1] [direction:1] [attribute id:2])+ case ZCL_CONFIGURE_REPORTING_RESPONSE_COMMAND_ID: - if (!emberAfConfigureReportingResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex)) + if (!emberAfConfigureReportingResponseCallback(clusterId, message + msgIndex, static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } @@ -578,7 +583,8 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // ... [min interval:0/2] [max interval:0/2] [reportable change:0/V] ... // ... [timeout:0/2])+ case ZCL_READ_REPORTING_CONFIGURATION_RESPONSE_COMMAND_ID: - if (!emberAfReadReportingConfigurationResponseCallback(clusterId, message + msgIndex, msgLen - msgIndex)) + if (!emberAfReadReportingConfigurationResponseCallback(clusterId, message + msgIndex, + static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } @@ -586,7 +592,7 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) // ([attribute id:2] [type:1] [data:V])+ case ZCL_REPORT_ATTRIBUTES_COMMAND_ID: - if (!emberAfReportAttributesCallback(clusterId, message + msgIndex, msgLen - msgIndex)) + if (!emberAfReportAttributesCallback(clusterId, message + msgIndex, static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } @@ -611,7 +617,8 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) case ZCL_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE_COMMAND_ID: { bool discoveryComplete = emberAfGetInt8u(message, msgIndex, msgLen); msgIndex++; - if (!emberAfDiscoverAttributesResponseCallback(clusterId, discoveryComplete, message + msgIndex, msgLen - msgIndex, + if (!emberAfDiscoverAttributesResponseCallback(clusterId, discoveryComplete, message + msgIndex, + static_cast(msgLen - msgIndex), (zclCmd == ZCL_DISCOVER_ATTRIBUTES_EXTENDED_RESPONSE_COMMAND_ID))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); @@ -642,8 +649,8 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) } savedIndex = appResponseLength; flag = emberAfExtractCommandIds(flag, cmd, clusterId, appResponseData + appResponseLength + 1, - EMBER_AF_RESPONSE_BUFFER_LEN - appResponseLength - 1, &appResponseLength, - startCommandIdentifier, maximumCommandIdentifiers); + static_cast(EMBER_AF_RESPONSE_BUFFER_LEN - appResponseLength - 1), + &appResponseLength, startCommandIdentifier, maximumCommandIdentifiers); appResponseData[savedIndex] = (flag ? 1 : 0); appResponseLength++; emberAfSendResponse(); @@ -655,9 +662,10 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) if (msgIndex <= msgLen) { printDiscoverCommandsResponse(false, // is ZCL command generated? - clusterId, discoveryComplete, message + msgIndex, msgLen - msgIndex); + clusterId, discoveryComplete, message + msgIndex, + static_cast(msgLen - msgIndex)); if (!emberAfDiscoverCommandsReceivedResponseCallback(clusterId, cmd->mfgCode, discoveryComplete, message + msgIndex, - msgLen - msgIndex)) + static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } @@ -674,9 +682,10 @@ bool emAfProcessGlobalCommand(EmberAfClusterCommand * cmd) if (msgIndex <= msgLen) { printDiscoverCommandsResponse(true, // is ZCL command generated? - clusterId, discoveryComplete, message + msgIndex, msgLen - msgIndex); + clusterId, discoveryComplete, message + msgIndex, + static_cast(msgLen - msgIndex)); if (!emberAfDiscoverCommandsGeneratedResponseCallback(clusterId, cmd->mfgCode, discoveryComplete, message + msgIndex, - msgLen - msgIndex)) + static_cast(msgLen - msgIndex))) { emberAfSendDefaultResponse(cmd, EMBER_ZCL_STATUS_SUCCESS); } diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 19281377b8b252..025bfef0d6793c 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -235,7 +235,7 @@ static void prepareForResponse(const EmberAfClusterCommand * cmd) if (cmd->interPanHeader == NULL) { emberAfResponseDestination = cmd->source; - emberAfResponseType &= ~ZCL_UTIL_RESP_INTERPAN; + emberAfResponseType = static_cast(emberAfResponseType & ~ZCL_UTIL_RESP_INTERPAN); } else { @@ -402,9 +402,9 @@ static void printIncomingZclMessage(const EmberAfClusterCommand * cmd) cmd->buffer[0], // frame control cmd->seqNum, cmd->commandId); emberAfAppFlush(); - emberAfAppPrintBuffer(cmd->buffer + cmd->payloadStartIndex, // message - cmd->bufLen - cmd->payloadStartIndex, // length - true); // spaces? + emberAfAppPrintBuffer(cmd->buffer + cmd->payloadStartIndex, // message + static_cast(cmd->bufLen - cmd->payloadStartIndex), // length + true); // spaces? emberAfAppFlush(); emberAfAppPrintln("]"); } @@ -480,8 +480,8 @@ bool emberAfProcessMessageIntoZclCmd(EmberApsFrame * apsFrame, EmberIncomingMess returnCmd->payloadStartIndex = 1; if (returnCmd->mfgSpecific) { - returnCmd->mfgCode = emberAfGetInt16u(message, returnCmd->payloadStartIndex, messageLength); - returnCmd->payloadStartIndex += 2; + returnCmd->mfgCode = emberAfGetInt16u(message, returnCmd->payloadStartIndex, messageLength); + returnCmd->payloadStartIndex = static_cast(returnCmd->payloadStartIndex + 2); } else { @@ -629,7 +629,7 @@ void emberAfSetNoReplyForNextMessage(bool set) } else { - emberAfResponseType &= ~ZCL_UTIL_RESP_NONE; + emberAfResponseType = static_cast(emberAfResponseType & ~ZCL_UTIL_RESP_NONE); } } @@ -655,7 +655,7 @@ void emAfApplyRetryOverride(EmberApsOption * options) } else if (emberAfApsRetryOverride == EMBER_AF_RETRY_OVERRIDE_UNSET) { - *options &= ~EMBER_APS_OPTION_RETRY; + *options = static_cast(*options & ~EMBER_APS_OPTION_RETRY); } else { @@ -747,9 +747,9 @@ EmberStatus emberAfSendResponseWithCallback(EmberAfMessageSentFunction callback) // the destination of the message. if ((emberAfResponseType & ZCL_UTIL_RESP_INTERPAN) != 0U) { - label = 'I'; - status = emberAfInterpanSendMessageCallback(&interpanResponseHeader, appResponseLength, appResponseData); - emberAfResponseType &= ~ZCL_UTIL_RESP_INTERPAN; + label = 'I'; + status = emberAfInterpanSendMessageCallback(&interpanResponseHeader, appResponseLength, appResponseData); + emberAfResponseType = static_cast(emberAfResponseType & ~ZCL_UTIL_RESP_INTERPAN); } else if (!isBroadcastDestination(emberAfResponseDestination)) { @@ -830,9 +830,9 @@ EmberStatus emberAfSendDefaultResponseWithCallback(const EmberAfClusterCommand * } appResponseLength = 0; - frameControl = (ZCL_GLOBAL_COMMAND | - (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER ? ZCL_FRAME_CONTROL_SERVER_TO_CLIENT - : ZCL_FRAME_CONTROL_CLIENT_TO_SERVER)); + frameControl = static_cast(ZCL_GLOBAL_COMMAND | + (cmd->direction == ZCL_DIRECTION_CLIENT_TO_SERVER ? ZCL_FRAME_CONTROL_SERVER_TO_CLIENT + : ZCL_FRAME_CONTROL_CLIENT_TO_SERVER)); if (!cmd->mfgSpecific) { @@ -964,24 +964,24 @@ bool emberAfDetermineIfLinkSecurityIsRequired(uint8_t commandId, bool incoming, uint8_t emberAfMaximumApsPayloadLength(EmberOutgoingMessageType type, uint64_t indexOrDestination, EmberApsFrame * apsFrame) { - EmberNodeId destination = EMBER_UNKNOWN_NODE_ID; - uint8_t max = EMBER_AF_MAXIMUM_APS_PAYLOAD_LENGTH; + ChipNodeId destination = EMBER_UNKNOWN_NODE_ID; + uint8_t max = EMBER_AF_MAXIMUM_APS_PAYLOAD_LENGTH; if ((apsFrame->options & EMBER_APS_OPTION_ENCRYPTION) != 0U) { - max -= EMBER_AF_APS_ENCRYPTION_OVERHEAD; + max = static_cast(max - EMBER_AF_APS_ENCRYPTION_OVERHEAD); } if ((apsFrame->options & EMBER_APS_OPTION_SOURCE_EUI64) != 0U) { - max -= EUI64_SIZE; + max = static_cast(max - EUI64_SIZE); } if ((apsFrame->options & EMBER_APS_OPTION_DESTINATION_EUI64) != 0U) { - max -= EUI64_SIZE; + max = static_cast(max - EUI64_SIZE); } if ((apsFrame->options & EMBER_APS_OPTION_FRAGMENT) != 0U) { - max -= EMBER_AF_APS_FRAGMENTATION_OVERHEAD; + max = static_cast(max - EMBER_AF_APS_FRAGMENTATION_OVERHEAD); } switch (type) @@ -1007,7 +1007,7 @@ uint8_t emberAfMaximumApsPayloadLength(EmberOutgoingMessageType type, uint64_t i break; } - max -= emberAfGetSourceRouteOverheadCallback(destination); + max = static_cast(max - emberAfGetSourceRouteOverheadCallback(destination)); return max; } @@ -1178,7 +1178,7 @@ int8_t emberAfCompareDates(EmberAfDate* date1, EmberAfDate* date2) // 2.15 from the ZCL spec 075123r02 uint8_t emberAfGetAttributeAnalogOrDiscreteType(uint8_t dataType) { - uint8_t index = 0; + unsigned index = 0; while (emberAfAnalogDiscreteThresholds[index] < dataType) { @@ -1240,12 +1240,13 @@ uint8_t emberAfAppendCharacters(uint8_t * zclString, uint8_t zclStringMaxLen, co return 0; } - freeChars = zclStringMaxLen - curLen; + freeChars = static_cast(zclStringMaxLen - curLen); charsToWrite = (freeChars > appendingCharsLen) ? appendingCharsLen : freeChars; memcpy(&zclString[1 + curLen], // 1 is to account for zcl's length byte appendingChars, charsToWrite); - zclString[0] = curLen + charsToWrite; + // Cast is safe, because the sum can't be bigger than zclStringMaxLen. + zclString[0] = static_cast(curLen + charsToWrite); return charsToWrite; }