Skip to content

Commit

Permalink
Add -Wconversion to various things in src/app.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Jun 25, 2021
1 parent bf61e87 commit c6c3607
Show file tree
Hide file tree
Showing 23 changed files with 77 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/lock-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion examples/lock-app/qpg6100/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 *) &currentLevel, sizeof(uint8_t));
Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/door-lock-server/door-lock-server-user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/app/clusters/scenes/scenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,17 @@ 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<uint16_t>(extensionFieldSetsIndex + 2);
length = static_cast<uint8_t>(length - 2);
if (length < 2)
{
break;
}
entry.hasOccupiedHeatingSetpointValue = true;
entry.occupiedHeatingSetpointValue =
(int16_t) emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
extensionFieldSetsIndex += 2;
length -= 2;
extensionFieldSetsIndex = static_cast<uint16_t>(extensionFieldSetsIndex + 2);
length = static_cast<uint8_t>(length - 2);
if (length < 1)
{
break;
Expand Down
2 changes: 2 additions & 0 deletions src/app/server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static_library("server") {

public_configs = [ ":server_config" ]

cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/app",
"${chip_root}/src/lib/mdns",
Expand Down
7 changes: 4 additions & 3 deletions src/app/server/OnboardingCodesUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(aUrlMaxSize)),
VerifyOrReturnError((writtenDataSize > 0) && (static_cast<size_t>(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<size_t>(writtenDataSize));
}

CHIP_ERROR GetManualPairingCode(std::string & aManualPairingCode, chip::RendezvousInformationFlags aRendezvousFlags)
Expand Down Expand Up @@ -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))
{

Expand Down
2 changes: 2 additions & 0 deletions src/app/tests/integration/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ executable("chip-im-responder") {
"${chip_root}/src/system",
]

cflags = [ "-Wconversion" ]

output_dir = root_out_dir
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/MockEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/app/tests/integration/MockEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/af-enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <stdint.h>

enum EmberAfStatus : uint32_t
enum EmberAfStatus : uint8_t
{
EMBER_ZCL_STATUS_SUCCESS = 0x00,
EMBER_ZCL_STATUS_FAILURE = 0x01,
Expand Down
8 changes: 8 additions & 0 deletions src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
#include <app/util/debug-printing.h>
#include <app/util/ember-print.h>

#include <lib/support/SafeInt.h>

/** @name Attribute Storage */
// @{

Expand Down Expand Up @@ -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
*/
Expand All @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ uint8_t emberAfGetDynamicIndexFromEndpoint(EndpointId id)
{
if (emAfEndpoints[index].endpoint == id)
{
return index - FIXED_ENDPOINT_COUNT;
return static_cast<uint8_t>(index - FIXED_ENDPOINT_COUNT);
}
}
return 0xFF;
Expand All @@ -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<uint8_t>(realIndex);

for (uint8_t i = FIXED_ENDPOINT_COUNT; i < MAX_ENDPOINT_COUNT; i++)
{
if (emAfEndpoints[i].endpoint == id)
Expand Down Expand Up @@ -213,7 +215,7 @@ EndpointId emberAfClearDynamicEndpoint(uint8_t index)
{
EndpointId ep = 0;

index += FIXED_ENDPOINT_COUNT;
index = static_cast<uint8_t>(index + FIXED_ENDPOINT_COUNT);

if ((index < MAX_ENDPOINT_COUNT) && (emAfEndpoints[index].endpoint != 0) && (emberAfEndpointIndexIsEnabled(index)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/attribute-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(commandExchangeCtx->GetExchangeId() & 0xFF) : 0);

imCompatibilityEmberAfCluster.commandId = commandId;
imCompatibilityEmberAfCluster.apsFrame = &imCompatibilityEmberApsFrame;
Expand Down
5 changes: 5 additions & 0 deletions src/app/util/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ void emberAfPutInt16sInResp(int16_t value)
emberAfPutInt16uInResp(static_cast<uint16_t>(value));
}

void emberAfPutStatusInResp(EmberAfStatus value)
{
emberAfPutInt8uInResp(static_cast<std::underlying_type_t<EmberAfStatus>>(value));
}

// ------------------------------------
// Utilities for reading from RAM buffers (reading from incoming message
// buffer)
Expand Down
6 changes: 3 additions & 3 deletions src/app/util/process-global-message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/app/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions src/app/zap-templates/templates/app/attribute-size-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(index - 1));
if (entryOffset == 0)
{
ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index);
Expand All @@ -113,7 +113,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
return 0;
}

entryLength = {{asCamelCased name}}Span->size();
if (!CanCastTo<uint16_t>({{asCamelCased name}}Span->size()))
{
ChipLogError(Zcl, "Span size %zu is too large", {{asCamelCased name}}Span->size());
return 0;
}
entryLength = static_cast<uint16_t>({{asCamelCased name}}Span->size());
{{else}}
copyListMember(dest, src, write, &entryOffset, entryLength); // {{type}}
{{/if}}
Expand Down
Loading

0 comments on commit c6c3607

Please sign in to comment.