Skip to content

Commit

Permalink
Add -Wconversion to various things in src/app (#7902)
Browse files Browse the repository at this point in the history
* Add -Wconversion to various things in src/app.

* Regenerate generated files
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 16, 2021
1 parent 62b2dbe commit 09e686c
Show file tree
Hide file tree
Showing 29 changed files with 120 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(index - 1));
if (entryOffset == 0)
{
ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index);
Expand All @@ -155,7 +155,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
return 0;
}

entryLength = acceptsHeaderListSpan->size();
if (!CanCastTo<uint16_t>(acceptsHeaderListSpan->size()))
{
ChipLogError(Zcl, "Span size %zu is too large", acceptsHeaderListSpan->size());
return 0;
}
entryLength = static_cast<uint16_t>(acceptsHeaderListSpan->size());
break;
}
case 0x0001: // supported streaming types
Expand Down Expand Up @@ -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<uint16_t>(index - 1));
if (entryOffset == 0)
{
ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index);
Expand All @@ -565,7 +570,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
return 0;
}

entryLength = listOctetStringSpan->size();
if (!CanCastTo<uint16_t>(listOctetStringSpan->size()))
{
ChipLogError(Zcl, "Span size %zu is too large", listOctetStringSpan->size());
return 0;
}
entryLength = static_cast<uint16_t>(listOctetStringSpan->size());
break;
}
case 0x001C: // list_struct_octet_string
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions examples/lighting-app/qpg6100/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
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);
}
}
9 changes: 7 additions & 2 deletions examples/tv-app/tv-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(index - 1));
if (entryOffset == 0)
{
ChipLogError(Zcl, "Index %" PRId32 " is invalid.", index);
Expand All @@ -155,7 +155,12 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
return 0;
}

entryLength = acceptsHeaderListSpan->size();
if (!CanCastTo<uint16_t>(acceptsHeaderListSpan->size()))
{
ChipLogError(Zcl, "Span size %zu is too large", acceptsHeaderListSpan->size());
return 0;
}
entryLength = static_cast<uint16_t>(acceptsHeaderListSpan->size());
break;
}
case 0x0001: // supported streaming types
Expand Down
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 @@ -857,17 +857,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
Loading

0 comments on commit 09e686c

Please sign in to comment.