Skip to content

Commit

Permalink
Modernize use nullptr (project-chip#16306)
Browse files Browse the repository at this point in the history
* use clang-tidy to modernize-use-nullptr

* Use BLE_CONNECTION_UNINITIALIZED instead of NULL for ble comparisons

* Define BLE_CONNECTION_UNINITIALIZED as nullptr instead of NULL

* Restyle
  • Loading branch information
andy31415 authored and andrei-menzopol committed Apr 14, 2022
1 parent fbaa789 commit 976a19d
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/app/MessageDef/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace chip::TLV;

namespace chip {
namespace app {
Builder::Builder() : mError(CHIP_ERROR_INCORRECT_STATE), mpWriter(NULL), mOuterContainerType(chip::TLV::kTLVType_NotSpecified) {}
Builder::Builder() : mError(CHIP_ERROR_INCORRECT_STATE), mpWriter(nullptr), mOuterContainerType(chip::TLV::kTLVType_NotSpecified) {}

void Builder::Init(chip::TLV::TLVWriter * const apWriter, chip::TLV::TLVType aOuterContainerType)
{
Expand Down
12 changes: 6 additions & 6 deletions src/app/util/af-event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const char * emAfEventStrings[] = {
EMBER_AF_GENERATED_EVENT_STRINGS
#endif

NULL,
nullptr,
};

EmberEventData emAfEvents[] = {
Expand All @@ -93,7 +93,7 @@ EmberEventData emAfEvents[] = {
EMBER_AF_GENERATED_EVENTS
#endif

{ NULL, NULL }
{ nullptr, nullptr }
};

void EventControlHandler(chip::System::Layer * systemLayer, void * appState)
Expand All @@ -103,7 +103,7 @@ void EventControlHandler(chip::System::Layer * systemLayer, void * appState)
{
control->status = EMBER_EVENT_INACTIVE;

if (control->callback != NULL)
if (control->callback != nullptr)
{
(control->callback)(control->endpoint);
return;
Expand Down Expand Up @@ -146,7 +146,7 @@ static EmberAfEventContext * findEventContext(EndpointId endpoint, ClusterId clu
}
}
#endif // EMBER_AF_GENERATED_EVENT_CONTEXT
return NULL;
return nullptr;
}

EmberStatus emberEventControlSetDelayMS(EmberEventControl * control, uint32_t delayMs)
Expand Down Expand Up @@ -218,7 +218,7 @@ EmberStatus emberAfScheduleTickExtended(EndpointId endpoint, ClusterId clusterId
// simulation.
EMBER_TEST_ASSERT(emberAfEndpointIsEnabled(endpoint));

if (context != NULL && emberAfEndpointIsEnabled(endpoint) &&
if (context != nullptr && emberAfEndpointIsEnabled(endpoint) &&
(emberEventControlSetDelayMS(context->eventControl, delayMs) == EMBER_SUCCESS))
{
context->pollControl = pollControl;
Expand Down Expand Up @@ -261,7 +261,7 @@ EmberStatus emberAfScheduleServerTick(EndpointId endpoint, ClusterId clusterId,
EmberStatus emberAfDeactivateClusterTick(EndpointId endpoint, ClusterId clusterId, bool isClient)
{
EmberAfEventContext * context = findEventContext(endpoint, clusterId, isClient);
if (context != NULL)
if (context != nullptr)
{
emberEventControlSetInactive(context->eventControl);
return EMBER_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/attribute-size-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ uint16_t emberAfAttributeValueSize(ClusterId clusterId, AttributeId attrId, Embe
uint16_t dataSize = 0;
if (emberAfIsThisDataTypeAStringType(dataType))
{
if (buffer != 0)
if (buffer != nullptr)
{
if (emberAfIsStringAttributeType(dataType))
{
Expand Down
68 changes: 34 additions & 34 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ void emberAfClusterDefaultResponseCallback(EndpointId endpoint, ClusterId cluste
uint8_t clientServerMask)
{
const EmberAfCluster * cluster = emberAfFindCluster(endpoint, clusterId, clientServerMask);
if (cluster != NULL)
if (cluster != nullptr)
{
EmberAfGenericClusterFunction f = emberAfFindClusterFunction(cluster, CLUSTER_MASK_DEFAULT_RESPONSE_FUNCTION);
if (f != NULL)
if (f != nullptr)
{
((EmberAfDefaultResponseFunction) f)(endpoint, commandId, status);
}
Expand All @@ -330,16 +330,16 @@ void emberAfClusterDefaultResponseCallback(EndpointId endpoint, ClusterId cluste
void emberAfClusterMessageSentCallback(const MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t msgLen,
uint8_t * message, EmberStatus status)
{
if (apsFrame != NULL && message != NULL && msgLen != 0)
if (apsFrame != nullptr && message != nullptr && msgLen != 0)
{
const EmberAfCluster * cluster = emberAfFindCluster(
apsFrame->sourceEndpoint, apsFrame->clusterId,
(((message[0] & ZCL_FRAME_CONTROL_DIRECTION_MASK) == ZCL_FRAME_CONTROL_SERVER_TO_CLIENT) ? CLUSTER_MASK_SERVER
: CLUSTER_MASK_CLIENT));
if (cluster != NULL)
if (cluster != nullptr)
{
EmberAfGenericClusterFunction f = emberAfFindClusterFunction(cluster, CLUSTER_MASK_MESSAGE_SENT_FUNCTION);
if (f != NULL)
if (f != nullptr)
{
((EmberAfMessageSentFunction) f)(destination, apsFrame, msgLen, message, status);
}
Expand All @@ -351,10 +351,10 @@ void emberAfClusterMessageSentCallback(const MessageSendDestination & destinatio
void emAfClusterAttributeChangedCallback(const app::ConcreteAttributePath & attributePath, uint8_t clientServerMask)
{
const EmberAfCluster * cluster = emberAfFindCluster(attributePath.mEndpointId, attributePath.mClusterId, clientServerMask);
if (cluster != NULL)
if (cluster != nullptr)
{
EmberAfGenericClusterFunction f = emberAfFindClusterFunction(cluster, CLUSTER_MASK_ATTRIBUTE_CHANGED_FUNCTION);
if (f != NULL)
if (f != nullptr)
{
((EmberAfClusterAttributeChangedCallback) f)(attributePath);
}
Expand All @@ -366,7 +366,7 @@ EmberAfStatus emAfClusterPreAttributeChangedCallback(const app::ConcreteAttribut
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
{
const EmberAfCluster * cluster = emberAfFindCluster(attributePath.mEndpointId, attributePath.mClusterId, clientServerMask);
if (cluster == NULL)
if (cluster == nullptr)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
}
Expand All @@ -376,7 +376,7 @@ EmberAfStatus emAfClusterPreAttributeChangedCallback(const app::ConcreteAttribut
// of the call on gcc-arm-none-eabi-9-2019-q4-major
EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)(
emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION));
if (f != NULL)
if (f != nullptr)
{
status = f(attributePath, attributeType, size, value);
}
Expand All @@ -393,7 +393,7 @@ static void initializeEndpoint(EmberAfDefinedEndpoint * definedEndpoint)
EmberAfGenericClusterFunction f;
emberAfClusterInitCallback(definedEndpoint->endpoint, cluster->clusterId);
f = emberAfFindClusterFunction(cluster, CLUSTER_MASK_INIT_FUNCTION);
if (f != NULL)
if (f != nullptr)
{
((EmberAfInitFunction) f)(definedEndpoint->endpoint);
}
Expand All @@ -417,16 +417,16 @@ void emAfCallInits(void)
const EmberAfAttributeMetadata * emberAfLocateAttributeMetadata(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,
uint8_t mask)
{
const EmberAfAttributeMetadata * metadata = NULL;
const EmberAfAttributeMetadata * metadata = nullptr;
EmberAfAttributeSearchRecord record;
record.endpoint = endpoint;
record.clusterId = clusterId;
record.clusterMask = mask;
record.attributeId = attributeId;
emAfReadOrWriteAttribute(&record, &metadata,
NULL, // buffer
0, // buffer size
false); // write?
nullptr, // buffer
0, // buffer size
false); // write?
return metadata;
}

Expand Down Expand Up @@ -491,7 +491,7 @@ static EmberAfStatus typeSensitiveMemCopy(ClusterId clusterId, uint8_t * dest, u
{
return EMBER_ZCL_STATUS_INSUFFICIENT_SPACE;
}
if (src == NULL)
if (src == nullptr)
{
memset(dest, 0, am->size);
}
Expand Down Expand Up @@ -577,7 +577,7 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
if (emAfMatchAttribute(cluster, am, attRecord))
{ // Got the attribute
// If passed metadata location is not null, populate
if (metadata != NULL)
if (metadata != nullptr)
{
*metadata = am;
}
Expand All @@ -599,7 +599,7 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
}
else
{
if (buffer == NULL)
if (buffer == nullptr)
{
return EMBER_ZCL_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -698,7 +698,7 @@ const EmberAfCluster * emberAfFindClusterInType(const EmberAfEndpointType * endp
}
}

return NULL;
return nullptr;
}

uint8_t emberAfClusterIndex(EndpointId endpoint, ClusterId clusterId, EmberAfClusterMask mask)
Expand All @@ -711,7 +711,7 @@ uint8_t emberAfClusterIndex(EndpointId endpoint, ClusterId clusterId, EmberAfClu
{
const EmberAfEndpointType * endpointType = emAfEndpoints[ep].endpointType;
uint8_t index = 0xFF;
if (emberAfFindClusterInType(endpointType, clusterId, mask, &index) != NULL)
if (emberAfFindClusterInType(endpointType, clusterId, mask, &index) != nullptr)
{
return index;
}
Expand All @@ -724,19 +724,19 @@ uint8_t emberAfClusterIndex(EndpointId endpoint, ClusterId clusterId, EmberAfClu
// cluster on it.
bool emberAfContainsCluster(EndpointId endpoint, ClusterId clusterId)
{
return (emberAfFindCluster(endpoint, clusterId, 0) != NULL);
return (emberAfFindCluster(endpoint, clusterId, 0) != nullptr);
}

// Returns whether the given endpoint has the server of the given cluster on it.
bool emberAfContainsServer(EndpointId endpoint, ClusterId clusterId)
{
return (emberAfFindCluster(endpoint, clusterId, CLUSTER_MASK_SERVER) != NULL);
return (emberAfFindCluster(endpoint, clusterId, CLUSTER_MASK_SERVER) != nullptr);
}

// Returns whether the given endpoint has the client of the given cluster on it.
bool emberAfContainsClient(EndpointId endpoint, ClusterId clusterId)
{
return (emberAfFindCluster(endpoint, clusterId, CLUSTER_MASK_CLIENT) != NULL);
return (emberAfFindCluster(endpoint, clusterId, CLUSTER_MASK_CLIENT) != nullptr);
}

// This will find the first server that has the clusterId given from the index of endpoint.
Expand Down Expand Up @@ -789,7 +789,7 @@ const EmberAfCluster * emberAfFindCluster(EndpointId endpoint, ClusterId cluster
uint16_t ep = emberAfIndexFromEndpoint(endpoint);
if (ep == 0xFFFF)
{
return NULL;
return nullptr;
}

return emberAfFindClusterInType(emAfEndpoints[ep].endpointType, clusterId, mask);
Expand All @@ -804,7 +804,7 @@ const EmberAfCluster * emberAfFindClusterIncludingDisabledEndpoints(EndpointId e
{
return emberAfFindClusterInType(emAfEndpoints[ep].endpointType, clusterId, mask);
}
return NULL;
return nullptr;
}

// Server wrapper for findClusterEndpointIndex
Expand All @@ -824,7 +824,7 @@ static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterI
{
uint16_t i, epi = 0;

if (emberAfFindCluster(endpoint, clusterId, mask) == NULL)
if (emberAfFindCluster(endpoint, clusterId, mask) == nullptr)
{
return 0xFFFF;
}
Expand All @@ -836,7 +836,7 @@ static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterI
break;
}
epi = static_cast<uint16_t>(
epi + ((emberAfFindClusterIncludingDisabledEndpoints(emAfEndpoints[i].endpoint, clusterId, mask) != NULL) ? 1 : 0));
epi + ((emberAfFindClusterIncludingDisabledEndpoints(emAfEndpoints[i].endpoint, clusterId, mask) != nullptr) ? 1 : 0));
}

return epi;
Expand Down Expand Up @@ -1002,7 +1002,7 @@ uint8_t emberAfClusterCount(EndpointId endpoint, bool server)
uint8_t emberAfClusterCountByIndex(uint16_t endpointIndex, bool server)
{
const EmberAfDefinedEndpoint * de = &(emAfEndpoints[endpointIndex]);
if (de->endpointType == NULL)
if (de->endpointType == nullptr)
{
return 0;
}
Expand Down Expand Up @@ -1054,13 +1054,13 @@ const EmberAfCluster * emberAfGetClusterByIndex(EndpointId endpoint, uint8_t clu

if (endpointIndex == 0xFFFF)
{
return NULL;
return nullptr;
}
definedEndpoint = &(emAfEndpoints[endpointIndex]);

if (clusterIndex >= definedEndpoint->endpointType->clusterCount)
{
return NULL;
return nullptr;
}
return &(definedEndpoint->endpointType->cluster[clusterIndex]);
}
Expand All @@ -1086,7 +1086,7 @@ const EmberAfCluster * emberAfGetNthCluster(EndpointId endpoint, uint8_t n, bool

if (index == 0xFFFF)
{
return NULL;
return nullptr;
}
de = &(emAfEndpoints[index]);

Expand All @@ -1103,7 +1103,7 @@ const EmberAfCluster * emberAfGetNthCluster(EndpointId endpoint, uint8_t n, bool
c++;
}
}
return NULL;
return nullptr;
}

// Returns the cluster id of Nth server or client cluster,
Expand Down Expand Up @@ -1133,7 +1133,7 @@ uint8_t emberAfGetClustersFromEndpoint(EndpointId endpoint, ClusterId * clusterL
for (i = 0; i < clusterCount; i++)
{
cluster = emberAfGetNthCluster(endpoint, i, server);
clusterList[i] = (cluster == NULL ? 0xFFFF : cluster->clusterId);
clusterList[i] = (cluster == nullptr ? 0xFFFF : cluster->clusterId);
}
return clusterCount;
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional
}

emAfReadOrWriteAttribute(&record,
NULL, // metadata - unused
nullptr, // metadata - unused
ptr,
0, // buffer size - unused
true); // write?
Expand Down Expand Up @@ -1341,7 +1341,7 @@ EmberAfGenericClusterFunction emberAfFindClusterFunction(const EmberAfCluster *

if ((cluster->mask & functionMask) == 0)
{
return NULL;
return nullptr;
}

while (mask < functionMask)
Expand Down
Loading

0 comments on commit 976a19d

Please sign in to comment.