From 1326d64a6411432866418384b1458bd05e6b1cb0 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 17 Jun 2020 22:44:54 -0700 Subject: [PATCH] [style] replace NULL with nullptr (#5109) --- Android.mk | 6 + examples/platforms/cc1352/CMakeLists.txt | 7 +- examples/platforms/cc2538/CMakeLists.txt | 7 +- examples/platforms/cc2650/CMakeLists.txt | 7 +- examples/platforms/cc2652/CMakeLists.txt | 7 +- examples/platforms/kw41z/CMakeLists.txt | 8 +- examples/platforms/qpg6095/CMakeLists.txt | 7 +- examples/platforms/qpg6095/settings.cpp | 4 +- examples/platforms/samr21/CMakeLists.txt | 7 +- examples/platforms/simulation/CMakeLists.txt | 7 +- examples/platforms/utils/CMakeLists.txt | 7 + examples/platforms/utils/mac_frame.cpp | 4 +- src/cli/cli.cpp | 50 ++-- src/cli/cli_coap.cpp | 44 ++-- src/cli/cli_coap.hpp | 4 +- src/cli/cli_coap_secure.cpp | 28 +-- src/cli/cli_commissioner.cpp | 6 +- src/cli/cli_console.cpp | 4 +- src/cli/cli_dataset.cpp | 4 +- src/cli/cli_joiner.cpp | 6 +- src/cli/cli_server.cpp | 2 +- src/cli/cli_udp.cpp | 10 +- src/core/api/backbone_router_api.cpp | 2 +- src/core/api/backbone_router_ftd_api.cpp | 6 +- src/core/api/border_router_api.cpp | 14 +- src/core/api/coap_api.cpp | 4 +- src/core/api/coap_secure_api.cpp | 6 +- src/core/api/crypto_api.cpp | 7 +- src/core/api/dataset_api.cpp | 16 +- src/core/api/heap_api.cpp | 2 +- src/core/api/ip6_api.cpp | 6 +- src/core/api/link_api.cpp | 12 +- src/core/api/message_api.cpp | 6 +- src/core/api/netdata_api.cpp | 2 +- src/core/api/server_api.cpp | 2 +- src/core/api/thread_api.cpp | 18 +- src/core/api/thread_ftd_api.cpp | 10 +- src/core/api/udp_api.cpp | 2 +- src/core/backbone_router/leader.hpp | 4 +- src/core/coap/coap.cpp | 124 +++++----- src/core/coap/coap.hpp | 26 +- src/core/coap/coap_message.cpp | 18 +- src/core/coap/coap_message.hpp | 24 +- src/core/coap/coap_secure.cpp | 26 +- src/core/coap/coap_secure.hpp | 10 +- src/core/common/instance.cpp | 10 +- src/core/common/instance.hpp | 4 +- src/core/common/linked_list.hpp | 48 ++-- src/core/common/message.cpp | 106 ++++---- src/core/common/message.hpp | 28 +-- src/core/common/notifier.cpp | 26 +- src/core/common/random_manager.cpp | 6 +- src/core/common/settings.hpp | 8 +- src/core/common/string.hpp | 5 +- src/core/common/tasklet.cpp | 16 +- src/core/common/tasklet.hpp | 4 +- src/core/common/timer.cpp | 4 +- src/core/common/tlvs.cpp | 10 +- src/core/common/tlvs.hpp | 2 +- src/core/common/trickle_timer.cpp | 2 +- src/core/crypto/ecdsa.cpp | 4 +- src/core/crypto/hmac_sha256.cpp | 2 +- src/core/diags/factory_diags.cpp | 2 +- src/core/diags/factory_diags.hpp | 4 +- src/core/mac/data_poll_handler.cpp | 18 +- src/core/mac/data_poll_handler.hpp | 2 +- src/core/mac/link_raw.cpp | 14 +- src/core/mac/link_raw.hpp | 6 +- src/core/mac/mac.cpp | 62 ++--- src/core/mac/mac.hpp | 10 +- src/core/mac/mac_filter.cpp | 28 +-- src/core/mac/mac_filter.hpp | 9 +- src/core/mac/mac_frame.cpp | 24 +- src/core/mac/mac_frame.hpp | 8 +- src/core/mac/sub_mac.cpp | 12 +- src/core/mac/sub_mac.hpp | 8 +- src/core/meshcop/announce_begin_client.cpp | 6 +- src/core/meshcop/border_agent.cpp | 56 ++--- src/core/meshcop/commissioner.cpp | 46 ++-- src/core/meshcop/commissioner.hpp | 6 +- src/core/meshcop/dataset.cpp | 12 +- src/core/meshcop/dataset.hpp | 10 +- src/core/meshcop/dataset_local.cpp | 8 +- src/core/meshcop/dataset_manager.cpp | 36 +-- src/core/meshcop/dataset_manager_ftd.cpp | 30 +-- src/core/meshcop/dtls.cpp | 68 +++--- src/core/meshcop/energy_scan_client.cpp | 12 +- src/core/meshcop/joiner.cpp | 30 +-- src/core/meshcop/joiner.hpp | 10 +- src/core/meshcop/joiner_router.cpp | 42 ++-- src/core/meshcop/meshcop.cpp | 2 +- src/core/meshcop/meshcop_leader.cpp | 14 +- src/core/meshcop/meshcop_tlvs.cpp | 16 +- src/core/meshcop/meshcop_tlvs.hpp | 20 +- src/core/meshcop/panid_query_client.cpp | 12 +- src/core/net/dhcp6_client.cpp | 22 +- src/core/net/dhcp6_server.cpp | 8 +- src/core/net/dns_client.cpp | 58 ++--- src/core/net/icmp6.cpp | 12 +- src/core/net/icmp6.hpp | 4 +- src/core/net/ip6.cpp | 74 +++--- src/core/net/ip6.hpp | 12 +- src/core/net/ip6_address.cpp | 6 +- src/core/net/ip6_address.hpp | 2 +- src/core/net/ip6_mpl.cpp | 24 +- src/core/net/netif.cpp | 44 ++-- src/core/net/sntp_client.cpp | 48 ++-- src/core/net/udp6.cpp | 12 +- src/core/net/udp6.hpp | 6 +- src/core/radio/radio.hpp | 6 +- src/core/radio/radio_callbacks.cpp | 2 +- src/core/thread/address_resolver.cpp | 90 +++---- src/core/thread/address_resolver.hpp | 2 +- src/core/thread/child_table.cpp | 22 +- src/core/thread/child_table.hpp | 27 ++- src/core/thread/discover_scanner.cpp | 14 +- src/core/thread/discover_scanner.hpp | 4 +- src/core/thread/dua_manager.cpp | 4 +- src/core/thread/energy_scan_server.cpp | 6 +- src/core/thread/indirect_sender.cpp | 32 +-- src/core/thread/mesh_forwarder.cpp | 58 ++--- src/core/thread/mesh_forwarder_ftd.cpp | 54 ++--- src/core/thread/mesh_forwarder_mtd.cpp | 2 +- src/core/thread/mle.cpp | 64 ++--- src/core/thread/mle.hpp | 4 +- src/core/thread/mle_router.cpp | 242 +++++++++---------- src/core/thread/mle_router.hpp | 14 +- src/core/thread/network_data.cpp | 76 +++--- src/core/thread/network_data.hpp | 54 ++--- src/core/thread/network_data_leader.cpp | 79 +++--- src/core/thread/network_data_leader.hpp | 8 +- src/core/thread/network_data_leader_ftd.cpp | 75 +++--- src/core/thread/network_data_leader_ftd.hpp | 2 +- src/core/thread/network_data_local.cpp | 10 +- src/core/thread/network_diagnostic.cpp | 32 +-- src/core/thread/network_diagnostic.hpp | 2 +- src/core/thread/panid_query_server.cpp | 6 +- src/core/thread/router_table.cpp | 44 ++-- src/core/thread/router_table.hpp | 24 +- src/core/thread/time_sync_service.cpp | 6 +- src/core/utils/channel_manager.cpp | 2 +- src/core/utils/channel_monitor.cpp | 2 +- src/core/utils/child_supervision.cpp | 10 +- src/core/utils/child_supervision.hpp | 5 +- src/core/utils/flash.cpp | 2 +- src/core/utils/flash.hpp | 8 +- src/core/utils/heap.cpp | 8 +- src/core/utils/heap.hpp | 2 +- src/core/utils/jam_detector.cpp | 6 +- src/core/utils/parse_cmdline.hpp | 2 +- src/core/utils/slaac_address.cpp | 10 +- src/core/utils/slaac_address.hpp | 6 +- src/lib/hdlc/hdlc.hpp | 13 +- src/lib/spinel/radio_spinel.hpp | 4 +- src/lib/spinel/radio_spinel_impl.hpp | 36 +-- src/lib/spinel/spinel_buffer.cpp | 42 ++-- src/lib/spinel/spinel_buffer.hpp | 4 +- src/lib/spinel/spinel_decoder.cpp | 4 +- src/lib/spinel/spinel_encoder.hpp | 2 +- src/ncp/changed_props_set.hpp | 7 +- src/ncp/example_vendor_hook.cpp | 4 +- src/ncp/ncp_base.cpp | 34 +-- src/ncp/ncp_base.hpp | 8 +- src/ncp/ncp_base_dispatcher.cpp | 2 +- src/ncp/ncp_base_ftd.cpp | 20 +- src/ncp/ncp_base_mtd.cpp | 126 +++++----- src/ncp/ncp_base_radio.cpp | 10 +- src/ncp/ncp_spi.cpp | 6 +- src/ncp/ncp_uart.cpp | 8 +- src/posix/client.cpp | 6 +- src/posix/console_cli.cpp | 4 +- src/posix/platform/alarm.cpp | 2 +- src/posix/platform/entropy.cpp | 8 +- src/posix/platform/hdlc_interface.cpp | 18 +- src/posix/platform/netif.cpp | 22 +- src/posix/platform/radio.cpp | 28 +-- src/posix/platform/radio_url.cpp | 22 +- src/posix/platform/radio_url.hpp | 4 +- src/posix/platform/settings.cpp | 20 +- src/posix/platform/spi_interface.cpp | 10 +- src/posix/platform/system.cpp | 8 +- src/posix/platform/uart.cpp | 20 +- src/posix/platform/udp.cpp | 30 +-- src/posix/platform/virtual_time.cpp | 2 +- tests/fuzz/cli_uart_received.cpp | 8 +- tests/fuzz/fuzzer_platform.cpp | 2 +- tests/fuzz/ip6_send.cpp | 12 +- tests/fuzz/ncp_uart_received.cpp | 8 +- tests/fuzz/radio_receive_done.cpp | 8 +- tests/unit/CMakeLists.txt | 6 + tests/unit/test_aes.cpp | 2 +- tests/unit/test_child.cpp | 8 +- tests/unit/test_child_table.cpp | 34 +-- tests/unit/test_flash.cpp | 10 +- tests/unit/test_hdlc.cpp | 34 +-- tests/unit/test_heap.cpp | 10 +- tests/unit/test_hmac_sha256.cpp | 8 +- tests/unit/test_link_quality.cpp | 2 +- tests/unit/test_linked_list.cpp | 60 ++--- tests/unit/test_lowpan.cpp | 14 +- tests/unit/test_mac_frame.cpp | 6 +- tests/unit/test_message.cpp | 4 +- tests/unit/test_message_queue.cpp | 27 ++- tests/unit/test_netif.cpp | 2 +- tests/unit/test_network_data.cpp | 2 +- tests/unit/test_platform.cpp | 38 +-- tests/unit/test_priority_queue.cpp | 55 ++--- tests/unit/test_spinel_buffer.cpp | 20 +- tests/unit/test_timer.cpp | 2 +- 209 files changed, 1981 insertions(+), 1906 deletions(-) diff --git a/Android.mk b/Android.mk index 6b22e961f..1bdeffa65 100644 --- a/Android.mk +++ b/Android.mk @@ -493,6 +493,12 @@ include $(CLEAR_VARS) LOCAL_MODULE := ot-ctl LOCAL_MODULE_TAGS := eng +LOCAL_CPPFLAGS := \ + -std=c++11 \ + -pedantic-errors \ + -Wno-non-virtual-dtor \ + $(NULL) + LOCAL_CFLAGS := \ -DOPENTHREAD_CONFIG_FILE=\ \ $(NULL) diff --git a/examples/platforms/cc1352/CMakeLists.txt b/examples/platforms/cc1352/CMakeLists.txt index 4a7031835..6ab6c1364 100644 --- a/examples/platforms/cc1352/CMakeLists.txt +++ b/examples/platforms/cc1352/CMakeLists.txt @@ -64,7 +64,12 @@ add_library(openthread-cc1352 cxx_helpers.c ) -set_property(TARGET openthread-cc1352 PROPERTY C_STANDARD 99) +set_target_properties( + openthread-cc1352 + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) target_link_libraries(openthread-cc1352 PUBLIC diff --git a/examples/platforms/cc2538/CMakeLists.txt b/examples/platforms/cc2538/CMakeLists.txt index 7c2c50f6e..f33848a8d 100644 --- a/examples/platforms/cc2538/CMakeLists.txt +++ b/examples/platforms/cc2538/CMakeLists.txt @@ -55,7 +55,12 @@ add_library(openthread-cc2538 $ ) -set_property(TARGET openthread-cc2538 PROPERTY C_STANDARD 99) +set_target_properties( + openthread-cc2538 + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) target_link_libraries(openthread-cc2538 PRIVATE openthread-platform-utils ot-config) target_link_options(openthread-cc2538 PUBLIC -T${PROJECT_SOURCE_DIR}/examples/platforms/cc2538/cc2538.ld) diff --git a/examples/platforms/cc2650/CMakeLists.txt b/examples/platforms/cc2650/CMakeLists.txt index 202730df1..84d7cf063 100644 --- a/examples/platforms/cc2650/CMakeLists.txt +++ b/examples/platforms/cc2650/CMakeLists.txt @@ -64,7 +64,12 @@ add_library(openthread-cc2650 $ ) -set_property(TARGET openthread-cc2650 PROPERTY C_STANDARD 99) +set_target_properties( + openthread-cc2650 + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) target_link_libraries(openthread-cc2650 PUBLIC diff --git a/examples/platforms/cc2652/CMakeLists.txt b/examples/platforms/cc2652/CMakeLists.txt index 98f03195e..ddd4e24cf 100644 --- a/examples/platforms/cc2652/CMakeLists.txt +++ b/examples/platforms/cc2652/CMakeLists.txt @@ -64,7 +64,12 @@ add_library(openthread-cc2652 uart.c ) -set_property(TARGET openthread-cc2652 PROPERTY C_STANDARD 99) +set_target_properties( + openthread-cc2652 + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) target_link_libraries(openthread-cc2652 PUBLIC diff --git a/examples/platforms/kw41z/CMakeLists.txt b/examples/platforms/kw41z/CMakeLists.txt index ac0721e1f..d76e8836a 100644 --- a/examples/platforms/kw41z/CMakeLists.txt +++ b/examples/platforms/kw41z/CMakeLists.txt @@ -52,7 +52,13 @@ add_library(openthread-kw41z uart.c ) -set_property(TARGET openthread-kw41z PROPERTY C_STANDARD 99) +set_target_properties( + openthread-kw41z + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) + target_link_libraries(openthread-kw41z PRIVATE nxp-kw41z-driver ot-config) target_link_options(openthread-kw41z PRIVATE -T${PROJECT_SOURCE_DIR}/examples/platforms/kw41z/MKW41Z512xxx4.ld) target_link_options(openthread-kw41z PRIVATE -Wl,--gc-sections -Wl,-Map=$.map) diff --git a/examples/platforms/qpg6095/CMakeLists.txt b/examples/platforms/qpg6095/CMakeLists.txt index cf9ed6f23..2851208d6 100644 --- a/examples/platforms/qpg6095/CMakeLists.txt +++ b/examples/platforms/qpg6095/CMakeLists.txt @@ -67,7 +67,12 @@ add_library(openthread-qpg6095 uart.c ) -set_property(TARGET openthread-qpg6095 PROPERTY C_STANDARD 99) +set_target_properties( + openthread-qpg6095 + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) target_link_libraries(openthread-qpg6095 PRIVATE diff --git a/examples/platforms/qpg6095/settings.cpp b/examples/platforms/qpg6095/settings.cpp index 46e8084b3..a6e4e4459 100644 --- a/examples/platforms/qpg6095/settings.cpp +++ b/examples/platforms/qpg6095/settings.cpp @@ -72,7 +72,7 @@ otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint if (error == OT_ERROR_NOT_FOUND) { - if (aValue != NULL) + if (aValue != nullptr) { *aValueLength = 0; } @@ -110,7 +110,7 @@ otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) otError error = OT_ERROR_NOT_FOUND; OT_UNUSED_VARIABLE(aInstance); - if (otPlatSettingsGet(aInstance, aKey, 0, NULL, NULL) == OT_ERROR_NONE) + if (otPlatSettingsGet(aInstance, aKey, 0, nullptr, nullptr) == OT_ERROR_NONE) { qorvoSettingsDelete(aKey, aIndex); error = OT_ERROR_NONE; diff --git a/examples/platforms/samr21/CMakeLists.txt b/examples/platforms/samr21/CMakeLists.txt index 9355d6c91..48db69fa7 100644 --- a/examples/platforms/samr21/CMakeLists.txt +++ b/examples/platforms/samr21/CMakeLists.txt @@ -60,7 +60,12 @@ add_library(openthread-samr21 uart.c ) -set_property(TARGET openthread-samr21 PROPERTY C_STANDARD 99) +set_target_properties( + openthread-samr21 + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) if(OT_CFLAGS MATCHES "-pedantic-errors") string(REPLACE "-pedantic-errors" "" OT_CFLAGS "${OT_CFLAGS}") diff --git a/examples/platforms/simulation/CMakeLists.txt b/examples/platforms/simulation/CMakeLists.txt index a0303a0ae..571825707 100644 --- a/examples/platforms/simulation/CMakeLists.txt +++ b/examples/platforms/simulation/CMakeLists.txt @@ -71,7 +71,12 @@ add_library(openthread-simulation $ ) -set_property(TARGET openthread-simulation PROPERTY C_STANDARD 99) +set_target_properties( + openthread-simulation + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) find_library(LIBRT rt) if(LIBRT) diff --git a/examples/platforms/utils/CMakeLists.txt b/examples/platforms/utils/CMakeLists.txt index 7ce733ca8..4f84c600d 100644 --- a/examples/platforms/utils/CMakeLists.txt +++ b/examples/platforms/utils/CMakeLists.txt @@ -34,6 +34,13 @@ add_library(openthread-platform-utils OBJECT soft_source_match_table.c ) +set_target_properties( + openthread-platform-utils + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) + target_include_directories(openthread-platform-utils PRIVATE ${OT_PUBLIC_INCLUDES} ${PROJECT_SOURCE_DIR}/examples/platforms diff --git a/examples/platforms/utils/mac_frame.cpp b/examples/platforms/utils/mac_frame.cpp index 8a9c932a8..fe81247a2 100644 --- a/examples/platforms/utils/mac_frame.cpp +++ b/examples/platforms/utils/mac_frame.cpp @@ -134,7 +134,7 @@ bool otMacFrameIsVersion2015(const otRadioFrame *aFrame) void otMacFrameGenerateImmAck(const otRadioFrame *aFrame, bool aIsFramePending, otRadioFrame *aAckFrame) { - assert(aFrame != NULL && aAckFrame != NULL); + assert(aFrame != nullptr && aAckFrame != nullptr); static_cast(aAckFrame)->GenerateImmAck(*static_cast(aFrame), aIsFramePending); } @@ -146,7 +146,7 @@ otError otMacFrameGenerateEnhAck(const otRadioFrame *aFrame, uint8_t aIeLength, otRadioFrame * aAckFrame) { - assert(aFrame != NULL && aAckFrame != NULL); + assert(aFrame != nullptr && aAckFrame != nullptr); return static_cast(aAckFrame)->GenerateEnhAck(*static_cast(aFrame), aIsFramePending, aIeData, aIeLength); diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 2daa1cc07..8f030ac4c 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -250,9 +250,9 @@ const struct Command Interpreter::sCommands[] = { }; Interpreter::Interpreter(Instance *aInstance) - : mUserCommands(NULL) + : mUserCommands(nullptr) , mUserCommandsLength(0) - , mServer(NULL) + , mServer(nullptr) , mPingLength(kDefaultPingLength) , mPingCount(kDefaultPingCount) , mPingInterval(kDefaultPingInterval) @@ -625,7 +625,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) { const otIp6InterfaceIdentifier *iid = otThreadGetFixedDuaInterfaceIdentifier(mInstance); - if (iid != NULL) + if (iid != nullptr) { OutputBytes(iid->m8, sizeof(otIp6InterfaceIdentifier)); mServer->OutputFormat("\r\n"); @@ -635,7 +635,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) case 2: if (strcmp(aArgs[1], "clear") == 0) { - SuccessOrExit(error = otThreadSetFixedDuaInterfaceIdentifier(mInstance, NULL)); + SuccessOrExit(error = otThreadSetFixedDuaInterfaceIdentifier(mInstance, nullptr)); } else { @@ -1353,7 +1353,7 @@ void Interpreter::HandleDnsResponse(const char *aHostname, const Ip6::Address *a if (aResult == OT_ERROR_NONE) { - if (aAddress != NULL) + if (aAddress != nullptr) { OutputIp6Address(*aAddress); } @@ -2050,12 +2050,12 @@ void Interpreter::ProcessNetif(uint8_t aArgsLength, char *aArgs[]) OT_UNUSED_VARIABLE(aArgs); otError error = OT_ERROR_NONE; - const char * netif = NULL; + const char * netif = nullptr; unsigned int netifidx = 0; SuccessOrExit(error = otPlatGetNetif(mInstance, &netif, &netifidx)); - mServer->OutputFormat("%s:%u\r\n", netif ? netif : "", netifidx); + mServer->OutputFormat("%s:%u\r\n", netif ? netif : "(null)", netifidx); exit: AppendResult(error); @@ -2415,7 +2415,7 @@ void Interpreter::HandlePingTimer(Timer &aTimer) void Interpreter::SendPing(void) { uint32_t timestamp = HostSwap32(TimerMilli::GetNow().GetValue()); - otMessage * message = NULL; + otMessage * message = nullptr; otMessageInfo messageInfo; memset(&messageInfo, 0, sizeof(messageInfo)); @@ -2423,8 +2423,8 @@ void Interpreter::SendPing(void) messageInfo.mHopLimit = mPingHopLimit; messageInfo.mAllowZeroHopLimit = mPingAllowZeroHopLimit; - message = otIp6NewMessage(mInstance, NULL); - VerifyOrExit(message != NULL, OT_NOOP); + message = otIp6NewMessage(mInstance, nullptr); + VerifyOrExit(message != nullptr, OT_NOOP); SuccessOrExit(otMessageAppend(message, ×tamp, sizeof(timestamp))); SuccessOrExit(otMessageSetLength(message, mPingLength)); @@ -2433,10 +2433,10 @@ void Interpreter::SendPing(void) SignalPingRequest(static_cast(&messageInfo)->GetPeerAddr(), mPingLength, HostSwap32(timestamp), messageInfo.mHopLimit); - message = NULL; + message = nullptr; exit: - if (message != NULL) + if (message != nullptr) { otMessageFree(message); } @@ -2490,7 +2490,7 @@ void Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) } else if (strcmp(aArgs[0], "disable") == 0) { - otLinkSetPcapCallback(mInstance, NULL, NULL); + otLinkSetPcapCallback(mInstance, nullptr, nullptr); SuccessOrExit(error = otLinkSetPromiscuous(mInstance, false)); } else @@ -2588,7 +2588,7 @@ otError Interpreter::ProcessPrefixAdd(uint8_t aArgsLength, char *aArgs[]) memset(&config, 0, sizeof(otBorderRouterConfig)); - if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == NULL) + if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == nullptr) { ExitNow(); } @@ -2689,7 +2689,7 @@ otError Interpreter::ProcessPrefixRemove(uint8_t aArgsLength, char *aArgs[]) memset(&prefix, 0, sizeof(otIp6Prefix)); - if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == NULL) + if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == nullptr) { ExitNow(); } @@ -2912,7 +2912,7 @@ otError Interpreter::ProcessRouteAdd(uint8_t aArgsLength, char *aArgs[]) VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS); - if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == NULL) + if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == nullptr) { ExitNow(); } @@ -2971,7 +2971,7 @@ otError Interpreter::ProcessRouteRemove(uint8_t aArgsLength, char *aArgs[]) VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS); - if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == NULL) + if ((prefixLengthStr = strchr(aArgs[argcur], '/')) == nullptr) { ExitNow(); } @@ -3300,7 +3300,7 @@ void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult, void *aCon void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult) { - if (aResult == NULL) + if (aResult == nullptr) { AppendResult(OT_ERROR_NONE); ExitNow(); @@ -3331,7 +3331,7 @@ void Interpreter::HandleEnergyScanResult(otEnergyScanResult *aResult, void *aCon void Interpreter::HandleEnergyScanResult(otEnergyScanResult *aResult) { - if (aResult == NULL) + if (aResult == nullptr) { AppendResult(OT_ERROR_NONE); ExitNow(); @@ -3857,7 +3857,7 @@ otError Interpreter::ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]) if (strcmp(aArgs[1], "*") == 0) { - SuccessOrExit(error = otLinkFilterAddRssIn(mInstance, NULL, rss)); + SuccessOrExit(error = otLinkFilterAddRssIn(mInstance, nullptr, rss)); } else { @@ -3875,7 +3875,7 @@ otError Interpreter::ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]) if (strcmp(aArgs[1], "*") == 0) { - SuccessOrExit(error = otLinkFilterAddRssIn(mInstance, NULL, rss)); + SuccessOrExit(error = otLinkFilterAddRssIn(mInstance, nullptr, rss)); } else { @@ -3891,7 +3891,7 @@ otError Interpreter::ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]) if (strcmp(aArgs[1], "*") == 0) { - SuccessOrExit(error = otLinkFilterRemoveRssIn(mInstance, NULL)); + SuccessOrExit(error = otLinkFilterRemoveRssIn(mInstance, nullptr)); } else { @@ -4003,14 +4003,14 @@ void Interpreter::ProcessDiag(uint8_t aArgsLength, char *aArgs[]) void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer) { - char * aArgs[kMaxArgs] = {NULL}; + char * aArgs[kMaxArgs] = {nullptr}; char * cmd; uint8_t aArgsLength = 0; size_t i = 0; mServer = &aServer; - VerifyOrExit(aBuf != NULL && StringLength(aBuf, aBufLength + 1) <= aBufLength, OT_NOOP); + VerifyOrExit(aBuf != nullptr && StringLength(aBuf, aBufLength + 1) <= aBufLength, OT_NOOP); VerifyOrExit(Utils::CmdLineParser::ParseCmd(aBuf, aArgsLength, aArgs, kMaxArgs) == OT_ERROR_NONE, mServer->OutputFormat("Error: too many args (max %d)\r\n", kMaxArgs)); @@ -4448,7 +4448,7 @@ extern "C" void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, cons OT_UNUSED_VARIABLE(aLogLevel); OT_UNUSED_VARIABLE(aLogRegion); - VerifyOrExit(Server::sServer != NULL, OT_NOOP); + VerifyOrExit(Server::sServer != nullptr, OT_NOOP); Server::sServer->OutputFormatV(aFormat, aArgs); Server::sServer->OutputFormat("\r\n"); diff --git a/src/cli/cli_coap.cpp b/src/cli/cli_coap.cpp index 8812eef8d..635067c2e 100644 --- a/src/cli/cli_coap.cpp +++ b/src/cli/cli_coap.cpp @@ -90,7 +90,7 @@ Coap::Coap(Interpreter &aInterpreter) otError Coap::CancelResourceSubscription(void) { otError error = OT_ERROR_NONE; - otMessage * message = NULL; + otMessage * message = nullptr; otMessageInfo messageInfo; memset(&messageInfo, 0, sizeof(messageInfo)); @@ -99,8 +99,8 @@ otError Coap::CancelResourceSubscription(void) VerifyOrExit(mRequestTokenLength != 0, error = OT_ERROR_INVALID_STATE); - message = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + message = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); otCoapMessageInit(message, OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_GET); @@ -116,7 +116,7 @@ otError Coap::CancelResourceSubscription(void) exit: - if ((error != OT_ERROR_NONE) && (message != NULL)) + if ((error != OT_ERROR_NONE) && (message != nullptr)) { otMessageFree(message); } @@ -207,7 +207,7 @@ exit: otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[]) { #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE - otMessage * notificationMessage = NULL; + otMessage * notificationMessage = nullptr; otMessageInfo messageInfo; #endif otError error = OT_ERROR_NONE; @@ -229,8 +229,8 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[]) mInterpreter.OutputIp6Address(mSubscriberSock.mAddress); mInterpreter.mServer->OutputFormat("\r\n"); - notificationMessage = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(notificationMessage != NULL, error = OT_ERROR_NO_BUFS); + notificationMessage = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(notificationMessage != nullptr, error = OT_ERROR_NO_BUFS); otCoapMessageInit( notificationMessage, @@ -256,7 +256,7 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[]) exit: #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE - if ((error != OT_ERROR_NONE) && (notificationMessage != NULL)) + if ((error != OT_ERROR_NONE) && (notificationMessage != nullptr)) { otMessageFree(notificationMessage); } @@ -359,7 +359,7 @@ exit: otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[]) { otError error = OT_ERROR_NONE; - otMessage * message = NULL; + otMessage * message = nullptr; otMessageInfo messageInfo; uint16_t payloadLength = 0; @@ -442,8 +442,8 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[]) } #endif - message = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + message = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); otCoapMessageInit(message, coapType, coapCode); otCoapMessageGenerateToken(message, ot::Coap::Message::kDefaultTokenLength); @@ -496,13 +496,13 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[]) } else { - error = otCoapSendRequestWithParameters(mInterpreter.mInstance, message, &messageInfo, NULL, NULL, + error = otCoapSendRequestWithParameters(mInterpreter.mInstance, message, &messageInfo, nullptr, nullptr, GetResponseTxParameters()); } exit: - if ((error != OT_ERROR_NONE) && (message != NULL)) + if ((error != OT_ERROR_NONE) && (message != nullptr)) { otMessageFree(message); } @@ -516,7 +516,7 @@ otError Coap::Process(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength < 1) { - IgnoreError(ProcessHelp(0, NULL)); + IgnoreError(ProcessHelp(0, nullptr)); error = OT_ERROR_INVALID_ARGS; } else @@ -542,7 +542,7 @@ void Coap::HandleRequest(void *aContext, otMessage *aMessage, const otMessageInf void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) { otError error = OT_ERROR_NONE; - otMessage *responseMessage = NULL; + otMessage *responseMessage = nullptr; otCoapCode responseCode = OT_COAP_CODE_EMPTY; #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE uint64_t observe = 0; @@ -560,7 +560,7 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) mInterpreter.mServer->OutputFormat("GET"); #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE SuccessOrExit(error = otCoapOptionIteratorInit(&iterator, aMessage)); - if (otCoapOptionIteratorGetFirstOptionMatching(&iterator, OT_COAP_OPTION_OBSERVE) != NULL) + if (otCoapOptionIteratorGetFirstOptionMatching(&iterator, OT_COAP_OPTION_OBSERVE) != nullptr) { SuccessOrExit(error = otCoapOptionIteratorGetOptionUintValue(&iterator, &observe)); observePresent = true; @@ -643,8 +643,8 @@ void Coap::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) responseCode = OT_COAP_CODE_VALID; } - responseMessage = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(responseMessage != NULL, error = OT_ERROR_NO_BUFS); + responseMessage = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(responseMessage != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit( error = otCoapMessageInitResponse(responseMessage, aMessage, OT_COAP_TYPE_ACKNOWLEDGMENT, responseCode)); @@ -670,7 +670,7 @@ exit: if (error != OT_ERROR_NONE) { - if (responseMessage != NULL) + if (responseMessage != nullptr) { mInterpreter.mServer->OutputFormat("coap send response error %d: %s\r\n", error, otThreadErrorToString(error)); @@ -699,7 +699,7 @@ void Coap::HandleNotificationResponse(otMessage *aMessage, const otMessageInfo * switch (aError) { case OT_ERROR_NONE: - if (aMessageInfo != NULL) + if (aMessageInfo != nullptr) { mInterpreter.mServer->OutputFormat("Received ACK in reply to notification from "); mInterpreter.OutputIp6Address(aMessageInfo->mPeerAddr); @@ -728,7 +728,7 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo mInterpreter.mServer->OutputFormat("coap receive response error %d: %s\r\n", aError, otThreadErrorToString(aError)); } - else if ((aMessageInfo != NULL) && (aMessage != NULL)) + else if ((aMessageInfo != nullptr) && (aMessage != nullptr)) { #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE otCoapOptionIterator iterator; @@ -743,7 +743,7 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo const otCoapOption *observeOpt = otCoapOptionIteratorGetFirstOptionMatching(&iterator, OT_COAP_OPTION_OBSERVE); - if (observeOpt != NULL) + if (observeOpt != nullptr) { uint64_t observeVal = 0; otError error = otCoapOptionIteratorGetOptionUintValue(&iterator, &observeVal); diff --git a/src/cli/cli_coap.hpp b/src/cli/cli_coap.hpp index e9b39acfa..a406683b5 100644 --- a/src/cli/cli_coap.hpp +++ b/src/cli/cli_coap.hpp @@ -116,12 +116,12 @@ private: const otCoapTxParameters *GetRequestTxParameters(void) const { - return mUseDefaultRequestTxParameters ? NULL : &mRequestTxParameters; + return mUseDefaultRequestTxParameters ? nullptr : &mRequestTxParameters; } const otCoapTxParameters *GetResponseTxParameters(void) const { - return mUseDefaultResponseTxParameters ? NULL : &mResponseTxParameters; + return mUseDefaultResponseTxParameters ? nullptr : &mResponseTxParameters; } static const Command sCommands[]; diff --git a/src/cli/cli_coap_secure.cpp b/src/cli/cli_coap_secure.cpp index 4a5fcc623..1fe87c471 100644 --- a/src/cli/cli_coap_secure.cpp +++ b/src/cli/cli_coap_secure.cpp @@ -188,7 +188,7 @@ otError CoapSecure::ProcessStop(uint8_t aArgsLength, char *aArgs[]) otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[]) { otError error = OT_ERROR_NONE; - otMessage * message = NULL; + otMessage * message = nullptr; otMessageInfo messageInfo; uint16_t payloadLength = 0; uint8_t indexShifter = 0; @@ -259,8 +259,8 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[]) } } - message = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + message = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); otCoapMessageInit(message, coapType, coapCode); otCoapMessageGenerateToken(message, ot::Coap::Message::kDefaultTokenLength); @@ -292,12 +292,12 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[]) } else { - error = otCoapSecureSendRequest(mInterpreter.mInstance, message, NULL, NULL); + error = otCoapSecureSendRequest(mInterpreter.mInstance, message, nullptr, nullptr); } exit: - if ((error != OT_ERROR_NONE) && (message != NULL)) + if ((error != OT_ERROR_NONE) && (message != nullptr)) { otMessageFree(message); } @@ -393,7 +393,7 @@ otError CoapSecure::Process(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength < 1) { - IgnoreError(ProcessHelp(0, NULL)); + IgnoreError(ProcessHelp(0, nullptr)); error = OT_ERROR_INVALID_ARGS; } else @@ -448,7 +448,7 @@ void CoapSecure::HandleRequest(void *aContext, otMessage *aMessage, const otMess void CoapSecure::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo) { otError error = OT_ERROR_NONE; - otMessage *responseMessage = NULL; + otMessage *responseMessage = nullptr; otCoapCode responseCode = OT_COAP_CODE_EMPTY; char responseContent[] = "helloWorld"; @@ -493,8 +493,8 @@ void CoapSecure::HandleRequest(otMessage *aMessage, const otMessageInfo *aMessag responseCode = OT_COAP_CODE_VALID; } - responseMessage = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(responseMessage != NULL, error = OT_ERROR_NO_BUFS); + responseMessage = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(responseMessage != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit( error = otCoapMessageInitResponse(responseMessage, aMessage, OT_COAP_TYPE_ACKNOWLEDGMENT, responseCode)); @@ -516,7 +516,7 @@ exit: if (error != OT_ERROR_NONE) { - if (responseMessage != NULL) + if (responseMessage != nullptr) { mInterpreter.mServer->OutputFormat("coaps send response error %d: %s\r\n", error, otThreadErrorToString(error)); @@ -561,13 +561,13 @@ void CoapSecure::DefaultHandler(void *aContext, otMessage *aMessage, const otMes void CoapSecure::DefaultHandler(otMessage *aMessage, const otMessageInfo *aMessageInfo) { otError error = OT_ERROR_NONE; - otMessage *responseMessage = NULL; + otMessage *responseMessage = nullptr; if ((otCoapMessageGetType(aMessage) == OT_COAP_TYPE_CONFIRMABLE) || (otCoapMessageGetCode(aMessage) == OT_COAP_CODE_GET)) { - responseMessage = otCoapNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(responseMessage != NULL, error = OT_ERROR_NO_BUFS); + responseMessage = otCoapNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(responseMessage != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = otCoapMessageInitResponse(responseMessage, aMessage, OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_NOT_FOUND)); @@ -576,7 +576,7 @@ void CoapSecure::DefaultHandler(otMessage *aMessage, const otMessageInfo *aMessa } exit: - if (error != OT_ERROR_NONE && responseMessage != NULL) + if (error != OT_ERROR_NONE && responseMessage != nullptr) { otMessageFree(responseMessage); } diff --git a/src/cli/cli_commissioner.cpp b/src/cli/cli_commissioner.cpp index d11497350..c90128314 100644 --- a/src/cli/cli_commissioner.cpp +++ b/src/cli/cli_commissioner.cpp @@ -122,7 +122,7 @@ otError Commissioner::ProcessJoiner(uint8_t aArgsLength, char *aArgs[]) if (strcmp(aArgs[2], "*") == 0) { - addrPtr = NULL; + addrPtr = nullptr; } else { @@ -300,7 +300,7 @@ exit: otError Commissioner::ProcessProvisioningUrl(uint8_t aArgsLength, char *aArgs[]) { - return otCommissionerSetProvisioningUrl(mInterpreter.mInstance, (aArgsLength > 1) ? aArgs[1] : NULL); + return otCommissionerSetProvisioningUrl(mInterpreter.mInstance, (aArgsLength > 1) ? aArgs[1] : nullptr); } otError Commissioner::ProcessSessionId(uint8_t aArgsLength, char *aArgs[]) @@ -392,7 +392,7 @@ otError Commissioner::Process(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength < 1) { - IgnoreError(ProcessHelp(0, NULL)); + IgnoreError(ProcessHelp(0, nullptr)); } else { diff --git a/src/cli/cli_console.cpp b/src/cli/cli_console.cpp index e2da74ad8..97fdcbd32 100644 --- a/src/cli/cli_console.cpp +++ b/src/cli/cli_console.cpp @@ -62,8 +62,8 @@ extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength) Console::Console(Instance *aInstance) : Server(aInstance) - , mCallback(NULL) - , mContext(NULL) + , mCallback(nullptr) + , mContext(nullptr) { } diff --git a/src/cli/cli_dataset.cpp b/src/cli/cli_dataset.cpp index 040eefe87..2d4fed70c 100644 --- a/src/cli/cli_dataset.cpp +++ b/src/cli/cli_dataset.cpp @@ -690,13 +690,13 @@ otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, char *aArgs[]) { SuccessOrExit(error = otDatasetSendMgmtActiveGet(mInterpreter.mInstance, &datasetComponents, tlvs, static_cast(length), - destAddrSpecified ? &address : NULL)); + destAddrSpecified ? &address : nullptr)); } else if (strcmp(aArgs[0], "pending") == 0) { SuccessOrExit(error = otDatasetSendMgmtPendingGet(mInterpreter.mInstance, &datasetComponents, tlvs, static_cast(length), - destAddrSpecified ? &address : NULL)); + destAddrSpecified ? &address : nullptr)); } else { diff --git a/src/cli/cli_joiner.cpp b/src/cli/cli_joiner.cpp index f37ed928d..f44cf1199 100644 --- a/src/cli/cli_joiner.cpp +++ b/src/cli/cli_joiner.cpp @@ -79,7 +79,7 @@ otError Joiner::ProcessId(uint8_t aArgsLength, char *aArgs[]) otError Joiner::ProcessStart(uint8_t aArgsLength, char *aArgs[]) { otError error; - const char *provisioningUrl = NULL; + const char *provisioningUrl = nullptr; VerifyOrExit(aArgsLength > 1, error = OT_ERROR_INVALID_ARGS); @@ -89,7 +89,7 @@ otError Joiner::ProcessStart(uint8_t aArgsLength, char *aArgs[]) } error = otJoinerStart(mInterpreter.mInstance, aArgs[1], provisioningUrl, PACKAGE_NAME, - OPENTHREAD_CONFIG_PLATFORM_INFO, PACKAGE_VERSION, NULL, &Joiner::HandleCallback, this); + OPENTHREAD_CONFIG_PLATFORM_INFO, PACKAGE_VERSION, nullptr, &Joiner::HandleCallback, this); exit: return error; @@ -111,7 +111,7 @@ otError Joiner::Process(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength < 1) { - IgnoreError(ProcessHelp(0, NULL)); + IgnoreError(ProcessHelp(0, nullptr)); } else { diff --git a/src/cli/cli_server.cpp b/src/cli/cli_server.cpp index a646fe143..0339c1fad 100644 --- a/src/cli/cli_server.cpp +++ b/src/cli/cli_server.cpp @@ -36,7 +36,7 @@ namespace ot { namespace Cli { -Server *Server::sServer = NULL; +Server *Server::sServer = nullptr; int Server::OutputFormat(const char *aFormat, ...) { diff --git a/src/cli/cli_udp.cpp b/src/cli/cli_udp.cpp index 292242001..24bdbe5df 100644 --- a/src/cli/cli_udp.cpp +++ b/src/cli/cli_udp.cpp @@ -136,7 +136,7 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[]) { otError error = OT_ERROR_NONE; otMessageInfo messageInfo; - otMessage * message = NULL; + otMessage * message = nullptr; uint8_t curArg = 0; uint16_t payloadLength = 0; PayloadType payloadType = kTypeText; @@ -179,8 +179,8 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[]) } } - message = otUdpNewMessage(mInterpreter.mInstance, NULL); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + message = otUdpNewMessage(mInterpreter.mInstance, nullptr); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); switch (payloadType) { @@ -222,7 +222,7 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[]) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { otMessageFree(message); } @@ -264,7 +264,7 @@ otError UdpExample::Process(uint8_t aArgsLength, char *aArgs[]) if (aArgsLength < 1) { - IgnoreError(ProcessHelp(0, NULL)); + IgnoreError(ProcessHelp(0, nullptr)); error = OT_ERROR_INVALID_ARGS; } else diff --git a/src/core/api/backbone_router_api.cpp b/src/core/api/backbone_router_api.cpp index 033000e5a..a27a621de 100644 --- a/src/core/api/backbone_router_api.cpp +++ b/src/core/api/backbone_router_api.cpp @@ -43,7 +43,7 @@ otError otBackboneRouterGetPrimary(otInstance *aInstance, otBackboneRouterConfig { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aConfig != NULL); + OT_ASSERT(aConfig != nullptr); return instance.Get().GetConfig(*aConfig); } diff --git a/src/core/api/backbone_router_ftd_api.cpp b/src/core/api/backbone_router_ftd_api.cpp index 7477d8f58..71032493e 100644 --- a/src/core/api/backbone_router_ftd_api.cpp +++ b/src/core/api/backbone_router_ftd_api.cpp @@ -59,7 +59,7 @@ void otBackboneRouterGetConfig(otInstance *aInstance, otBackboneRouterConfig *aC { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aConfig != NULL); + OT_ASSERT(aConfig != nullptr); instance.Get().GetConfig(*aConfig); } @@ -68,7 +68,7 @@ void otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterConf { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aConfig != NULL); + OT_ASSERT(aConfig != nullptr); instance.Get().SetConfig(*aConfig); } @@ -105,7 +105,7 @@ otError otBackboneRouterGetDomainPrefix(otInstance *aInstance, otBorderRouterCon { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aConfig != NULL); + OT_ASSERT(aConfig != nullptr); return instance.Get().GetDomainPrefix(*aConfig); } diff --git a/src/core/api/border_router_api.cpp b/src/core/api/border_router_api.cpp index 4832183a3..1a2048dac 100644 --- a/src/core/api/border_router_api.cpp +++ b/src/core/api/border_router_api.cpp @@ -47,7 +47,7 @@ otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *a { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aData != NULL && aDataLength != NULL); + OT_ASSERT(aData != nullptr && aDataLength != nullptr); return instance.Get().GetNetworkData(aStable, aData, *aDataLength); } @@ -57,7 +57,7 @@ otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRoute otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - OT_ASSERT(aConfig != NULL); + OT_ASSERT(aConfig != nullptr); // Add Prefix validation check: // Thread 1.1 Specification 5.13.2 says // "A valid prefix MUST NOT allow both DHCPv6 and SLAAC for address configuration" @@ -85,7 +85,7 @@ otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefi otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - OT_ASSERT(aPrefix != NULL); + OT_ASSERT(aPrefix != nullptr); #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE error = instance.Get().RemoveDomainPrefix(*aPrefix); @@ -105,7 +105,7 @@ otError otBorderRouterGetNextOnMeshPrefix(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aIterator != NULL && aConfig != NULL); + OT_ASSERT(aIterator != nullptr && aConfig != nullptr); return instance.Get().GetNextOnMeshPrefix(*aIterator, *aConfig); } @@ -114,7 +114,7 @@ otError otBorderRouterAddRoute(otInstance *aInstance, const otExternalRouteConfi { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aConfig != NULL); + OT_ASSERT(aConfig != nullptr); return instance.Get().AddHasRoutePrefix( aConfig->mPrefix.mPrefix.mFields.m8, aConfig->mPrefix.mLength, aConfig->mPreference, aConfig->mStable); @@ -124,7 +124,7 @@ otError otBorderRouterRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPre { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aPrefix != NULL); + OT_ASSERT(aPrefix != nullptr); return instance.Get().RemoveHasRoutePrefix(aPrefix->mPrefix.mFields.m8, aPrefix->mLength); } @@ -135,7 +135,7 @@ otError otBorderRouterGetNextRoute(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aIterator != NULL && aConfig != NULL); + OT_ASSERT(aIterator != nullptr && aConfig != nullptr); return instance.Get().GetNextExternalRoute(*aIterator, *aConfig); } diff --git a/src/core/api/coap_api.cpp b/src/core/api/coap_api.cpp index d0579acb3..a817319ba 100644 --- a/src/core/api/coap_api.cpp +++ b/src/core/api/coap_api.cpp @@ -213,7 +213,7 @@ otError otCoapSendRequestWithParameters(otInstance * aInstance, Instance & instance = *static_cast(aInstance); const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters); - if (aTxParameters != NULL) + if (aTxParameters != nullptr) { VerifyOrExit(txParameters.IsValid(), error = OT_ERROR_INVALID_ARGS); } @@ -270,7 +270,7 @@ otError otCoapSendResponseWithParameters(otInstance * aInstance, return instance.GetApplicationCoap().SendMessage(*static_cast(aMessage), *static_cast(aMessageInfo), - Coap::TxParameters::From(aTxParameters), NULL, NULL); + Coap::TxParameters::From(aTxParameters), nullptr, nullptr); } #endif // OPENTHREAD_CONFIG_COAP_API_ENABLE diff --git a/src/core/api/coap_secure_api.cpp b/src/core/api/coap_secure_api.cpp index 7139fa728..942bc7851 100644 --- a/src/core/api/coap_secure_api.cpp +++ b/src/core/api/coap_secure_api.cpp @@ -61,7 +61,7 @@ void otCoapSecureSetCertificate(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aX509Cert != NULL && aX509Length != 0 && aPrivateKey != NULL && aPrivateKeyLength != 0); + OT_ASSERT(aX509Cert != nullptr && aX509Length != 0 && aPrivateKey != nullptr && aPrivateKeyLength != 0); instance.GetApplicationCoapSecure().SetCertificate(aX509Cert, aX509Length, aPrivateKey, aPrivateKeyLength); } @@ -72,7 +72,7 @@ void otCoapSecureSetCaCertificateChain(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aX509CaCertificateChain != NULL && aX509CaCertChainLength != 0); + OT_ASSERT(aX509CaCertificateChain != nullptr && aX509CaCertChainLength != 0); instance.GetApplicationCoapSecure().SetCaCertificateChain(aX509CaCertificateChain, aX509CaCertChainLength); } @@ -87,7 +87,7 @@ void otCoapSecureSetPsk(otInstance * aInstance, { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aPsk != NULL && aPskLength != 0 && aPskIdentity != NULL && aPskIdLength != 0); + OT_ASSERT(aPsk != nullptr && aPskLength != 0 && aPskIdentity != nullptr && aPskIdLength != 0); instance.GetApplicationCoapSecure().SetPreSharedKey(aPsk, aPskLength, aPskIdentity, aPskIdLength); } diff --git a/src/core/api/crypto_api.cpp b/src/core/api/crypto_api.cpp index 3bdacce6c..9023a4b1c 100644 --- a/src/core/api/crypto_api.cpp +++ b/src/core/api/crypto_api.cpp @@ -52,7 +52,7 @@ void otCryptoHmacSha256(const uint8_t *aKey, { HmacSha256 hmac; - OT_ASSERT((aKey != NULL) && (aBuf != NULL) && (aHash != NULL)); + OT_ASSERT((aKey != nullptr) && (aBuf != nullptr) && (aHash != nullptr)); hmac.Start(aKey, aKeyLength); hmac.Update(aBuf, aBufLength); @@ -74,14 +74,15 @@ void otCryptoAesCcm(const uint8_t *aKey, { AesCcm aesCcm; - OT_ASSERT((aKey != NULL) && (aNonce != NULL) && (aPlainText != NULL) && (aCipherText != NULL) && (aTag != NULL)); + OT_ASSERT((aKey != nullptr) && (aNonce != nullptr) && (aPlainText != nullptr) && (aCipherText != nullptr) && + (aTag != nullptr)); aesCcm.SetKey(aKey, aKeyLength); aesCcm.Init(aHeaderLength, aLength, aTagLength, aNonce, aNonceLength); if (aHeaderLength != 0) { - OT_ASSERT(aHeader != NULL); + OT_ASSERT(aHeader != nullptr); aesCcm.Header(aHeader, aHeaderLength); } diff --git a/src/core/api/dataset_api.cpp b/src/core/api/dataset_api.cpp index b96df62ac..a55812e27 100644 --- a/src/core/api/dataset_api.cpp +++ b/src/core/api/dataset_api.cpp @@ -61,7 +61,7 @@ otError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Read(*aDataset); } @@ -70,7 +70,7 @@ otError otDatasetGetActiveTlvs(otInstance *aInstance, otOperationalDatasetTlvs * { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Read(*aDataset); } @@ -79,7 +79,7 @@ otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aD { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Save(*aDataset); } @@ -88,7 +88,7 @@ otError otDatasetSetActiveTlvs(otInstance *aInstance, const otOperationalDataset { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Save(*aDataset); } @@ -97,7 +97,7 @@ otError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDatase { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Read(*aDataset); } @@ -106,7 +106,7 @@ otError otDatasetGetPendingTlvs(otInstance *aInstance, otOperationalDatasetTlvs { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Read(*aDataset); } @@ -115,7 +115,7 @@ otError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *a { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Save(*aDataset); } @@ -124,7 +124,7 @@ otError otDatasetSetPendingTlvs(otInstance *aInstance, const otOperationalDatase { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aDataset != NULL); + OT_ASSERT(aDataset != nullptr); return instance.Get().Save(*aDataset); } diff --git a/src/core/api/heap_api.cpp b/src/core/api/heap_api.cpp index 0cd96fee3..d921954ca 100644 --- a/src/core/api/heap_api.cpp +++ b/src/core/api/heap_api.cpp @@ -50,7 +50,7 @@ void *otHeapCAlloc(size_t aCount, size_t aSize) OT_ASSERT(false); // This function is reachable when asserts are disabled - OT_UNREACHABLE_CODE(return NULL;) + OT_UNREACHABLE_CODE(return nullptr;) } void otHeapFree(void *aPointer) diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 86b1cd29f..3157b1b67 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -182,7 +182,7 @@ otMessage *otIp6NewMessageFromBuffer(otInstance * aInstance, Instance &instance = *static_cast(aInstance); Message * message; - if (aSettings != NULL) + if (aSettings != nullptr) { message = instance.Get().NewMessage(aData, aDataLength, Message::Settings(aSettings)); } @@ -234,7 +234,7 @@ otError otIp6AddressFromString(const char *aString, otIp6Address *aAddress) uint8_t otIp6PrefixMatch(const otIp6Address *aFirst, const otIp6Address *aSecond) { - OT_ASSERT(aFirst != NULL && aSecond != NULL); + OT_ASSERT(aFirst != nullptr && aSecond != nullptr); return static_cast(aFirst)->PrefixMatch(*static_cast(aSecond)); } @@ -251,7 +251,7 @@ otError otIp6SelectSourceAddress(otInstance *aInstance, otMessageInfo *aMessageI const Ip6::NetifUnicastAddress *netifAddr; netifAddr = instance.Get().SelectSourceAddress(*static_cast(aMessageInfo)); - VerifyOrExit(netifAddr != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(netifAddr != nullptr, error = OT_ERROR_NOT_FOUND); memcpy(&aMessageInfo->mSockAddr, &netifAddr->mAddress, sizeof(aMessageInfo->mSockAddr)); exit: diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index 80f4bee00..700c5ac89 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -116,7 +116,7 @@ otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExt otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - OT_ASSERT(aExtAddress != NULL); + OT_ASSERT(aExtAddress != nullptr); VerifyOrExit(instance.Get().IsDisabled(), error = OT_ERROR_INVALID_STATE); instance.Get().SetExtAddress(*static_cast(aExtAddress)); @@ -236,7 +236,7 @@ otError otLinkFilterAddAddress(otInstance *aInstance, const otExtAddress *aExtAd { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aExtAddress != NULL); + OT_ASSERT(aExtAddress != nullptr); return instance.Get().AddAddress(*static_cast(aExtAddress)); } @@ -245,7 +245,7 @@ otError otLinkFilterRemoveAddress(otInstance *aInstance, const otExtAddress *aEx { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aExtAddress != NULL); + OT_ASSERT(aExtAddress != nullptr); return instance.Get().RemoveAddress(*static_cast(aExtAddress)); } @@ -261,7 +261,7 @@ otError otLinkFilterGetNextAddress(otInstance *aInstance, otMacFilterIterator *a { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aIterator != NULL && aEntry != NULL); + OT_ASSERT(aIterator != nullptr && aEntry != nullptr); return instance.Get().GetNextAddress(*aIterator, *aEntry); } @@ -291,7 +291,7 @@ otError otLinkFilterGetNextRssIn(otInstance *aInstance, otMacFilterIterator *aIt { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aIterator != NULL && aEntry != NULL); + OT_ASSERT(aIterator != nullptr && aEntry != nullptr); return instance.Get().GetNextRssIn(*aIterator, *aEntry); } @@ -322,7 +322,7 @@ const uint32_t *otLinkGetTxDirectRetrySuccessHistogram(otInstance *aInstance, ui const uint32_t *otLinkGetTxIndirectRetrySuccessHistogram(otInstance *aInstance, uint8_t *aNumberOfEntries) { - const uint32_t *histogram = NULL; + const uint32_t *histogram = nullptr; #if OPENTHREAD_FTD Instance &instance = *static_cast(aInstance); diff --git a/src/core/api/message_api.cpp b/src/core/api/message_api.cpp index d02aa097f..52b742842 100644 --- a/src/core/api/message_api.cpp +++ b/src/core/api/message_api.cpp @@ -115,7 +115,7 @@ int otMessageWrite(otMessage *aMessage, uint16_t aOffset, const void *aBuf, uint void otMessageQueueInit(otMessageQueue *aQueue) { - aQueue->mData = NULL; + aQueue->mData = nullptr; } void otMessageQueueEnqueue(otMessageQueue *aQueue, otMessage *aMessage) @@ -152,13 +152,13 @@ otMessage *otMessageQueueGetNext(otMessageQueue *aQueue, const otMessage *aMessa { Message *next; - VerifyOrExit(aMessage != NULL, next = NULL); + VerifyOrExit(aMessage != nullptr, next = nullptr); { const Message &message = *static_cast(aMessage); MessageQueue & queue = *static_cast(aQueue); - VerifyOrExit(message.GetMessageQueue() == &queue, next = NULL); + VerifyOrExit(message.GetMessageQueue() == &queue, next = nullptr); next = message.GetNext(); } diff --git a/src/core/api/netdata_api.cpp b/src/core/api/netdata_api.cpp index 10cf88622..2c49c6cc8 100644 --- a/src/core/api/netdata_api.cpp +++ b/src/core/api/netdata_api.cpp @@ -44,7 +44,7 @@ otError otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_ { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aData != NULL && aDataLength != NULL); + OT_ASSERT(aData != nullptr && aDataLength != nullptr); return instance.Get().GetNetworkData(aStable, aData, *aDataLength); } diff --git a/src/core/api/server_api.cpp b/src/core/api/server_api.cpp index 42391dc56..3d01e1c70 100644 --- a/src/core/api/server_api.cpp +++ b/src/core/api/server_api.cpp @@ -46,7 +46,7 @@ otError otServerGetNetDataLocal(otInstance *aInstance, bool aStable, uint8_t *aD { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aData != NULL && aDataLength != NULL); + OT_ASSERT(aData != nullptr && aDataLength != nullptr); return instance.Get().GetNetworkData(aStable, aData, *aDataLength); } diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 649a3e96e..ca260dee0 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -89,7 +89,7 @@ otError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aLeaderRloc) { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aLeaderRloc != NULL); + OT_ASSERT(aLeaderRloc != nullptr); return instance.Get().GetLeaderAddress(*static_cast(aLeaderRloc)); } @@ -123,7 +123,7 @@ otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey) otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - OT_ASSERT(aKey != NULL); + OT_ASSERT(aKey != nullptr); VerifyOrExit(instance.Get().IsDisabled(), error = OT_ERROR_INVALID_STATE); @@ -243,7 +243,7 @@ otError otThreadSetFixedDuaInterfaceIdentifier(otInstance *aInstance, const otIp const otIp6InterfaceIdentifier *otThreadGetFixedDuaInterfaceIdentifier(otInstance *aInstance) { Instance & instance = *static_cast(aInstance); - const otIp6InterfaceIdentifier *iid = NULL; + const otIp6InterfaceIdentifier *iid = nullptr; if (instance.Get().IsFixedDuaInterfaceIdentifierSet()) { @@ -302,7 +302,7 @@ otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterato { Instance &instance = *static_cast(aInstance); - OT_ASSERT((aInfo != NULL) && (aIterator != NULL)); + OT_ASSERT((aInfo != nullptr) && (aIterator != nullptr)); return instance.Get().GetNextNeighborInfo(*aIterator, *aInfo); } @@ -319,7 +319,7 @@ otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData) Instance &instance = *static_cast(aInstance); otError error = OT_ERROR_NONE; - OT_ASSERT(aLeaderData != NULL); + OT_ASSERT(aLeaderData != nullptr); VerifyOrExit(instance.Get().IsAttached(), error = OT_ERROR_DETACHED); *aLeaderData = instance.Get().GetLeaderData(); @@ -362,7 +362,7 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) otError error = OT_ERROR_NONE; Router * parent; - OT_ASSERT(aParentInfo != NULL); + OT_ASSERT(aParentInfo != nullptr); // Reference device needs get the original parent's info even after the node state changed. #if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE @@ -393,7 +393,7 @@ otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - OT_ASSERT(aParentRssi != NULL); + OT_ASSERT(aParentRssi != nullptr); *aParentRssi = instance.Get().GetParent().GetLinkInfo().GetAverageRss(); @@ -408,7 +408,7 @@ otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi) otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - OT_ASSERT(aLastRssi != NULL); + OT_ASSERT(aLastRssi != nullptr); *aLastRssi = instance.Get().GetParent().GetLinkInfo().GetLastRss(); @@ -459,7 +459,7 @@ otError otThreadDiscover(otInstance * aInstance, return instance.Get().Discover( static_cast(aScanChannels), aPanId, aJoiner, aEnableEui64Filtering, - /* aFilterIndexes (use hash of factory EUI64) */ NULL, aCallback, aCallbackContext); + /* aFilterIndexes (use hash of factory EUI64) */ nullptr, aCallback, aCallbackContext); } bool otThreadIsDiscoverInProgress(otInstance *aInstance) diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index 0440d68c2..738a26580 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -257,7 +257,7 @@ otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChi { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aChildInfo != NULL); + OT_ASSERT(aChildInfo != nullptr); return instance.Get().GetChildInfoById(aChildId, *aChildInfo); } @@ -266,7 +266,7 @@ otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint16_t aChildIndex, { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aChildInfo != NULL); + OT_ASSERT(aChildInfo != nullptr); return instance.Get().GetChildInfoByIndex(aChildIndex, *aChildInfo); } @@ -281,7 +281,7 @@ otError otThreadGetChildNextIp6Address(otInstance * aInstance, Child::Ip6AddressIterator iterator; Ip6::Address * address; - OT_ASSERT(aIterator != NULL && aAddress != NULL); + OT_ASSERT(aIterator != nullptr && aAddress != nullptr); address = static_cast(aAddress); iterator.Set(*aIterator); @@ -311,7 +311,7 @@ otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRoute { Instance &instance = *static_cast(aInstance); - OT_ASSERT(aRouterInfo != NULL); + OT_ASSERT(aRouterInfo != nullptr); return instance.Get().GetRouterInfo(aRouterId, *aRouterInfo); } @@ -320,7 +320,7 @@ otError otThreadGetNextCacheEntry(otInstance *aInstance, otCacheEntryInfo *aEntr { Instance &instance = *static_cast(aInstance); - OT_ASSERT((aIterator != NULL) && (aEntryInfo != NULL)); + OT_ASSERT((aIterator != nullptr) && (aEntryInfo != nullptr)); return instance.Get().GetNextCacheEntry(*aEntryInfo, *aIterator); } diff --git a/src/core/api/udp_api.cpp b/src/core/api/udp_api.cpp index 144dd4c1a..ef527a176 100644 --- a/src/core/api/udp_api.cpp +++ b/src/core/api/udp_api.cpp @@ -105,7 +105,7 @@ void otUdpForwardReceive(otInstance * aInstance, Ip6::MessageInfo messageInfo; Instance & instance = *static_cast(aInstance); - OT_ASSERT(aMessage != NULL && aPeerAddr != NULL); + OT_ASSERT(aMessage != nullptr && aPeerAddr != nullptr); messageInfo.SetSockAddr(instance.Get().GetMeshLocal16()); messageInfo.SetSockPort(aSockPort); diff --git a/src/core/backbone_router/leader.hpp b/src/core/backbone_router/leader.hpp index 65403bb5a..08df80470 100644 --- a/src/core/backbone_router/leader.hpp +++ b/src/core/backbone_router/leader.hpp @@ -139,10 +139,10 @@ public: /** * This method gets the Domain Prefix in the Thread Network. * - * @retval A pointer to the Domain Prefix or NULL if there is no Domain Prefix. + * @retval A pointer to the Domain Prefix or nullptr if there is no Domain Prefix. * */ - const otIp6Prefix *GetDomainPrefix(void) const { return (mDomainPrefix.mLength == 0) ? NULL : &mDomainPrefix; } + const otIp6Prefix *GetDomainPrefix(void) const { return (mDomainPrefix.mLength == 0) ? nullptr : &mDomainPrefix; } /** * This method indicates whether or not the Domain Prefix is available in the Thread Network. diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 42e20c186..4a9370c41 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -52,18 +52,18 @@ CoapBase::CoapBase(Instance &aInstance, Sender aSender) , mMessageId(Random::NonCrypto::GetUint16()) , mRetransmissionTimer(aInstance, Coap::HandleRetransmissionTimer, this) , mResources() - , mContext(NULL) - , mInterceptor(NULL) + , mContext(nullptr) + , mInterceptor(nullptr) , mResponsesQueue(aInstance) - , mDefaultHandler(NULL) - , mDefaultHandlerContext(NULL) + , mDefaultHandler(nullptr) + , mDefaultHandlerContext(nullptr) , mSender(aSender) { } void CoapBase::ClearRequestsAndResponses(void) { - ClearRequests(NULL); // Clear requests matching any address. + ClearRequests(nullptr); // Clear requests matching any address. mResponsesQueue.DequeueAllResponses(); } @@ -76,16 +76,16 @@ void CoapBase::ClearRequests(const Ip6::Address *aAddress) { Message *nextMessage; - for (Message *message = mPendingRequests.GetHead(); message != NULL; message = nextMessage) + for (Message *message = mPendingRequests.GetHead(); message != nullptr; message = nextMessage) { Metadata metadata; nextMessage = message->GetNextCoapMessage(); metadata.ReadFrom(*message); - if ((aAddress == NULL) || (metadata.mSourceAddress == *aAddress)) + if ((aAddress == nullptr) || (metadata.mSourceAddress == *aAddress)) { - FinalizeCoapTransaction(*message, metadata, NULL, NULL, OT_ERROR_ABORT); + FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_ABORT); } } } @@ -98,7 +98,7 @@ void CoapBase::AddResource(Resource &aResource) void CoapBase::RemoveResource(Resource &aResource) { IgnoreError(mResources.Remove(aResource)); - aResource.SetNext(NULL); + aResource.SetNext(nullptr); } void CoapBase::SetDefaultHandler(RequestHandler aHandler, void *aContext) @@ -115,9 +115,9 @@ void CoapBase::SetInterceptor(Interceptor aInterceptor, void *aContext) Message *CoapBase::NewMessage(const Message::Settings &aSettings) { - Message *message = NULL; + Message *message = nullptr; - VerifyOrExit((message = static_cast(Get().NewMessage(0, aSettings))) != NULL, OT_NOOP); + VerifyOrExit((message = static_cast(Get().NewMessage(0, aSettings))) != nullptr, OT_NOOP); message->SetOffset(0); exit: @@ -136,7 +136,7 @@ otError CoapBase::SendMessage(Message & aMessage, void * aContext) { otError error; - Message *storedCopy = NULL; + Message *storedCopy = nullptr; uint16_t copyLength = 0; switch (aMessage.GetType()) @@ -158,7 +158,7 @@ otError CoapBase::SendMessage(Message & aMessage, { copyLength = aMessage.GetLength(); } - else if (aMessage.IsNonConfirmable() && (aHandler != NULL)) + else if (aMessage.IsNonConfirmable() && (aHandler != nullptr)) { // As we do not retransmit non confirmable messages, create a // copy of header only, for token information. @@ -175,7 +175,7 @@ otError CoapBase::SendMessage(Message & aMessage, bool observe; SuccessOrExit(error = iterator.Init(&aMessage)); - observe = (iterator.GetFirstOptionMatching(OT_COAP_OPTION_OBSERVE) != NULL); + observe = (iterator.GetFirstOptionMatching(OT_COAP_OPTION_OBSERVE) != nullptr); // Special case, if we're sending a GET with Observe=1, that is a cancellation. if (observe && (aMessage.GetCode() == OT_COAP_CODE_GET)) @@ -194,9 +194,9 @@ otError CoapBase::SendMessage(Message & aMessage, // If we can find the previous handler context, cancel that too. Peer address // and tokens, etc should all match. Message *origRequest = FindRelatedRequest(aMessage, aMessageInfo, handlerMetadata); - if (origRequest != NULL) + if (origRequest != nullptr) { - FinalizeCoapTransaction(*origRequest, handlerMetadata, NULL, NULL, OT_ERROR_NONE); + FinalizeCoapTransaction(*origRequest, handlerMetadata, nullptr, nullptr, OT_ERROR_NONE); } } } @@ -219,14 +219,14 @@ otError CoapBase::SendMessage(Message & aMessage, (metadata.mConfirmable ? metadata.mRetransmissionTimeout : aTxParameters.CalculateMaxTransmitWait()); storedCopy = CopyAndEnqueueMessage(aMessage, copyLength, metadata); - VerifyOrExit(storedCopy != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(storedCopy != nullptr, error = OT_ERROR_NO_BUFS); } SuccessOrExit(error = Send(aMessage, aMessageInfo)); exit: - if (error != OT_ERROR_NONE && storedCopy != NULL) + if (error != OT_ERROR_NONE && storedCopy != nullptr) { DequeueMessage(*storedCopy); } @@ -266,11 +266,11 @@ otError CoapBase::SendNotFound(const Message &aRequest, const Ip6::MessageInfo & otError CoapBase::SendEmptyMessage(Message::Type aType, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; - Message *message = NULL; + Message *message = nullptr; VerifyOrExit(aRequest.IsConfirmable(), error = OT_ERROR_INVALID_ARGS); - VerifyOrExit((message = NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(aType, OT_COAP_CODE_EMPTY); message->SetMessageId(aRequest.GetMessageId()); @@ -280,7 +280,7 @@ otError CoapBase::SendEmptyMessage(Message::Type aType, const Message &aRequest, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -291,10 +291,10 @@ exit: otError CoapBase::SendHeaderResponse(Message::Code aCode, const Message &aRequest, const Ip6::MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; - Message *message = NULL; + Message *message = nullptr; VerifyOrExit(aRequest.IsRequest(), error = OT_ERROR_INVALID_ARGS); - VerifyOrExit((message = NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); switch (aRequest.GetType()) { @@ -318,7 +318,7 @@ otError CoapBase::SendHeaderResponse(Message::Code aCode, const Message &aReques exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -339,7 +339,7 @@ void CoapBase::HandleRetransmissionTimer(void) Message * nextMessage; Ip6::MessageInfo messageInfo; - for (Message *message = mPendingRequests.GetHead(); message != NULL; message = nextMessage) + for (Message *message = mPendingRequests.GetHead(); message != nullptr; message = nextMessage) { nextMessage = message->GetNextCoapMessage(); @@ -358,7 +358,7 @@ void CoapBase::HandleRetransmissionTimer(void) if (!metadata.mConfirmable || (metadata.mRetransmissionsRemaining == 0)) { // No expected response or acknowledgment. - FinalizeCoapTransaction(*message, metadata, NULL, NULL, OT_ERROR_RESPONSE_TIMEOUT); + FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_RESPONSE_TIMEOUT); continue; } @@ -399,7 +399,7 @@ void CoapBase::FinalizeCoapTransaction(Message & aRequest, { DequeueMessage(aRequest); - if (aMetadata.mResponseHandler != NULL) + if (aMetadata.mResponseHandler != nullptr) { aMetadata.mResponseHandler(aMetadata.mResponseContext, aResponse, aMessageInfo, aResult); } @@ -411,14 +411,14 @@ otError CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext) Message *nextMessage; Metadata metadata; - for (Message *message = mPendingRequests.GetHead(); message != NULL; message = nextMessage) + for (Message *message = mPendingRequests.GetHead(); message != nullptr; message = nextMessage) { nextMessage = message->GetNextCoapMessage(); metadata.ReadFrom(*message); if (metadata.mResponseHandler == aHandler && metadata.mResponseContext == aContext) { - FinalizeCoapTransaction(*message, metadata, NULL, NULL, OT_ERROR_ABORT); + FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_ABORT); error = OT_ERROR_NONE; } } @@ -429,9 +429,9 @@ otError CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext) Message *CoapBase::CopyAndEnqueueMessage(const Message &aMessage, uint16_t aCopyLength, const Metadata &aMetadata) { otError error = OT_ERROR_NONE; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; - VerifyOrExit((messageCopy = aMessage.Clone(aCopyLength)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = aMessage.Clone(aCopyLength)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = aMetadata.AppendTo(*messageCopy)); @@ -441,10 +441,10 @@ Message *CoapBase::CopyAndEnqueueMessage(const Message &aMessage, uint16_t aCopy exit: - if (error != OT_ERROR_NONE && messageCopy != NULL) + if (error != OT_ERROR_NONE && messageCopy != nullptr) { messageCopy->Free(); - messageCopy = NULL; + messageCopy = nullptr; } return messageCopy; @@ -454,7 +454,7 @@ void CoapBase::DequeueMessage(Message &aMessage) { mPendingRequests.Dequeue(aMessage); - if (mRetransmissionTimer.IsRunning() && (mPendingRequests.GetHead() == NULL)) + if (mRetransmissionTimer.IsRunning() && (mPendingRequests.GetHead() == nullptr)) { mRetransmissionTimer.Stop(); } @@ -468,11 +468,11 @@ void CoapBase::DequeueMessage(Message &aMessage) void CoapBase::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; // Create a message copy for lower layers. messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(Metadata)); - VerifyOrExit(messageCopy != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(messageCopy != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = Send(*messageCopy, aMessageInfo)); @@ -482,7 +482,7 @@ exit: { otLogWarnCoap("Failed to send copy: %s", otThreadErrorToString(error)); - if (messageCopy != NULL) + if (messageCopy != nullptr) { messageCopy->Free(); } @@ -495,7 +495,7 @@ Message *CoapBase::FindRelatedRequest(const Message & aResponse, { Message *message; - for (message = mPendingRequests.GetHead(); message != NULL; message = message->GetNextCoapMessage()) + for (message = mPendingRequests.GetHead(); message != nullptr; message = message->GetNextCoapMessage()) { aMetadata.ReadFrom(*message); @@ -556,14 +556,14 @@ void CoapBase::Receive(ot::Message &aMessage, const Ip6::MessageInfo &aMessageIn void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { Metadata metadata; - Message *request = NULL; + Message *request = nullptr; otError error = OT_ERROR_NONE; #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE bool responseObserve = false; #endif request = FindRelatedRequest(aMessage, aMessageInfo, metadata); - VerifyOrExit(request != NULL, OT_NOOP); + VerifyOrExit(request != nullptr, OT_NOOP); #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE if (metadata.mObserve && request->IsRequest()) @@ -572,7 +572,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo OptionIterator iterator; SuccessOrExit(error = iterator.Init(&aMessage)); - responseObserve = (iterator.GetFirstOptionMatching(OT_COAP_OPTION_OBSERVE) != NULL); + responseObserve = (iterator.GetFirstOptionMatching(OT_COAP_OPTION_OBSERVE) != nullptr); } #endif @@ -581,7 +581,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo case OT_COAP_TYPE_RESET: if (aMessage.IsEmpty()) { - FinalizeCoapTransaction(*request, metadata, NULL, NULL, OT_ERROR_ABORT); + FinalizeCoapTransaction(*request, metadata, nullptr, nullptr, OT_ERROR_ABORT); } // Silently ignore non-empty reset messages (RFC 7252, p. 4.2). @@ -612,7 +612,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo // Remove the message if response is not expected, otherwise await // response. - if (metadata.mResponseHandler == NULL) + if (metadata.mResponseHandler == nullptr) { DequeueMessage(*request); } @@ -625,7 +625,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo // dealing with RFC7641 rules here. // (If there is no response handler, then we're wasting our time!) #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE - if (metadata.mObserve && responseObserve && (metadata.mResponseHandler != NULL)) + if (metadata.mObserve && responseObserve && (metadata.mResponseHandler != nullptr)) { // This is a RFC7641 notification. The request is *not* done! metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, OT_ERROR_NONE); @@ -654,11 +654,11 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo // Separate response or observation notification. If the request was to a multicast // address, OR both the request and response carry Observe options, then this is NOT // the final message, we may see multiples. - if ((metadata.mResponseHandler != NULL) && (metadata.mDestinationAddress.IsMulticast() + if ((metadata.mResponseHandler != nullptr) && (metadata.mDestinationAddress.IsMulticast() #if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE - || (metadata.mObserve && responseObserve) + || (metadata.mObserve && responseObserve) #endif - )) + )) { // If multicast non-confirmable request, allow multiple responses metadata.mResponseHandler(metadata.mResponseContext, &aMessage, &aMessageInfo, OT_ERROR_NONE); @@ -673,7 +673,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo exit: - if (error == OT_ERROR_NONE && request == NULL) + if (error == OT_ERROR_NONE && request == nullptr) { if (aMessage.IsConfirmable() || aMessage.IsNonConfirmable()) { @@ -688,11 +688,11 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo { char uriPath[Resource::kMaxReceivedUriPath]; char * curUriPath = uriPath; - Message * cachedResponse = NULL; + Message * cachedResponse = nullptr; otError error = OT_ERROR_NOT_FOUND; OptionIterator iterator; - if (mInterceptor != NULL) + if (mInterceptor != nullptr) { SuccessOrExit(error = mInterceptor(aMessage, aMessageInfo, mContext)); } @@ -714,7 +714,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo } SuccessOrExit(error = iterator.Init(&aMessage)); - for (const otCoapOption *option = iterator.GetFirstOption(); option != NULL; option = iterator.GetNextOption()) + for (const otCoapOption *option = iterator.GetFirstOption(); option != nullptr; option = iterator.GetNextOption()) { switch (option->mNumber) { @@ -764,7 +764,7 @@ exit: IgnoreError(SendNotFound(aMessage, aMessageInfo)); } - if (cachedResponse != NULL) + if (cachedResponse != nullptr) { cachedResponse->Free(); } @@ -798,10 +798,10 @@ otError ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest, const Message *cacheResponse; cacheResponse = FindMatchedResponse(aRequest, aMessageInfo); - VerifyOrExit(cacheResponse != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(cacheResponse != nullptr, error = OT_ERROR_NOT_FOUND); *aResponse = cacheResponse->Clone(cacheResponse->GetLength() - sizeof(ResponseMetadata)); - VerifyOrExit(*aResponse != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(*aResponse != nullptr, error = OT_ERROR_NO_BUFS); exit: return error; @@ -811,7 +811,7 @@ const Message *ResponsesQueue::FindMatchedResponse(const Message &aRequest, cons { Message *message; - for (message = mQueue.GetHead(); message != NULL; message = message->GetNextCoapMessage()) + for (message = mQueue.GetHead(); message != nullptr; message = message->GetNextCoapMessage()) { if (message->GetMessageId() == aRequest.GetMessageId()) { @@ -840,11 +840,11 @@ void ResponsesQueue::EnqueueResponse(Message & aMessage, metadata.mDequeueTime = TimerMilli::GetNow() + aTxParameters.CalculateExchangeLifetime(); metadata.mMessageInfo = aMessageInfo; - VerifyOrExit(FindMatchedResponse(aMessage, aMessageInfo) == NULL, OT_NOOP); + VerifyOrExit(FindMatchedResponse(aMessage, aMessageInfo) == nullptr, OT_NOOP); UpdateQueue(); - VerifyOrExit((responseCopy = aMessage.Clone()) != NULL, OT_NOOP); + VerifyOrExit((responseCopy = aMessage.Clone()) != nullptr, OT_NOOP); VerifyOrExit(metadata.AppendTo(*responseCopy) == OT_ERROR_NONE, responseCopy->Free()); @@ -859,20 +859,20 @@ exit: void ResponsesQueue::UpdateQueue(void) { uint16_t msgCount = 0; - Message * earliestMsg = NULL; + Message * earliestMsg = nullptr; TimeMilli earliestDequeueTime(0); // Check the number of messages in the queue and if number is at // `kMaxCachedResponses` remove the one with earliest dequeue // time. - for (Message *message = mQueue.GetHead(); message != NULL; message = message->GetNextCoapMessage()) + for (Message *message = mQueue.GetHead(); message != nullptr; message = message->GetNextCoapMessage()) { ResponseMetadata metadata; metadata.ReadFrom(*message); - if ((earliestMsg == NULL) || (metadata.mDequeueTime < earliestDequeueTime)) + if ((earliestMsg == nullptr) || (metadata.mDequeueTime < earliestDequeueTime)) { earliestMsg = message; earliestDequeueTime = metadata.mDequeueTime; @@ -897,7 +897,7 @@ void ResponsesQueue::DequeueAllResponses(void) { Message *message; - while ((message = mQueue.GetHead()) != NULL) + while ((message = mQueue.GetHead()) != nullptr) { DequeueResponse(*message); } @@ -914,7 +914,7 @@ void ResponsesQueue::HandleTimer(void) TimeMilli nextDequeueTime = now.GetDistantFuture(); Message * nextMessage; - for (Message *message = mQueue.GetHead(); message != NULL; message = nextMessage) + for (Message *message = mQueue.GetHead(); message != nullptr; message = nextMessage) { ResponseMetadata metadata; diff --git a/src/core/coap/coap.hpp b/src/core/coap/coap.hpp index 00ba15cde..d8f172939 100644 --- a/src/core/coap/coap.hpp +++ b/src/core/coap/coap.hpp @@ -90,11 +90,11 @@ public: /** * This static method coverts a pointer to `otCoapTxParameters` to `Coap::TxParamters` * - * If the pointer is NULL, the default parameters are used instead. + * If the pointer is nullptr, the default parameters are used instead. * * @param[in] aTxParameters A pointer to tx parameter. * - * @returns A reference to corresponding `TxParamters` if @p aTxParameters is not NULL, otherwise the default tx + * @returns A reference to corresponding `TxParamters` if @p aTxParameters is not nullptr, otherwise the default tx * parameters. * */ @@ -154,7 +154,7 @@ public: /** * This constructor initializes the resource. * - * @param[in] aUriPath A pointer to a NULL-terminated string for the URI path. + * @param[in] aUriPath A pointer to a null-terminated string for the URI path. * @param[in] aHandler A function pointer that is called when receiving a CoAP message for @p aUriPath. * @param[in] aContext A pointer to arbitrary context information. */ @@ -163,7 +163,7 @@ public: mUriPath = aUriPath; mHandler = aHandler; mContext = aContext; - mNext = NULL; + mNext = nullptr; } /** @@ -322,7 +322,7 @@ public: /* This method sets the default handler for unhandled CoAP requests. * * @param[in] aHandler A function pointer that shall be called when an unhandled request arrives. - * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used. + * @param[in] aContext A pointer to arbitrary context information. May be nullptr if not used. * */ void SetDefaultHandler(RequestHandler aHandler, void *aContext); @@ -332,7 +332,7 @@ public: * * @param[in] aSettings The message settings. * - * @returns A pointer to the message or NULL if failed to allocate message. + * @returns A pointer to the message or nullptr if failed to allocate message. * */ Message *NewMessage(const Message::Settings &aSettings = Message::Settings::GetDefault()); @@ -340,7 +340,7 @@ public: /** * This method creates a new message with a CoAP header that has Network Control priority level. * - * @returns A pointer to the message or NULL if failed to allocate message. + * @returns A pointer to the message or nullptr if failed to allocate message. * */ Message *NewPriorityMessage(void) @@ -352,7 +352,7 @@ public: * This method sends a CoAP message with custom transmission parameters. * * If a response for a request is expected, respective function and context information should be provided. - * If no response is expected, these arguments should be NULL pointers. + * If no response is expected, these arguments should be nullptr pointers. * If Message Id was not set in the header (equal to 0), this function will assign unique Message Id to the message. * * @param[in] aMessage A reference to the message to send. @@ -368,14 +368,14 @@ public: otError SendMessage(Message & aMessage, const Ip6::MessageInfo &aMessageInfo, const TxParameters & aTxParameters, - ResponseHandler aHandler = NULL, - void * aContext = NULL); + ResponseHandler aHandler = nullptr, + void * aContext = nullptr); /** * This method sends a CoAP message with default transmission parameters. * * If a response for a request is expected, respective function and context information should be provided. - * If no response is expected, these arguments should be NULL pointers. + * If no response is expected, these arguments should be nullptr pointers. * If Message Id was not set in the header (equal to 0), this function will assign unique Message Id to the message. * * @param[in] aMessage A reference to the message to send. @@ -389,8 +389,8 @@ public: */ otError SendMessage(Message & aMessage, const Ip6::MessageInfo &aMessageInfo, - ResponseHandler aHandler = NULL, - void * aContext = NULL); + ResponseHandler aHandler = nullptr, + void * aContext = nullptr); /** * This method sends a CoAP reset message. diff --git a/src/core/coap/coap_message.cpp b/src/core/coap/coap_message.cpp index f01b93e4f..5d03b9d9e 100644 --- a/src/core/coap/coap_message.cpp +++ b/src/core/coap/coap_message.cpp @@ -175,7 +175,7 @@ otError Message::AppendUriPathOptions(const char *aUriPath) const char *cur = aUriPath; const char *end; - while ((end = strchr(cur, '/')) != NULL) + while ((end = strchr(cur, '/')) != nullptr) { SuccessOrExit(error = AppendOption(OT_COAP_OPTION_URI_PATH, static_cast(end - cur), cur)); cur = end + 1; @@ -258,7 +258,7 @@ otError Message::ParseHeader(void) VerifyOrExit(GetTokenLength() <= kMaxTokenLength, error = OT_ERROR_PARSE); SuccessOrExit(error = iterator.Init(this)); - for (const otCoapOption *option = iterator.GetFirstOption(); option != NULL; option = iterator.GetNextOption()) + for (const otCoapOption *option = iterator.GetFirstOption(); option != nullptr; option = iterator.GetNextOption()) { } @@ -304,7 +304,7 @@ Message *Message::Clone(uint16_t aLength) const { Message *message = static_cast(ot::Message::Clone(aLength)); - VerifyOrExit(message != NULL, OT_NOOP); + VerifyOrExit(message != nullptr, OT_NOOP); memcpy(&message->GetHelpData(), &GetHelpData(), sizeof(GetHelpData())); @@ -434,9 +434,9 @@ exit: const otCoapOption *OptionIterator::GetFirstOptionMatching(uint16_t aOption) { - const otCoapOption *rval = NULL; + const otCoapOption *rval = nullptr; - for (const otCoapOption *option = GetFirstOption(); option != NULL; option = GetNextOption()) + for (const otCoapOption *option = GetFirstOption(); option != nullptr; option = GetNextOption()) { if (option->mNumber == aOption) { @@ -451,7 +451,7 @@ const otCoapOption *OptionIterator::GetFirstOptionMatching(uint16_t aOption) const otCoapOption *OptionIterator::GetFirstOption(void) { - const otCoapOption *option = NULL; + const otCoapOption *option = nullptr; const Message & message = GetMessage(); ClearOption(); @@ -468,9 +468,9 @@ const otCoapOption *OptionIterator::GetFirstOption(void) const otCoapOption *OptionIterator::GetNextOptionMatching(uint16_t aOption) { - const otCoapOption *rval = NULL; + const otCoapOption *rval = nullptr; - for (const otCoapOption *option = GetNextOption(); option != NULL; option = GetNextOption()) + for (const otCoapOption *option = GetNextOption(); option != nullptr; option = GetNextOption()) { if (option->mNumber == aOption) { @@ -490,7 +490,7 @@ const otCoapOption *OptionIterator::GetNextOption(void) uint16_t optionLength; uint8_t buf[Message::kMaxOptionHeaderSize]; uint8_t * cur = buf + 1; - otCoapOption * rval = NULL; + otCoapOption * rval = nullptr; const Message &message = GetMessage(); VerifyOrExit(mNextOptionOffset < message.GetLength(), error = OT_ERROR_NOT_FOUND); diff --git a/src/core/coap/coap_message.hpp b/src/core/coap/coap_message.hpp index c601a4e81..4606e3905 100644 --- a/src/core/coap/coap_message.hpp +++ b/src/core/coap/coap_message.hpp @@ -133,7 +133,7 @@ public: * * @param[in] aType The Type value. * @param[in] aCode The Code value. - * @param[in] aUriPath A pointer to a NULL-terminated string. + * @param[in] aUriPath A pointer to a null-terminated string. * * @retval OT_ERROR_NONE Successfully appended the option. * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size. @@ -342,7 +342,7 @@ public: /** * This method appends a Uri-Path option. * - * @param[in] aUriPath A pointer to a NULL-terminated string. + * @param[in] aUriPath A pointer to a null-terminated string. * * @retval OT_ERROR_NONE Successfully appended the option. * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type. @@ -369,7 +369,7 @@ public: /** * This method appends a Proxy-Uri option. * - * @param[in] aProxyUri A pointer to a NULL-terminated string. + * @param[in] aProxyUri A pointer to a null-terminated string. * * @retval OT_ERROR_NONE Successfully appended the option. * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type. @@ -404,7 +404,7 @@ public: /** * This method appends a single Uri-Query option. * - * @param[in] aUriQuery A pointer to NULL-terminated string, which should contain a single key=value pair. + * @param[in] aUriQuery A pointer to null-terminated string, which should contain a single key=value pair. * * @retval OT_ERROR_NONE Successfully appended the option. * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type. @@ -523,7 +523,7 @@ public: * * @param[in] aLength Number of payload bytes to copy. * - * @returns A pointer to the message or NULL if insufficient message buffers are available. + * @returns A pointer to the message or nullptr if insufficient message buffers are available. * */ Message *Clone(uint16_t aLength) const; @@ -535,7 +535,7 @@ public: * `Type`, `SubType`, `LinkSecurity`, `Offset`, `InterfaceId`, and `Priority` fields on the cloned message are also * copied from the original one. * - * @returns A pointer to the message or NULL if insufficient message buffers are available. + * @returns A pointer to the message or nullptr if insufficient message buffers are available. * */ Message *Clone(void) const { return Clone(GetLength()); } @@ -552,7 +552,7 @@ public: * This method should be used when the message is in a `Coap::MessageQueue` (i.e., a queue containing only CoAP * messages). * - * @returns A pointer to the next message in the queue or NULL if at the end of the queue. + * @returns A pointer to the next message in the queue or nullptr if at the end of the queue. * */ Message *GetNextCoapMessage(void) { return static_cast(GetNext()); } @@ -563,7 +563,7 @@ public: * This method should be used when the message is in a `Coap::MessageQueue` (i.e., a queue containing only CoAP * messages). * - * @returns A pointer to the next message in the queue or NULL if at the end of the queue. + * @returns A pointer to the next message in the queue or nullptr if at the end of the queue. * */ const Message *GetNextCoapMessage(void) const { return static_cast(GetNext()); } @@ -722,7 +722,7 @@ public: * * @param[in] aOption Option number to look for. * - * @returns A pointer to the first matching option. If no option matching @p aOption is seen, NULL pointer is + * @returns A pointer to the first matching option. If no option matching @p aOption is seen, nullptr pointer is * returned. */ const otCoapOption *GetFirstOptionMatching(uint16_t aOption); @@ -730,7 +730,7 @@ public: /** * This method returns a pointer to the first option. * - * @returns A pointer to the first option. If no option is present NULL pointer is returned. + * @returns A pointer to the first option. If no option is present nullptr pointer is returned. */ const otCoapOption *GetFirstOption(void); @@ -743,14 +743,14 @@ public: * @param[in] aOption Option number to look for. * * @returns A pointer to the next matching option (relative to current iterator position). If no option matching @p - * aOption is seen, NULL pointer is returned. + * aOption is seen, nullptr pointer is returned. */ const otCoapOption *GetNextOptionMatching(uint16_t aOption); /** * This method returns a pointer to the next option. * - * @returns A pointer to the next option. If no more options are present NULL pointer is returned. + * @returns A pointer to the next option. If no more options are present nullptr pointer is returned. */ const otCoapOption *GetNextOption(void); diff --git a/src/core/coap/coap_secure.cpp b/src/core/coap/coap_secure.cpp index 33fcd7fbc..33f0fbe65 100644 --- a/src/core/coap/coap_secure.cpp +++ b/src/core/coap/coap_secure.cpp @@ -48,8 +48,8 @@ namespace Coap { CoapSecure::CoapSecure(Instance &aInstance, bool aLayerTwoSecurity) : CoapBase(aInstance, &CoapSecure::Send) , mDtls(aInstance, aLayerTwoSecurity) - , mConnectedCallback(NULL) - , mConnectedContext(NULL) + , mConnectedCallback(nullptr) + , mConnectedContext(nullptr) , mTransmitQueue() , mTransmitTask(aInstance, &CoapSecure::HandleTransmit, this) { @@ -59,8 +59,8 @@ otError CoapSecure::Start(uint16_t aPort) { otError error = OT_ERROR_NONE; - mConnectedCallback = NULL; - mConnectedContext = NULL; + mConnectedCallback = nullptr; + mConnectedContext = nullptr; SuccessOrExit(error = mDtls.Open(&CoapSecure::HandleDtlsReceive, &CoapSecure::HandleDtlsConnected, this)); SuccessOrExit(error = mDtls.Bind(aPort)); @@ -73,8 +73,8 @@ otError CoapSecure::Start(MeshCoP::Dtls::TransportCallback aCallback, void *aCon { otError error = OT_ERROR_NONE; - mConnectedCallback = NULL; - mConnectedContext = NULL; + mConnectedCallback = nullptr; + mConnectedContext = nullptr; SuccessOrExit(error = mDtls.Open(&CoapSecure::HandleDtlsReceive, &CoapSecure::HandleDtlsConnected, this)); SuccessOrExit(error = mDtls.Bind(aCallback, aContext)); @@ -93,7 +93,7 @@ void CoapSecure::Stop(void) { mDtls.Close(); - for (ot::Message *message = mTransmitQueue.GetHead(); message != NULL; message = message->GetNext()) + for (ot::Message *message = mTransmitQueue.GetHead(); message != nullptr; message = message->GetNext()) { mTransmitQueue.Dequeue(*message); message->Free(); @@ -189,7 +189,7 @@ void CoapSecure::HandleDtlsConnected(void *aContext, bool aConnected) void CoapSecure::HandleDtlsConnected(bool aConnected) { - if (mConnectedCallback != NULL) + if (mConnectedCallback != nullptr) { mConnectedCallback(aConnected, mConnectedContext); } @@ -202,9 +202,9 @@ void CoapSecure::HandleDtlsReceive(void *aContext, uint8_t *aBuf, uint16_t aLeng void CoapSecure::HandleDtlsReceive(uint8_t *aBuf, uint16_t aLength) { - ot::Message *message = NULL; + ot::Message *message = nullptr; - VerifyOrExit((message = Get().New(Message::kTypeIp6, Message::GetHelpDataReserved())) != NULL, + VerifyOrExit((message = Get().New(Message::kTypeIp6, Message::GetHelpDataReserved())) != nullptr, OT_NOOP); SuccessOrExit(message->Append(aBuf, aLength)); @@ -212,7 +212,7 @@ void CoapSecure::HandleDtlsReceive(uint8_t *aBuf, uint16_t aLength) exit: - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -228,10 +228,10 @@ void CoapSecure::HandleTransmit(void) otError error = OT_ERROR_NONE; ot::Message *message = mTransmitQueue.GetHead(); - VerifyOrExit(message != NULL, OT_NOOP); + VerifyOrExit(message != nullptr, OT_NOOP); mTransmitQueue.Dequeue(*message); - if (mTransmitQueue.GetHead() != NULL) + if (mTransmitQueue.GetHead() != nullptr) { mTransmitTask.Post(); } diff --git a/src/core/coap/coap_secure.hpp b/src/core/coap/coap_secure.hpp index b6add7c97..a0281f512 100644 --- a/src/core/coap/coap_secure.hpp +++ b/src/core/coap/coap_secure.hpp @@ -250,7 +250,7 @@ public: * This method sends a CoAP message over secure DTLS connection. * * If a response for a request is expected, respective function and context information should be provided. - * If no response is expected, these arguments should be NULL pointers. + * If no response is expected, these arguments should be nullptr pointers. * If Message Id was not set in the header (equal to 0), this function will assign unique Message Id to the message. * * @param[in] aMessage A reference to the message to send. @@ -262,13 +262,13 @@ public: * @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized. * */ - otError SendMessage(Message &aMessage, ResponseHandler aHandler = NULL, void *aContext = NULL); + otError SendMessage(Message &aMessage, ResponseHandler aHandler = nullptr, void *aContext = nullptr); /** * This method sends a CoAP message over secure DTLS connection. * * If a response for a request is expected, respective function and context information should be provided. - * If no response is expected, these arguments should be NULL pointers. + * If no response is expected, these arguments should be nullptr pointers. * If Message Id was not set in the header (equal to 0), this function will assign unique Message Id to the message. * * @param[in] aMessage A reference to the message to send. @@ -283,8 +283,8 @@ public: */ otError SendMessage(Message & aMessage, const Ip6::MessageInfo &aMessageInfo, - ResponseHandler aHandler = NULL, - void * aContext = NULL); + ResponseHandler aHandler = nullptr, + void * aContext = nullptr); /** * This method is used to pass UDP messages to the secure CoAP server. diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 77f19ff64..550423d8e 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -51,8 +51,8 @@ OT_DEFINE_ALIGNED_VAR(gInstanceRaw, sizeof(Instance), uint64_t); #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE -otHeapFreeFn ot::Instance::mFree = NULL; -otHeapCAllocFn ot::Instance::mCAlloc = NULL; +otHeapFreeFn ot::Instance::mFree = nullptr; +otHeapCAllocFn ot::Instance::mCAlloc = nullptr; #endif // OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE @@ -141,14 +141,14 @@ Instance &Instance::Get(void) Instance *Instance::Init(void *aBuffer, size_t *aBufferSize) { - Instance *instance = NULL; + Instance *instance = nullptr; - VerifyOrExit(aBufferSize != NULL, OT_NOOP); + VerifyOrExit(aBufferSize != nullptr, OT_NOOP); // Make sure the input buffer is big enough VerifyOrExit(sizeof(Instance) <= *aBufferSize, *aBufferSize = sizeof(Instance)); - VerifyOrExit(aBuffer != NULL, OT_NOOP); + VerifyOrExit(aBuffer != nullptr, OT_NOOP); instance = new (aBuffer) Instance(); diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index c0de28e3e..63e9474b6 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -237,14 +237,14 @@ public: #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE void HeapFree(void *aPointer) { - OT_ASSERT(mFree != NULL); + OT_ASSERT(mFree != nullptr); mFree(aPointer); } void *HeapCAlloc(size_t aCount, size_t aSize) { - OT_ASSERT(mCAlloc != NULL); + OT_ASSERT(mCAlloc != nullptr); return mCAlloc(aCount, aSize); } diff --git a/src/core/common/linked_list.hpp b/src/core/common/linked_list.hpp index ba82fb6ed..143745815 100644 --- a/src/core/common/linked_list.hpp +++ b/src/core/common/linked_list.hpp @@ -69,7 +69,7 @@ public: /** * This method gets the next entry in the linked list. * - * @returns A pointer to the next entry in the linked list or NULL if at the end of the list. + * @returns A pointer to the next entry in the linked list or nullptr if at the end of the list. * */ const Type *GetNext(void) const { return static_cast(static_cast(this)->mNext); } @@ -77,7 +77,7 @@ public: /** * This method gets the next entry in the linked list. * - * @returns A pointer to the next entry in the linked list or NULL if at the end of the list. + * @returns A pointer to the next entry in the linked list or nullptr if at the end of the list. * */ Type *GetNext(void) { return static_cast(static_cast(this)->mNext); } @@ -106,14 +106,14 @@ public: * */ LinkedList(void) - : mHead(NULL) + : mHead(nullptr) { } /** * This method returns the entry at the head of the linked list * - * @returns Pointer to the entry at the head of the linked list, or NULL if list is empty. + * @returns Pointer to the entry at the head of the linked list, or nullptr if list is empty. * */ Type *GetHead(void) { return mHead; } @@ -121,7 +121,7 @@ public: /** * This method returns the entry at the head of the linked list. * - * @returns Pointer to the entry at the head of the linked list, or NULL if list is empty. + * @returns Pointer to the entry at the head of the linked list, or nullptr if list is empty. * */ const Type *GetHead(void) const { return mHead; } @@ -138,7 +138,7 @@ public: * This method clears the linked list. * */ - void Clear(void) { mHead = NULL; } + void Clear(void) { mHead = nullptr; } /** * This method indicates whether the linked list is empty or not. @@ -147,7 +147,7 @@ public: * @retval FALSE If the linked list is not empty. * */ - bool IsEmpty(void) const { return (mHead == NULL); } + bool IsEmpty(void) const { return (mHead == nullptr); } /** * This method pushes an entry at the head of the linked list. @@ -179,14 +179,14 @@ public: * * @note This method does not change the popped entry itself, i.e., the popped entry next pointer stays as before. * - * @returns The entry that was popped if list is not empty, or NULL if list is empty. + * @returns The entry that was popped if list is not empty, or nullptr if list is empty. * */ Type *Pop(void) { Type *entry = mHead; - if (mHead != NULL) + if (mHead != nullptr) { mHead = mHead->GetNext(); } @@ -199,17 +199,17 @@ public: * * @note This method does not change the popped entry itself, i.e., the popped entry next pointer stays as before. * - * @param[in] aPrevEntry A pointer to a previous entry. If it is not NULL the entry after this will be popped, - * otherwise (if it is NULL) the entry at head of the list is popped. + * @param[in] aPrevEntry A pointer to a previous entry. If it is not nullptr the entry after this will be popped, + * otherwise (if it is nullptr) the entry at head of the list is popped. * - * @returns Pointer to the entry that was popped, or NULL if there is no entry to pop. + * @returns Pointer to the entry that was popped, or nullptr if there is no entry to pop. * */ Type *PopAfter(Type *aPrevEntry) { Type *entry; - if (aPrevEntry == NULL) + if (aPrevEntry == nullptr) { entry = Pop(); } @@ -217,7 +217,7 @@ public: { entry = aPrevEntry->GetNext(); - if (entry != NULL) + if (entry != nullptr) { aPrevEntry->SetNext(entry->GetNext()); } @@ -239,7 +239,7 @@ public: { bool contains = false; - for (Type *cur = mHead; cur != NULL; cur = cur->GetNext()) + for (Type *cur = mHead; cur != nullptr; cur = cur->GetNext()) { if (cur == &aEntry) { @@ -297,9 +297,9 @@ public: Pop(); error = OT_ERROR_NONE; } - else if (mHead != NULL) + else if (mHead != nullptr) { - for (Type *cur = mHead; cur->GetNext() != NULL; cur = cur->GetNext()) + for (Type *cur = mHead; cur->GetNext() != nullptr; cur = cur->GetNext()) { if (cur->GetNext() == &aEntry) { @@ -318,7 +318,7 @@ public: * * @param[in] aEntry A reference to an entry to find. * @param[out] aPrevEntry A pointer to output previous entry on success (when @p aEntry is found is the list). - * @p aPrevEntry is set to NULL if the @p aEntry is head of the list. Otherwise it + * @p aPrevEntry is set to nullptr if the @p aEntry is head of the list. Otherwise it * is updated to point to previous entry before @p aEntry in the list. * * @retval OT_ERROR_NONE The entry was found in the list and @p aPrevEntry was updated successfully. @@ -331,12 +331,12 @@ public: if (mHead == &aEntry) { - aPrevEntry = NULL; + aPrevEntry = nullptr; error = OT_ERROR_NONE; } else { - for (Type *cur = mHead; cur->GetNext() != NULL; cur = cur->GetNext()) + for (Type *cur = mHead; cur->GetNext() != nullptr; cur = cur->GetNext()) { if (cur->GetNext() == &aEntry) { @@ -353,16 +353,16 @@ public: /** * This method returns the tail of the linked list (i.e., the last entry in the list). * - * @returns A pointer to tail entry in the linked list or NULL if list is empty. + * @returns A pointer to tail entry in the linked list or nullptr if list is empty. * */ const Type *GetTail(void) const { const Type *tail = mHead; - if (tail != NULL) + if (tail != nullptr) { - while (tail->GetNext() != NULL) + while (tail->GetNext() != nullptr) { tail = tail->GetNext(); } @@ -374,7 +374,7 @@ public: /** * This method returns the tail of the linked list (i.e., the last entry in the list). * - * @returns A pointer to tail entry in the linked list or NULL if list is empty. + * @returns A pointer to tail entry in the linked list or nullptr if list is empty. * */ Type *GetTail(void) { return const_cast(const_cast *>(this)->GetTail()); } diff --git a/src/core/common/message.cpp b/src/core/common/message.cpp index cb1be9f87..caf7e8c46 100644 --- a/src/core/common/message.cpp +++ b/src/core/common/message.cpp @@ -66,7 +66,7 @@ Message *MessagePool::New(Message::Type aType, uint16_t aReserveHeader, Message: otError error = OT_ERROR_NONE; Message *message; - VerifyOrExit((message = static_cast(NewBuffer(aPriority))) != NULL, OT_NOOP); + VerifyOrExit((message = static_cast(NewBuffer(aPriority))) != nullptr, OT_NOOP); memset(message, 0, sizeof(*message)); message->SetMessagePool(this); @@ -81,7 +81,7 @@ exit: if (error != OT_ERROR_NONE) { Free(message); - message = NULL; + message = nullptr; } return message; @@ -101,14 +101,14 @@ Message *MessagePool::New(Message::Type aType, uint16_t aReserveHeader, const Me void MessagePool::Free(Message *aMessage) { - OT_ASSERT(aMessage->Next() == NULL && aMessage->Prev() == NULL); + OT_ASSERT(aMessage->Next() == nullptr && aMessage->Prev() == nullptr); FreeBuffers(static_cast(aMessage)); } Buffer *MessagePool::NewBuffer(Message::Priority aPriority) { - Buffer *buffer = NULL; + Buffer *buffer = nullptr; SuccessOrExit(ReclaimBuffers(1, aPriority)); @@ -120,15 +120,15 @@ Buffer *MessagePool::NewBuffer(Message::Priority aPriority) buffer = mFreeBuffers.Pop(); - if (buffer != NULL) + if (buffer != nullptr) { - buffer->SetNextBuffer(NULL); + buffer->SetNextBuffer(nullptr); mNumFreeBuffers--; } #endif - if (buffer == NULL) + if (buffer == nullptr) { otLogInfoMem("No available message buffer"); } @@ -139,7 +139,7 @@ exit: void MessagePool::FreeBuffers(Buffer *aBuffer) { - while (aBuffer != NULL) + while (aBuffer != nullptr) { Buffer *next = aBuffer->GetNextBuffer(); #if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT @@ -193,8 +193,8 @@ Message::Settings::Settings(LinkSecurityMode aSecurityMode, Priority aPriority) } Message::Settings::Settings(const otMessageSettings *aSettings) - : mLinkSecurityEnabled((aSettings != NULL) ? aSettings->mLinkSecurityEnabled : true) - , mPriority((aSettings != NULL) ? static_cast(aSettings->mPriority) : kPriorityNormal) + : mLinkSecurityEnabled((aSettings != nullptr) ? aSettings->mLinkSecurityEnabled : true) + , mPriority((aSettings != nullptr) ? static_cast(aSettings->mPriority) : kPriorityNormal) { } @@ -209,10 +209,10 @@ otError Message::ResizeMessage(uint16_t aLength) while (curLength < aLength) { - if (curBuffer->GetNextBuffer() == NULL) + if (curBuffer->GetNextBuffer() == nullptr) { curBuffer->SetNextBuffer(GetMessagePool()->NewBuffer(GetPriority())); - VerifyOrExit(curBuffer->GetNextBuffer() != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(curBuffer->GetNextBuffer() != nullptr, error = OT_ERROR_NO_BUFS); } curBuffer = curBuffer->GetNextBuffer(); @@ -222,7 +222,7 @@ otError Message::ResizeMessage(uint16_t aLength) // remove buffers lastBuffer = curBuffer; curBuffer = curBuffer->GetNextBuffer(); - lastBuffer->SetNextBuffer(NULL); + lastBuffer->SetNextBuffer(nullptr); GetMessagePool()->FreeBuffers(curBuffer); @@ -243,17 +243,17 @@ Message *Message::GetNext(void) const if (GetMetadata().mInPriorityQ) { PriorityQueue *priorityQueue = GetPriorityQueue(); - VerifyOrExit(priorityQueue != NULL, next = NULL); + VerifyOrExit(priorityQueue != nullptr, next = nullptr); tail = priorityQueue->GetTail(); } else { MessageQueue *messageQueue = GetMessageQueue(); - VerifyOrExit(messageQueue != NULL, next = NULL); + VerifyOrExit(messageQueue != nullptr, next = nullptr); tail = messageQueue->GetTail(); } - next = (this == tail) ? NULL : Next(); + next = (this == tail) ? nullptr : Next(); exit: return next; @@ -346,7 +346,7 @@ otError Message::SetPriority(Priority aPriority) { otError error = OT_ERROR_NONE; uint8_t priority = static_cast(aPriority); - PriorityQueue *priorityQueue = NULL; + PriorityQueue *priorityQueue = nullptr; VerifyOrExit(priority < kNumPriorities, error = OT_ERROR_INVALID_ARGS); @@ -361,7 +361,7 @@ otError Message::SetPriority(Priority aPriority) GetMetadata().mPriority = priority; - if (priorityQueue != NULL) + if (priorityQueue != nullptr) { priorityQueue->Enqueue(*this); } @@ -389,11 +389,11 @@ exit: otError Message::Prepend(const void *aBuf, uint16_t aLength) { otError error = OT_ERROR_NONE; - Buffer *newBuffer = NULL; + Buffer *newBuffer = nullptr; while (aLength > GetReserved()) { - VerifyOrExit((newBuffer = GetMessagePool()->NewBuffer(GetPriority())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((newBuffer = GetMessagePool()->NewBuffer(GetPriority())) != nullptr, error = OT_ERROR_NO_BUFS); newBuffer->SetNextBuffer(GetNextBuffer()); SetNextBuffer(newBuffer); @@ -412,7 +412,7 @@ otError Message::Prepend(const void *aBuf, uint16_t aLength) GetMetadata().mLength += aLength; SetOffset(GetOffset() + aLength); - if (aBuf != NULL) + if (aBuf != nullptr) { Write(0, aLength, aBuf); } @@ -484,7 +484,7 @@ uint16_t Message::Read(uint16_t aOffset, uint16_t aLength, void *aBuf) const while (aOffset >= kBufferDataSize) { - OT_ASSERT(curBuffer != NULL); + OT_ASSERT(curBuffer != nullptr); curBuffer = curBuffer->GetNextBuffer(); aOffset -= kBufferDataSize; @@ -493,7 +493,7 @@ uint16_t Message::Read(uint16_t aOffset, uint16_t aLength, void *aBuf) const // begin copy while (aLength > 0) { - OT_ASSERT(curBuffer != NULL); + OT_ASSERT(curBuffer != nullptr); bytesToCopy = kBufferDataSize - aOffset; @@ -559,7 +559,7 @@ int Message::Write(uint16_t aOffset, uint16_t aLength, const void *aBuf) while (aOffset >= kBufferDataSize) { - OT_ASSERT(curBuffer != NULL); + OT_ASSERT(curBuffer != nullptr); curBuffer = curBuffer->GetNextBuffer(); aOffset -= kBufferDataSize; @@ -568,7 +568,7 @@ int Message::Write(uint16_t aOffset, uint16_t aLength, const void *aBuf) // begin copy while (aLength > 0) { - OT_ASSERT(curBuffer != NULL); + OT_ASSERT(curBuffer != nullptr); bytesToCopy = kBufferDataSize - aOffset; @@ -618,7 +618,7 @@ Message *Message::Clone(uint16_t aLength) const Message *messageCopy; uint16_t offset; - VerifyOrExit((messageCopy = GetMessagePool()->New(GetType(), GetReserved(), GetPriority())) != NULL, + VerifyOrExit((messageCopy = GetMessagePool()->New(GetType(), GetReserved(), GetPriority())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = messageCopy->SetLength(aLength)); CopyTo(0, 0, aLength, *messageCopy); @@ -635,10 +635,10 @@ Message *Message::Clone(uint16_t aLength) const exit: - if (error != OT_ERROR_NONE && messageCopy != NULL) + if (error != OT_ERROR_NONE && messageCopy != nullptr) { messageCopy->Free(); - messageCopy = NULL; + messageCopy = nullptr; } return messageCopy; @@ -733,7 +733,7 @@ uint16_t Message::UpdateChecksum(uint16_t aChecksum, uint16_t aOffset, uint16_t while (aOffset >= kBufferDataSize) { - OT_ASSERT(curBuffer != NULL); + OT_ASSERT(curBuffer != nullptr); curBuffer = curBuffer->GetNextBuffer(); aOffset -= kBufferDataSize; @@ -742,7 +742,7 @@ uint16_t Message::UpdateChecksum(uint16_t aChecksum, uint16_t aOffset, uint16_t // begin copy while (aLength > 0) { - OT_ASSERT(curBuffer != NULL); + OT_ASSERT(curBuffer != nullptr); bytesToCover = kBufferDataSize - aOffset; @@ -786,22 +786,22 @@ void Message::SetPriorityQueue(PriorityQueue *aPriorityQueue) MessageQueue::MessageQueue(void) { - SetTail(NULL); + SetTail(nullptr); } Message *MessageQueue::GetHead(void) const { - return (GetTail() == NULL) ? NULL : GetTail()->Next(); + return (GetTail() == nullptr) ? nullptr : GetTail()->Next(); } void MessageQueue::Enqueue(Message &aMessage, QueuePosition aPosition) { OT_ASSERT(!aMessage.IsInAQueue()); - OT_ASSERT((aMessage.Next() == NULL) && (aMessage.Prev() == NULL)); + OT_ASSERT((aMessage.Next() == nullptr) && (aMessage.Prev() == nullptr)); aMessage.SetMessageQueue(this); - if (GetTail() == NULL) + if (GetTail() == nullptr) { aMessage.Next() = &aMessage; aMessage.Prev() = &aMessage; @@ -828,7 +828,7 @@ void MessageQueue::Enqueue(Message &aMessage, QueuePosition aPosition) void MessageQueue::Dequeue(Message &aMessage) { OT_ASSERT(aMessage.GetMessageQueue() == this); - OT_ASSERT((aMessage.Next() != NULL) && (aMessage.Prev() != NULL)); + OT_ASSERT((aMessage.Next() != nullptr) && (aMessage.Prev() != nullptr)); if (&aMessage == GetTail()) { @@ -836,17 +836,17 @@ void MessageQueue::Dequeue(Message &aMessage) if (&aMessage == GetTail()) { - SetTail(NULL); + SetTail(nullptr); } } aMessage.Prev()->Next() = aMessage.Next(); aMessage.Next()->Prev() = aMessage.Prev(); - aMessage.Prev() = NULL; - aMessage.Next() = NULL; + aMessage.Prev() = nullptr; + aMessage.Next() = nullptr; - aMessage.SetMessageQueue(NULL); + aMessage.SetMessageQueue(nullptr); } void MessageQueue::GetInfo(uint16_t &aMessageCount, uint16_t &aBufferCount) const @@ -854,7 +854,7 @@ void MessageQueue::GetInfo(uint16_t &aMessageCount, uint16_t &aBufferCount) cons aMessageCount = 0; aBufferCount = 0; - for (const Message *message = GetHead(); message != NULL; message = message->GetNext()) + for (const Message *message = GetHead(); message != nullptr; message = message->GetNext()) { aMessageCount++; aBufferCount += message->GetBufferCount(); @@ -865,20 +865,20 @@ PriorityQueue::PriorityQueue(void) { for (int priority = 0; priority < Message::kNumPriorities; priority++) { - mTails[priority] = NULL; + mTails[priority] = nullptr; } } Message *PriorityQueue::FindFirstNonNullTail(Message::Priority aStartPriorityLevel) const { - Message *tail = NULL; + Message *tail = nullptr; uint8_t priority; priority = static_cast(aStartPriorityLevel); do { - if (mTails[priority] != NULL) + if (mTails[priority] != nullptr) { tail = mTails[priority]; break; @@ -896,7 +896,7 @@ Message *PriorityQueue::GetHead(void) const tail = FindFirstNonNullTail(Message::kPriorityLow); - return (tail == NULL) ? NULL : tail->Next(); + return (tail == nullptr) ? nullptr : tail->Next(); } Message *PriorityQueue::GetHeadForPriority(Message::Priority aPriority) const @@ -904,17 +904,17 @@ Message *PriorityQueue::GetHeadForPriority(Message::Priority aPriority) const Message *head; Message *previousTail; - if (mTails[aPriority] != NULL) + if (mTails[aPriority] != nullptr) { previousTail = FindFirstNonNullTail(static_cast(PrevPriority(aPriority))); - OT_ASSERT(previousTail != NULL); + OT_ASSERT(previousTail != nullptr); head = previousTail->Next(); } else { - head = NULL; + head = nullptr; } return head; @@ -939,7 +939,7 @@ void PriorityQueue::Enqueue(Message &aMessage) tail = FindFirstNonNullTail(priority); - if (tail != NULL) + if (tail != nullptr) { next = tail->Next(); @@ -974,7 +974,7 @@ void PriorityQueue::Dequeue(Message &aMessage) if ((&aMessage == tail) || (tail->GetPriority() != priority)) { - tail = NULL; + tail = nullptr; } mTails[priority] = tail; @@ -982,10 +982,10 @@ void PriorityQueue::Dequeue(Message &aMessage) aMessage.Next()->Prev() = aMessage.Prev(); aMessage.Prev()->Next() = aMessage.Next(); - aMessage.Next() = NULL; - aMessage.Prev() = NULL; + aMessage.Next() = nullptr; + aMessage.Prev() = nullptr; - aMessage.SetMessageQueue(NULL); + aMessage.SetMessageQueue(nullptr); } void PriorityQueue::GetInfo(uint16_t &aMessageCount, uint16_t &aBufferCount) const @@ -993,7 +993,7 @@ void PriorityQueue::GetInfo(uint16_t &aMessageCount, uint16_t &aBufferCount) con aMessageCount = 0; aBufferCount = 0; - for (const Message *message = GetHead(); message != NULL; message = message->GetNext()) + for (const Message *message = GetHead(); message != nullptr; message = message->GetNext()) { aMessageCount++; aBufferCount += message->GetBufferCount(); diff --git a/src/core/common/message.hpp b/src/core/common/message.hpp index f4cac407f..00bd5aa51 100644 --- a/src/core/common/message.hpp +++ b/src/core/common/message.hpp @@ -303,7 +303,7 @@ public: /** * This constructor initializes the `Settings` object from a given `otMessageSettings`. * - * @param[in] aSettings A pointer to `otMessageSettings` to covert from. If NULL default settings (link + * @param[in] aSettings A pointer to `otMessageSettings` to covert from. If nullptr default settings (link * security enabled with `kPriorityNormal` priority) would be used. * */ @@ -349,7 +349,7 @@ public: /** * This method returns a pointer to the next message. * - * @returns A pointer to the next message in the list or NULL if at the end of the list. + * @returns A pointer to the next message in the list or nullptr if at the end of the list. * */ Message *GetNext(void) const; @@ -546,7 +546,7 @@ public: * * @param[in] aLength Number of payload bytes to copy. * - * @returns A pointer to the message or NULL if insufficient message buffers are available. + * @returns A pointer to the message or nullptr if insufficient message buffers are available. * */ Message *Clone(uint16_t aLength) const; @@ -558,7 +558,7 @@ public: * `Type`, `SubType`, `LinkSecurity`, `Offset`, `InterfaceId`, and `Priority` fields on the cloned message are also * copied from the original one. * - * @returns A pointer to the message or NULL if insufficient message buffers are available. + * @returns A pointer to the message or nullptr if insufficient message buffers are available. * */ Message *Clone(void) const { return Clone(GetLength()); } @@ -835,23 +835,23 @@ public: /** * This method returns a pointer to the message queue (if any) where this message is queued. * - * @returns A pointer to the message queue or NULL if not in any message queue. + * @returns A pointer to the message queue or nullptr if not in any message queue. * */ MessageQueue *GetMessageQueue(void) const { - return (!GetMetadata().mInPriorityQ) ? GetMetadata().mQueue.mMessage : NULL; + return (!GetMetadata().mInPriorityQ) ? GetMetadata().mQueue.mMessage : nullptr; } /** * This method returns a pointer to the priority message queue (if any) where this message is queued. * - * @returns A pointer to the priority queue or NULL if not in any priority queue. + * @returns A pointer to the priority queue or nullptr if not in any priority queue. * */ PriorityQueue *GetPriorityQueue(void) const { - return (GetMetadata().mInPriorityQ) ? GetMetadata().mQueue.mPriority : NULL; + return (GetMetadata().mInPriorityQ) ? GetMetadata().mQueue.mPriority : nullptr; } /** @@ -930,7 +930,7 @@ private: * @returns `true` if the message is in any queue, `false` otherwise. * */ - bool IsInAQueue(void) const { return (GetMetadata().mQueue.mMessage != NULL); } + bool IsInAQueue(void) const { return (GetMetadata().mQueue.mMessage != nullptr); } /** * This method sets the message queue information for the message. @@ -1118,7 +1118,7 @@ public: * * @param[in] aPriority Priority level. * - * @returns A pointer to the first message with given priority level or NULL if there is no messages with + * @returns A pointer to the first message with given priority level or nullptr if there is no messages with * this priority level. * */ @@ -1172,12 +1172,12 @@ private: } /** - * This private method finds the first non-NULL tail starting from the given priority level and moving forward. + * This private method finds the first non-nullptr tail starting from the given priority level and moving forward. * It wraps from priority value `kNumPriorities` -1 back to 0. * * aStartPriorityLevel Starting priority level. * - * @returns The first non-NULL tail pointer, or NULL if all the + * @returns The first non-nullptr tail pointer, or nullptr if all the * */ Message *FindFirstNonNullTail(Message::Priority aStartPriorityLevel) const; @@ -1212,7 +1212,7 @@ public: * @param[in] aReserveHeader The number of header bytes to reserve. * @param[in] aPriority The priority level of the message. * - * @returns A pointer to the message or NULL if no message buffers are available. + * @returns A pointer to the message or nullptr if no message buffers are available. * */ Message *New(Message::Type aType, uint16_t aReserveHeader, Message::Priority aPriority); @@ -1225,7 +1225,7 @@ public: * @param[in] aReserveHeader The number of header bytes to reserve. * @param[in] aSettings The message settings. * - * @returns A pointer to the message or NULL if no message buffers are available. + * @returns A pointer to the message or nullptr if no message buffers are available. * */ Message *New(Message::Type aType, diff --git a/src/core/common/notifier.cpp b/src/core/common/notifier.cpp index d1fd8c9b9..d8463addd 100644 --- a/src/core/common/notifier.cpp +++ b/src/core/common/notifier.cpp @@ -42,7 +42,7 @@ namespace ot { Notifier::Receiver::Receiver(Instance &aInstance, Handler aHandler) : mHandler(aHandler) - , mNext(NULL) + , mNext(nullptr) { aInstance.Get().RegisterReceiver(*this); } @@ -56,8 +56,8 @@ Notifier::Notifier(Instance &aInstance) { for (unsigned int i = 0; i < kMaxExternalHandlers; i++) { - mExternalCallbacks[i].mHandler = NULL; - mExternalCallbacks[i].mContext = NULL; + mExternalCallbacks[i].mHandler = nullptr; + mExternalCallbacks[i].mContext = nullptr; } } @@ -69,17 +69,17 @@ void Notifier::RegisterReceiver(Receiver &aReceiver) otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aContext) { otError error = OT_ERROR_NONE; - ExternalCallback *unusedCallback = NULL; + ExternalCallback *unusedCallback = nullptr; - VerifyOrExit(aCallback != NULL, OT_NOOP); + VerifyOrExit(aCallback != nullptr, OT_NOOP); for (unsigned int i = 0; i < kMaxExternalHandlers; i++) { ExternalCallback &callback = mExternalCallbacks[i]; - if (callback.mHandler == NULL) + if (callback.mHandler == nullptr) { - if (unusedCallback == NULL) + if (unusedCallback == nullptr) { unusedCallback = &callback; } @@ -90,7 +90,7 @@ otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aCont VerifyOrExit((callback.mHandler != aCallback) || (callback.mContext != aContext), error = OT_ERROR_ALREADY); } - VerifyOrExit(unusedCallback != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(unusedCallback != nullptr, error = OT_ERROR_NO_BUFS); unusedCallback->mHandler = aCallback; unusedCallback->mContext = aContext; @@ -101,7 +101,7 @@ exit: void Notifier::RemoveCallback(otStateChangedCallback aCallback, void *aContext) { - VerifyOrExit(aCallback != NULL, OT_NOOP); + VerifyOrExit(aCallback != nullptr, OT_NOOP); for (unsigned int i = 0; i < kMaxExternalHandlers; i++) { @@ -109,8 +109,8 @@ void Notifier::RemoveCallback(otStateChangedCallback aCallback, void *aContext) if ((callback.mHandler == aCallback) && (callback.mContext == aContext)) { - callback.mHandler = NULL; - callback.mContext = NULL; + callback.mHandler = nullptr; + callback.mContext = nullptr; } } @@ -152,7 +152,7 @@ void Notifier::EmitEvents(void) LogEvents(events); - for (Receiver *receiver = mReceivers.GetHead(); receiver != NULL; receiver = receiver->GetNext()) + for (Receiver *receiver = mReceivers.GetHead(); receiver != nullptr; receiver = receiver->GetNext()) { receiver->Emit(events); } @@ -161,7 +161,7 @@ void Notifier::EmitEvents(void) { ExternalCallback &callback = mExternalCallbacks[i]; - if (callback.mHandler != NULL) + if (callback.mHandler != nullptr) { callback.mHandler(events.GetAsFlags(), callback.mContext); } diff --git a/src/core/common/random_manager.cpp b/src/core/common/random_manager.cpp index e6ee45d62..2ffd0820b 100644 --- a/src/core/common/random_manager.cpp +++ b/src/core/common/random_manager.cpp @@ -153,7 +153,7 @@ void RandomManager::Entropy::Init(void) mbedtls_entropy_init(&mEntropyContext); #ifndef OT_MBEDTLS_STRONG_DEFAULT_ENTROPY_PRESENT - mbedtls_entropy_add_source(&mEntropyContext, &RandomManager::Entropy::HandleMbedtlsEntropyPoll, NULL, + mbedtls_entropy_add_source(&mEntropyContext, &RandomManager::Entropy::HandleMbedtlsEntropyPoll, nullptr, MBEDTLS_ENTROPY_MIN_HARDWARE, MBEDTLS_ENTROPY_SOURCE_STRONG); #endif // OT_MBEDTLS_STRONG_DEFAULT_ENTROPY_PRESENT } @@ -175,7 +175,7 @@ int RandomManager::Entropy::HandleMbedtlsEntropyPoll(void * aData, SuccessOrExit(otPlatEntropyGet(reinterpret_cast(aOutput), static_cast(aInLen))); rval = 0; - VerifyOrExit(aOutLen != NULL, OT_NOOP); + VerifyOrExit(aOutLen != nullptr, OT_NOOP); *aOutLen = aInLen; exit: @@ -191,7 +191,7 @@ exit: void RandomManager::CryptoCtrDrbg::Init(void) { mbedtls_ctr_drbg_init(&mCtrDrbg); - mbedtls_ctr_drbg_seed(&mCtrDrbg, mbedtls_entropy_func, RandomManager::GetMbedTlsEntropyContext(), NULL, 0); + mbedtls_ctr_drbg_seed(&mCtrDrbg, mbedtls_entropy_func, RandomManager::GetMbedTlsEntropyContext(), nullptr, 0); } void RandomManager::CryptoCtrDrbg::Deinit(void) diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 9ae472a58..37b867c88 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -76,7 +76,7 @@ public: * * @param[in] aKey The key associated with the value. * @param[in] aValue A pointer to where the new value of the setting should be read from. - * MUST NOT be NULL if @p aValueLength is non-zero. + * MUST NOT be nullptr if @p aValueLength is non-zero. * @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero. * * @retval OT_ERROR_NONE The value was added. @@ -104,12 +104,12 @@ public: * @param[in] aKey The key associated with the requested value. * @param[in] aIndex The index of the specific item to get. * @param[out] aValue A pointer to where the value of the setting should be written. - * May be NULL if just testing for the presence or length of a key. + * May be nullptr if just testing for the presence or length of a key. * @param[inout] aValueLength A pointer to the length of the value. * When called, this should point to an integer containing the maximum bytes that * can be written to @p aValue. * At return, the actual length of the setting is written. - * May be NULL if performing a presence check. + * May be nullptr if performing a presence check. * * @retval OT_ERROR_NONE The value was fetched successfully. * @retval OT_ERROR_NOT_FOUND The key was not found. @@ -125,7 +125,7 @@ public: * * @param[in] aKey The key associated with the value. * @param[in] aValue A pointer to where the new value of the setting should be read from. - * MUST NOT be NULL if @p aValueLength is non-zero. + * MUST NOT be nullptr if @p aValueLength is non-zero. * @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero. * * @retval OT_ERROR_NONE The value was changed. diff --git a/src/core/common/string.hpp b/src/core/common/string.hpp index 2e79e326c..d15d24a88 100644 --- a/src/core/common/string.hpp +++ b/src/core/common/string.hpp @@ -57,12 +57,13 @@ namespace ot { */ /** - * This function returns the number of characters that precede the terminating NULL character. + * This function returns the number of characters that precede the terminating nullptr character. * * @param[in] aString A pointer to the string. * @param[in] aMaxLength The maximum length in bytes. * - * @returns The number of characters that precede the terminating NULL character or @p aMaxLength, whichever is smaller. + * @returns The number of characters that precede the terminating nullptr character or @p aMaxLength, whichever is + * smaller. * */ uint16_t StringLength(const char *aString, uint16_t aMaxLength); diff --git a/src/core/common/tasklet.cpp b/src/core/common/tasklet.cpp index 9d2c1a3c1..de8bab9f5 100644 --- a/src/core/common/tasklet.cpp +++ b/src/core/common/tasklet.cpp @@ -45,7 +45,7 @@ Tasklet::Tasklet(Instance &aInstance, Handler aHandler, void *aOwner) : InstanceLocator(aInstance) , OwnerLocator(aOwner) , mHandler(aHandler) - , mNext(NULL) + , mNext(nullptr) { } @@ -58,7 +58,7 @@ void Tasklet::Post(void) } TaskletScheduler::TaskletScheduler(void) - : mTail(NULL) + : mTail(nullptr) { } @@ -66,7 +66,7 @@ void TaskletScheduler::PostTasklet(Tasklet &aTasklet) { // Tasklets are saved in a circular singly linked list. - if (mTail == NULL) + if (mTail == nullptr) { mTail = &aTasklet; mTail->mNext = mTail; @@ -86,26 +86,26 @@ void TaskletScheduler::ProcessQueuedTasklets(void) // This method processes all tasklets queued when this is called. We // keep a copy the current list and then clear the main list by - // setting `mTail` to NULL. A newly posted tasklet while processing + // setting `mTail` to nullptr. A newly posted tasklet while processing // the currently queued tasklets will then trigger a call to // `otTaskletsSignalPending()`. - mTail = NULL; + mTail = nullptr; - while (tail != NULL) + while (tail != nullptr) { Tasklet *tasklet = tail->mNext; if (tasklet == tail) { - tail = NULL; + tail = nullptr; } else { tail->mNext = tasklet->mNext; } - tasklet->mNext = NULL; + tasklet->mNext = nullptr; tasklet->RunTask(); } } diff --git a/src/core/common/tasklet.hpp b/src/core/common/tasklet.hpp index cc5f666c2..ade2722ab 100644 --- a/src/core/common/tasklet.hpp +++ b/src/core/common/tasklet.hpp @@ -99,7 +99,7 @@ public: * @retval FALSE The tasklet is not posted. * */ - bool IsPosted(void) const { return (mNext != NULL); } + bool IsPosted(void) const { return (mNext != nullptr); } private: void RunTask(void) { mHandler(*this); } @@ -168,7 +168,7 @@ public: * @retval FALSE If there are no tasklets pending. * */ - bool AreTaskletsPending(void) const { return mTail != NULL; } + bool AreTaskletsPending(void) const { return mTail != nullptr; } /** * This method processes all tasklets queued when this is called. diff --git a/src/core/common/timer.cpp b/src/core/common/timer.cpp index 3233bb79a..2a0ad2f60 100644 --- a/src/core/common/timer.cpp +++ b/src/core/common/timer.cpp @@ -100,7 +100,7 @@ void TimerMilli::Stop(void) void TimerScheduler::Add(Timer &aTimer, const AlarmApi &aAlarmApi) { - Timer *prev = NULL; + Timer *prev = nullptr; Time now(aAlarmApi.AlarmGetNow()); Remove(aTimer, aAlarmApi); @@ -113,7 +113,7 @@ void TimerScheduler::Add(Timer &aTimer, const AlarmApi &aAlarmApi) } } - if (prev == NULL) + if (prev == nullptr) { mTimerList.Push(aTimer); SetAlarm(aAlarmApi); diff --git a/src/core/common/tlvs.cpp b/src/core/common/tlvs.cpp index 8dd90695d..447c34701 100644 --- a/src/core/common/tlvs.cpp +++ b/src/core/common/tlvs.cpp @@ -73,7 +73,7 @@ otError Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, uint16_t offset; uint16_t size; - SuccessOrExit(error = Find(aMessage, aType, &offset, &size, NULL)); + SuccessOrExit(error = Find(aMessage, aType, &offset, &size, nullptr)); if (aMaxSize > size) { @@ -88,7 +88,7 @@ exit: otError Tlv::FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset) { - return Find(aMessage, aType, &aOffset, NULL, NULL); + return Find(aMessage, aType, &aOffset, nullptr, nullptr); } otError Tlv::FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength) @@ -150,17 +150,17 @@ otError Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uin if (tlv.GetType() == aType) { - if (aOffset != NULL) + if (aOffset != nullptr) { *aOffset = offset; } - if (aSize != NULL) + if (aSize != nullptr) { *aSize = static_cast(size); } - if (aIsExtendedTlv != NULL) + if (aIsExtendedTlv != nullptr) { *aIsExtendedTlv = (tlv.mLength == kExtendedLength); } diff --git a/src/core/common/tlvs.hpp b/src/core/common/tlvs.hpp index d3039c88f..8fe2cd45c 100644 --- a/src/core/common/tlvs.hpp +++ b/src/core/common/tlvs.hpp @@ -412,7 +412,7 @@ private: * This private static method searches within a given message for TLV type and outputs the TLV offset, size and * whether it is an Extended TLV. * - * A NULL pointer can be used for output parameters @p aOffset, @p aSize, or @p aIsExtendedTlv if the parameter + * A nullptr pointer can be used for output parameters @p aOffset, @p aSize, or @p aIsExtendedTlv if the parameter * is not required. * * @param[in] aMessage A reference to the message to search within. diff --git a/src/core/common/trickle_timer.cpp b/src/core/common/trickle_timer.cpp index aed66a0d3..cbfb2ee02 100644 --- a/src/core/common/trickle_timer.cpp +++ b/src/core/common/trickle_timer.cpp @@ -61,7 +61,7 @@ TrickleTimer::TrickleTimer(Instance &aInstance, , mIsRunning(false) , mInTransmitPhase(false) { - OT_ASSERT(aTransmitHandler != NULL); + OT_ASSERT(aTransmitHandler != nullptr); } void TrickleTimer::Start(uint32_t aIntervalMin, uint32_t aIntervalMax, Mode aMode) diff --git a/src/core/crypto/ecdsa.cpp b/src/core/crypto/ecdsa.cpp index 10f80a863..3b50ee0f4 100644 --- a/src/core/crypto/ecdsa.cpp +++ b/src/core/crypto/ecdsa.cpp @@ -66,12 +66,12 @@ otError Ecdsa::Sign(uint8_t * aOutput, mbedtls_mpi_init(&sMpi); // Parse a private key in PEM format. - VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, NULL, 0) == 0, + VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, nullptr, 0) == 0, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(mbedtls_pk_get_type(&pkCtx) == MBEDTLS_PK_ECKEY, error = OT_ERROR_INVALID_ARGS); keypair = mbedtls_pk_ec(pkCtx); - OT_ASSERT(keypair != NULL); + OT_ASSERT(keypair != nullptr); VerifyOrExit(mbedtls_ecdsa_from_keypair(&ctx, keypair) == 0, error = OT_ERROR_FAILED); diff --git a/src/core/crypto/hmac_sha256.cpp b/src/core/crypto/hmac_sha256.cpp index 2d981c9d9..0187d996f 100644 --- a/src/core/crypto/hmac_sha256.cpp +++ b/src/core/crypto/hmac_sha256.cpp @@ -38,7 +38,7 @@ namespace Crypto { HmacSha256::HmacSha256(void) { - const mbedtls_md_info_t *mdInfo = NULL; + const mbedtls_md_info_t *mdInfo = nullptr; mbedtls_md_init(&mContext); mdInfo = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256); mbedtls_md_setup(&mContext, mdInfo, 1); diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index 43cb7f020..ac1371646 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -581,7 +581,7 @@ otError Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, siz { if (strcmp(aArgs[0], sCommands[i].mName) == 0) { - error = (this->*sCommands[i].mCommand)(aArgsLength - 1, (aArgsLength > 1) ? &aArgs[1] : NULL, aOutput, + error = (this->*sCommands[i].mCommand)(aArgsLength - 1, (aArgsLength > 1) ? &aArgs[1] : nullptr, aOutput, aOutputMaxLen); ExitNow(); } diff --git a/src/core/diags/factory_diags.hpp b/src/core/diags/factory_diags.hpp index cc0352d7e..3c3dd4129 100644 --- a/src/core/diags/factory_diags.hpp +++ b/src/core/diags/factory_diags.hpp @@ -62,7 +62,7 @@ public: /** * This method processes a factory diagnostics command line. * - * @param[in] aString A NULL-terminated input string. + * @param[in] aString A null-terminated input string. * @param[out] aOutput The diagnostics execution result. * @param[in] aOutputMaxLen The output buffer size. * @@ -102,7 +102,7 @@ public: /** * The radio driver calls this method to notify OpenThread diagnostics module of a received frame. * - * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed. * @param[in] aError OT_ERROR_NONE when successfully received a frame, * OT_ERROR_ABORT when reception was aborted and a frame was not received, * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. diff --git a/src/core/mac/data_poll_handler.cpp b/src/core/mac/data_poll_handler.cpp index cb4de8246..8676504bc 100644 --- a/src/core/mac/data_poll_handler.cpp +++ b/src/core/mac/data_poll_handler.cpp @@ -71,7 +71,7 @@ inline void DataPollHandler::Callbacks::HandleFrameChangeDone(Child &aChild) DataPollHandler::DataPollHandler(Instance &aInstance) : InstanceLocator(aInstance) - , mIndirectTxChild(NULL) + , mIndirectTxChild(nullptr) , mFrameContext() , mCallbacks(aInstance) { @@ -88,7 +88,7 @@ void DataPollHandler::Clear(void) child.ResetIndirectTxAttempts(); } - mIndirectTxChild = NULL; + mIndirectTxChild = nullptr; } void DataPollHandler::HandleNewFrame(Child &aChild) @@ -135,7 +135,7 @@ void DataPollHandler::HandleDataPoll(Mac::RxFrame &aFrame) SuccessOrExit(aFrame.GetSrcAddr(macSource)); child = Get().FindChild(macSource, Child::kInStateValidOrRestoring); - VerifyOrExit(child != NULL, OT_NOOP); + VerifyOrExit(child != nullptr, OT_NOOP); child->SetLastHeard(TimerMilli::GetNow()); child->ResetLinkFailures(); @@ -154,7 +154,7 @@ void DataPollHandler::HandleDataPoll(Mac::RxFrame &aFrame) ExitNow(); } - if (mIndirectTxChild == NULL) + if (mIndirectTxChild == nullptr) { mIndirectTxChild = child; Get().RequestIndirectFrameTransmission(); @@ -172,7 +172,7 @@ otError DataPollHandler::HandleFrameRequest(Mac::TxFrame &aFrame) { otError error = OT_ERROR_NONE; - VerifyOrExit(mIndirectTxChild != NULL, error = OT_ERROR_ABORT); + VerifyOrExit(mIndirectTxChild != nullptr, error = OT_ERROR_ABORT); SuccessOrExit(error = mCallbacks.PrepareFrameForChild(aFrame, mFrameContext, *mIndirectTxChild)); @@ -204,9 +204,9 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError { Child *child = mIndirectTxChild; - VerifyOrExit(child != NULL, OT_NOOP); + VerifyOrExit(child != nullptr, OT_NOOP); - mIndirectTxChild = NULL; + mIndirectTxChild = nullptr; HandleSentFrame(aFrame, aError, *child); exit: @@ -300,13 +300,13 @@ void DataPollHandler::ProcessPendingPolls(void) // Find the child with earliest poll receive time. - if ((mIndirectTxChild == NULL) || (child->GetLastHeard() < mIndirectTxChild->GetLastHeard())) + if ((mIndirectTxChild == nullptr) || (child->GetLastHeard() < mIndirectTxChild->GetLastHeard())) { mIndirectTxChild = child; } } - if (mIndirectTxChild != NULL) + if (mIndirectTxChild != nullptr) { mIndirectTxChild->SetDataPollPending(false); Get().RequestIndirectFrameTransmission(); diff --git a/src/core/mac/data_poll_handler.hpp b/src/core/mac/data_poll_handler.hpp index 4fcbd34f0..91762e4b2 100644 --- a/src/core/mac/data_poll_handler.hpp +++ b/src/core/mac/data_poll_handler.hpp @@ -268,7 +268,7 @@ private: // In the current implementation of `DataPollHandler`, we can have a // single indirect tx operation active at MAC layer at each point of - // time. `mIndirectTxChild` indicates the child being handled (NULL + // time. `mIndirectTxChild` indicates the child being handled (nullptr // indicates no active indirect tx). `mFrameContext` tracks the // context for the prepared frame for the current indirect tx. diff --git a/src/core/mac/link_raw.cpp b/src/core/mac/link_raw.cpp index 1eea09f29..9fa17ceed 100644 --- a/src/core/mac/link_raw.cpp +++ b/src/core/mac/link_raw.cpp @@ -53,9 +53,9 @@ LinkRaw::LinkRaw(Instance &aInstance) : InstanceLocator(aInstance) , mReceiveChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL) , mPanId(kPanIdBroadcast) - , mReceiveDoneCallback(NULL) - , mTransmitDoneCallback(NULL) - , mEnergyScanDoneCallback(NULL) + , mReceiveDoneCallback(nullptr) + , mTransmitDoneCallback(nullptr) + , mEnergyScanDoneCallback(nullptr) #if OPENTHREAD_RADIO , mSubMac(aInstance) #elif OPENTHREAD_CONFIG_LINK_RAW_ENABLE @@ -148,7 +148,7 @@ exit: void LinkRaw::InvokeReceiveDone(RxFrame *aFrame, otError aError) { - otLogDebgMac("LinkRaw::ReceiveDone(%d bytes), error:%s", (aFrame != NULL) ? aFrame->mLength : 0, + otLogDebgMac("LinkRaw::ReceiveDone(%d bytes), error:%s", (aFrame != nullptr) ? aFrame->mLength : 0, otThreadErrorToString(aError)); if (mReceiveDoneCallback && (aError == OT_ERROR_NONE)) @@ -177,7 +177,7 @@ void LinkRaw::InvokeTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aE if (mTransmitDoneCallback) { mTransmitDoneCallback(&GetInstance(), &aFrame, aAckFrame, aError); - mTransmitDoneCallback = NULL; + mTransmitDoneCallback = nullptr; } } @@ -196,10 +196,10 @@ exit: void LinkRaw::InvokeEnergyScanDone(int8_t aEnergyScanMaxRssi) { - if (IsEnabled() && mEnergyScanDoneCallback != NULL) + if (IsEnabled() && mEnergyScanDoneCallback != nullptr) { mEnergyScanDoneCallback(&GetInstance(), aEnergyScanMaxRssi); - mEnergyScanDoneCallback = NULL; + mEnergyScanDoneCallback = nullptr; } } diff --git a/src/core/mac/link_raw.hpp b/src/core/mac/link_raw.hpp index 4bcec7772..5de185491 100644 --- a/src/core/mac/link_raw.hpp +++ b/src/core/mac/link_raw.hpp @@ -107,7 +107,7 @@ public: /** * This method invokes the mReceiveDoneCallback, if set. * - * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed. * @param[in] aError OT_ERROR_NONE when successfully received a frame, * OT_ERROR_ABORT when reception was aborted and a frame was not received, * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. @@ -140,7 +140,7 @@ public: * This method invokes the mTransmitDoneCallback, if set. * * @param[in] aFrame The transmitted frame. - * @param[in] aAckFrame A pointer to the ACK frame, NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel, @@ -281,7 +281,7 @@ public: * of a frame transmission request, this method is invoked on all frame transmission attempts. * * @param[in] aFrame The transmitted frame. - * @param[in] aAckFrame A pointer to the ACK frame, or NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel, diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 7384fa6df..7f4c659dc 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -112,12 +112,12 @@ Mac::Mac(Instance &aInstance) #if OPENTHREAD_FTD , mMaxFrameRetriesIndirect(kDefaultMaxFrameRetriesIndirect) #endif - , mActiveScanHandler(NULL) // Initialize `mActiveScanHandler` and `mEnergyScanHandler` union - , mScanHandlerContext(NULL) + , mActiveScanHandler(nullptr) // Initialize `mActiveScanHandler` and `mEnergyScanHandler` union + , mScanHandlerContext(nullptr) , mSubMac(aInstance) , mOperationTask(aInstance, &Mac::HandleOperationTask, this) , mTimer(aInstance, Mac::HandleTimer, this) - , mOobFrame(NULL) + , mOobFrame(nullptr) , mKeyIdMode2FrameCounter(0) , mCcaSampleCount(0) #if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE @@ -229,13 +229,13 @@ otError Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, Active { otError error = OT_ERROR_NONE; Address address; - const Beacon * beacon = NULL; - const BeaconPayload *beaconPayload = NULL; + const Beacon * beacon = nullptr; + const BeaconPayload *beaconPayload = nullptr; uint16_t payloadLength; memset(&aResult, 0, sizeof(ActiveScanResult)); - VerifyOrExit(aBeaconFrame != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aBeaconFrame != nullptr, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aBeaconFrame->GetType() == Frame::kFcfFrameBeacon, error = OT_ERROR_PARSE); SuccessOrExit(error = aBeaconFrame->GetSrcAddr(address)); @@ -290,18 +290,18 @@ void Mac::PerformActiveScan(void) { mSubMac.SetPanId(mPanId); FinishOperation(); - ReportActiveScanResult(NULL); + ReportActiveScanResult(nullptr); PerformNextOperation(); } } void Mac::ReportActiveScanResult(const RxFrame *aBeaconFrame) { - VerifyOrExit(mActiveScanHandler != NULL, OT_NOOP); + VerifyOrExit(mActiveScanHandler != nullptr, OT_NOOP); - if (aBeaconFrame == NULL) + if (aBeaconFrame == nullptr) { - mActiveScanHandler(NULL, mScanHandlerContext); + mActiveScanHandler(nullptr, mScanHandlerContext); } else { @@ -341,9 +341,9 @@ exit: { FinishOperation(); - if (mEnergyScanHandler != NULL) + if (mEnergyScanHandler != nullptr) { - mEnergyScanHandler(NULL, mScanHandlerContext); + mEnergyScanHandler(nullptr, mScanHandlerContext); } PerformNextOperation(); @@ -354,7 +354,7 @@ void Mac::ReportEnergyScanResult(int8_t aRssi) { EnergyScanResult result; - VerifyOrExit((mEnergyScanHandler != NULL) && (aRssi != kInvalidRssiValue), OT_NOOP); + VerifyOrExit((mEnergyScanHandler != nullptr) && (aRssi != kInvalidRssiValue), OT_NOOP); result.mChannel = mScanChannel; result.mMaxRssi = aRssi; @@ -566,7 +566,7 @@ otError Mac::RequestOutOfBandFrameTransmission(otRadioFrame *aOobFrame) { otError error = OT_ERROR_NONE; - VerifyOrExit(aOobFrame != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aOobFrame != nullptr, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(!mPendingTransmitOobFrame && (mOperation != kOperationTransmitOutOfBandFrame), error = OT_ERROR_ALREADY); @@ -872,8 +872,8 @@ void Mac::PrepareBeacon(TxFrame &aFrame) { uint8_t beaconLength; uint16_t fcf; - Beacon * beacon = NULL; - BeaconPayload *beaconPayload = NULL; + Beacon * beacon = nullptr; + BeaconPayload *beaconPayload = nullptr; fcf = Frame::kFcfFrameBeacon | Frame::kFcfDstAddrNone | Frame::kFcfSrcAddrExt; aFrame.InitMacHeader(fcf, Frame::kSecNone); @@ -949,7 +949,7 @@ void Mac::ProcessTransmitSecurity(TxFrame &aFrame) { KeyManager & keyManager = Get(); uint8_t keyIdMode; - const ExtAddress *extAddress = NULL; + const ExtAddress *extAddress = nullptr; VerifyOrExit(aFrame.GetSecurityEnabled(), OT_NOOP); @@ -1114,7 +1114,7 @@ exit: // the radio platform aborting the tx operation. sendFrame.SetLength(0); - HandleTransmitDone(sendFrame, NULL, OT_ERROR_ABORT); + HandleTransmitDone(sendFrame, nullptr, OT_ERROR_ABORT); } } @@ -1156,7 +1156,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame, // Record frame transmission success/failure state (for a neighbor). - if ((neighbor != NULL) && ackRequested) + if ((neighbor != nullptr) && ackRequested) { bool frameTxSuccess = true; @@ -1201,7 +1201,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame, // Update neighbor's RSSI link info from the received Ack. - if ((aError == OT_ERROR_NONE) && ackRequested && (aAckFrame != NULL) && (neighbor != NULL)) + if ((aError == OT_ERROR_NONE) && ackRequested && (aAckFrame != nullptr) && (neighbor != nullptr)) { neighbor->GetLinkInfo().AddRss(aAckFrame->GetRssi()); } @@ -1289,7 +1289,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError case kOperationTransmitPoll: OT_ASSERT(aFrame.IsEmpty() || aFrame.GetAckRequest()); - if ((aError == OT_ERROR_NONE) && (aAckFrame != NULL)) + if ((aError == OT_ERROR_NONE) && (aAckFrame != nullptr)) { bool framePending = aAckFrame->GetFramePending(); @@ -1327,7 +1327,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError Get().HandleSentFrame(aFrame, aError); #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 if (aError == OT_ERROR_NONE && Get().GetParent().IsEnhancedKeepAliveSupported() && - aFrame.GetSecurityEnabled() && aAckFrame != NULL) + aFrame.GetSecurityEnabled() && aAckFrame != nullptr) { Get().ProcessFrame(*aAckFrame); } @@ -1445,7 +1445,7 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne break; case Frame::kKeyIdMode1: - VerifyOrExit(aNeighbor != NULL, OT_NOOP); + VerifyOrExit(aNeighbor != nullptr, OT_NOOP); IgnoreError(aFrame.GetKeyId(keyid)); keyid--; @@ -1556,7 +1556,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) mCounters.mRxTotal++; SuccessOrExit(error); - VerifyOrExit(aFrame != NULL, error = OT_ERROR_NO_FRAME_RECEIVED); + VerifyOrExit(aFrame != nullptr, error = OT_ERROR_NO_FRAME_RECEIVED); VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE); // Ensure we have a valid frame before attempting to read any contents of @@ -1581,7 +1581,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) #if OPENTHREAD_FTD // Allow multicasts from neighbor routers if FTD - if (neighbor == NULL && dstaddr.IsBroadcast() && Get().IsFullThreadDevice()) + if (neighbor == nullptr && dstaddr.IsBroadcast() && Get().IsFullThreadDevice()) { neighbor = Get().GetRxOnlyNeighborRouter(srcaddr); } @@ -1605,7 +1605,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) case Address::kTypeShort: otLogDebgMac("Received frame from short address 0x%04x", srcaddr.GetShort()); - VerifyOrExit(neighbor != NULL, error = OT_ERROR_UNKNOWN_NEIGHBOR); + VerifyOrExit(neighbor != nullptr, error = OT_ERROR_UNKNOWN_NEIGHBOR); srcaddr.SetExtended(neighbor->GetExtAddress()); @@ -1628,7 +1628,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) // Clear any previous link info to ensure the fixed RSSI // value takes effect quickly. - if (neighbor != NULL) + if (neighbor != nullptr) { neighbor->GetLinkInfo().Clear(); } @@ -1680,7 +1680,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) Get().ProcessFrame(*aFrame); - if (neighbor != NULL) + if (neighbor != nullptr) { neighbor->GetLinkInfo().AddRss(aFrame->GetRssi()); @@ -1989,7 +1989,7 @@ void Mac::LogFrameRxFailure(const RxFrame *aFrame, otError aError) const break; } - if (aFrame == NULL) + if (aFrame == nullptr) { otLogMac(logLevel, "Frame rx failed, error:%s", otThreadErrorToString(aError)); } @@ -2037,10 +2037,10 @@ uint8_t Mac::GetTimeIeOffset(const Frame &aFrame) { uint8_t offset = 0; const uint8_t *base = aFrame.GetPsdu(); - const uint8_t *cur = NULL; + const uint8_t *cur = nullptr; cur = reinterpret_cast(aFrame.GetTimeIe()); - VerifyOrExit(cur != NULL, OT_NOOP); + VerifyOrExit(cur != nullptr, OT_NOOP); cur += sizeof(VendorIeHeader); offset = static_cast(cur - base); diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 838681bd5..c2ae35d06 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -227,7 +227,7 @@ public: * @retval OT_ERROR_NONE Successfully scheduled the frame transmission. * @retval OT_ERROR_ALREADY MAC layer is busy sending a previously requested frame. * @retval OT_ERROR_INVALID_STATE The MAC layer is not enabled. - * @retval OT_ERROR_INVALID_ARGS The argument @p aOobFrame is NULL. + * @retval OT_ERROR_INVALID_ARGS The argument @p aOobFrame is nullptr. * */ otError RequestOutOfBandFrameTransmission(otRadioFrame *aOobFrame); @@ -465,7 +465,7 @@ public: /** * This method is called to handle a received frame. * - * @param[in] aFrame A pointer to the received frame, or NULL if the receive operation was aborted. + * @param[in] aFrame A pointer to the received frame, or nullptr if the receive operation was aborted. * @param[in] aError OT_ERROR_NONE when successfully received a frame, * OT_ERROR_ABORT when reception was aborted and a frame was not received. * @@ -488,7 +488,7 @@ public: * of a frame transmission request, this method is invoked on all frame transmission attempts. * * @param[in] aFrame The transmitted frame. - * @param[in] aAckFrame A pointer to the ACK frame, or NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel, @@ -508,7 +508,7 @@ public: * This method is called to handle transmit events. * * @param[in] aFrame The frame that was transmitted. - * @param[in] aAckFrame A pointer to the ACK frame, NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE when the tx failed due to activity on the channel, @@ -553,7 +553,7 @@ public: * This method registers a callback to provide received raw IEEE 802.15.4 frames. * * @param[in] aPcapCallback A pointer to a function that is called when receiving an IEEE 802.15.4 link frame - * or NULL to disable the callback. + * or nullptr to disable the callback. * @param[in] aCallbackContext A pointer to application-specific context. * */ diff --git a/src/core/mac/mac_filter.cpp b/src/core/mac/mac_filter.cpp index 3ef079545..3120075e5 100644 --- a/src/core/mac/mac_filter.cpp +++ b/src/core/mac/mac_filter.cpp @@ -63,7 +63,7 @@ Filter::FilterEntry *Filter::FindEntry(const ExtAddress &aExtAddress) } } - entry = NULL; + entry = nullptr; exit: return entry; @@ -78,7 +78,7 @@ Filter::FilterEntry *Filter::FindAvailableEntry(void) VerifyOrExit(entry->IsInUse(), OT_NOOP); } - entry = NULL; + entry = nullptr; exit: return entry; @@ -103,9 +103,9 @@ otError Filter::AddAddress(const ExtAddress &aExtAddress) otError error = OT_ERROR_NONE; FilterEntry *entry = FindEntry(aExtAddress); - if (entry == NULL) + if (entry == nullptr) { - VerifyOrExit((entry = FindAvailableEntry()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((entry = FindAvailableEntry()) != nullptr, error = OT_ERROR_NO_BUFS); entry->mExtAddress = aExtAddress; } @@ -121,7 +121,7 @@ otError Filter::RemoveAddress(const ExtAddress &aExtAddress) otError error = OT_ERROR_NONE; FilterEntry *entry = FindEntry(aExtAddress); - if (entry == NULL || !entry->mFiltered) + if (entry == nullptr || !entry->mFiltered) { ExitNow(error = OT_ERROR_NOT_FOUND); } @@ -166,15 +166,15 @@ otError Filter::AddRssIn(const ExtAddress *aExtAddress, int8_t aRss) otError error = OT_ERROR_NONE; FilterEntry *entry; - // Set the default RssIn when aExtAddress is not given (NULL) - VerifyOrExit(aExtAddress != NULL, mDefaultRssIn = aRss); + // Set the default RssIn when aExtAddress is not given (nullptr) + VerifyOrExit(aExtAddress != nullptr, mDefaultRssIn = aRss); entry = FindEntry(*aExtAddress); - if (entry == NULL) + if (entry == nullptr) { entry = FindAvailableEntry(); - VerifyOrExit(entry != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NO_BUFS); entry->mExtAddress = *aExtAddress; } @@ -191,10 +191,10 @@ otError Filter::RemoveRssIn(const ExtAddress *aExtAddress) FilterEntry *entry; // If no aExtAddress is given, remove default RssIn - VerifyOrExit(aExtAddress != NULL, mDefaultRssIn = kFixedRssDisabled); + VerifyOrExit(aExtAddress != nullptr, mDefaultRssIn = kFixedRssDisabled); entry = FindEntry(*aExtAddress); - VerifyOrExit(entry != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NOT_FOUND); entry->mRssIn = kFixedRssDisabled; exit: @@ -252,14 +252,14 @@ otError Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss) if (mAddressMode == OT_MAC_FILTER_ADDRESS_MODE_WHITELIST) { - VerifyOrExit(entry != NULL && entry->mFiltered, error = OT_ERROR_ADDRESS_FILTERED); + VerifyOrExit(entry != nullptr && entry->mFiltered, error = OT_ERROR_ADDRESS_FILTERED); } else if (mAddressMode == OT_MAC_FILTER_ADDRESS_MODE_BLACKLIST) { - VerifyOrExit(entry == NULL || !entry->mFiltered, error = OT_ERROR_ADDRESS_FILTERED); + VerifyOrExit(entry == nullptr || !entry->mFiltered, error = OT_ERROR_ADDRESS_FILTERED); } - if ((entry != NULL) && (entry->mRssIn != kFixedRssDisabled)) + if ((entry != nullptr) && (entry->mRssIn != kFixedRssDisabled)) { aRss = entry->mRssIn; } diff --git a/src/core/mac/mac_filter.hpp b/src/core/mac/mac_filter.hpp index 0480861cf..fc3f86a92 100644 --- a/src/core/mac/mac_filter.hpp +++ b/src/core/mac/mac_filter.hpp @@ -150,11 +150,12 @@ public: * This method sets the received signal strength for the messages from the Extended Address. * The default received signal strength for all received messages would be set if no Extended Address is specified. * - * @param[in] aExtAddress A pointer to the Extended Address, or NULL to set the default received signal strength. + * @param[in] aExtAddress A pointer to the Extended Address, or nullptr to set the default received signal + * strength. * @param[in] aRss The received signal strength to set. * * @retval OT_ERROR_NONE Successfully set @p aRss for @p aExtAddress, or - * set the default @p aRss for all received messages if @p aExtAddress is NULL. + * set the default @p aRss for all received messages if @p aExtAddress is nullptr. * @retval OT_ERROR_NO_BUFS No available entry exists. * */ @@ -168,8 +169,8 @@ public: * * @retval OT_ERROR_NONE Successfully removed the received signal strength setting for the received * messages from @p aExtAddress or removed the default received signal strength - * setting if @p aExtAddress is NULL. - * @retval OT_ERROR_NOT_FOUND @p aExtAddress is not in the RssIn filter if it is not NULL. + * setting if @p aExtAddress is nullptr. + * @retval OT_ERROR_NOT_FOUND @p aExtAddress is not in the RssIn filter if it is not nullptr. * */ otError RemoveRssIn(const ExtAddress *aExtAddress); diff --git a/src/core/mac/mac_frame.cpp b/src/core/mac/mac_frame.cpp index b23a2f588..e47a635ea 100644 --- a/src/core/mac/mac_frame.cpp +++ b/src/core/mac/mac_frame.cpp @@ -838,7 +838,7 @@ uint8_t Frame::FindPayloadIndex(void) const { uint8_t index = SkipSecurityHeaderIndex(); #if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT - const uint8_t *cur = NULL; + const uint8_t *cur = nullptr; const uint8_t *footer = GetFooter(); #endif @@ -887,7 +887,7 @@ const uint8_t *Frame::GetPayload(void) const uint8_t index = FindPayloadIndex(); const uint8_t *payload = GetPsdu() + index; - VerifyOrExit(index != kInvalidIndex, payload = NULL); + VerifyOrExit(index != kInvalidIndex, payload = nullptr); exit: return payload; @@ -938,7 +938,7 @@ exit: const uint8_t *Frame::GetHeaderIe(uint8_t aIeId) const { uint8_t index = FindHeaderIeIndex(); - const uint8_t *cur = NULL; + const uint8_t *cur = nullptr; const uint8_t *payload = GetPayload(); VerifyOrExit(index != kInvalidIndex, OT_NOOP); @@ -957,14 +957,14 @@ const uint8_t *Frame::GetHeaderIe(uint8_t aIeId) const cur += sizeof(HeaderIe); - VerifyOrExit(cur + len <= payload, cur = NULL); + VerifyOrExit(cur + len <= payload, cur = nullptr); cur += len; } if (cur == payload) { - cur = NULL; + cur = nullptr; } exit: @@ -978,7 +978,7 @@ void Frame::SetCslIe(uint16_t aCslPeriod, uint16_t aCslPhase) uint8_t *cur = GetHeaderIe(Frame::kHeaderIeCsl); CslIe * csl; - OT_ASSERT(cur != NULL); + OT_ASSERT(cur != nullptr); csl = reinterpret_cast(cur + sizeof(HeaderIe)); csl->SetPeriod(aCslPeriod); @@ -989,20 +989,20 @@ void Frame::SetCslIe(uint16_t aCslPeriod, uint16_t aCslPhase) #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE const TimeIe *Frame::GetTimeIe(void) const { - const TimeIe * timeIe = NULL; - const uint8_t *cur = NULL; + const TimeIe * timeIe = nullptr; + const uint8_t *cur = nullptr; uint8_t oui[VendorIeHeader::kVendorOuiSize] = {VendorIeHeader::kVendorOuiNest & 0xff, (VendorIeHeader::kVendorOuiNest >> 8) & 0xff, (VendorIeHeader::kVendorOuiNest >> 16) & 0xff}; cur = GetHeaderIe(kHeaderIeVendor); - VerifyOrExit(cur != NULL, OT_NOOP); + VerifyOrExit(cur != nullptr, OT_NOOP); cur += sizeof(HeaderIe); timeIe = reinterpret_cast(cur); - VerifyOrExit(memcmp(oui, timeIe->GetVendorOui(), VendorIeHeader::kVendorOuiSize) == 0, timeIe = NULL); - VerifyOrExit(timeIe->GetSubType() == VendorIeHeader::kVendorIeTime, timeIe = NULL); + VerifyOrExit(memcmp(oui, timeIe->GetVendorOui(), VendorIeHeader::kVendorOuiSize) == 0, timeIe = nullptr); + VerifyOrExit(timeIe->GetSubType() == VendorIeHeader::kVendorIeTime, timeIe = nullptr); exit: return timeIe; @@ -1181,7 +1181,7 @@ otError TxFrame::GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, con // Set header IE if (aIeLength > 0) { - OT_ASSERT(aIeData != NULL); + OT_ASSERT(aIeData != nullptr); memcpy(GetPsdu() + FindHeaderIeIndex(), aIeData, aIeLength); } diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index faabf089a..81385af4e 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -878,7 +878,7 @@ public: /** * This method returns a pointer to the vendor specific Time IE. * - * @returns A pointer to the Time IE, NULL if not found. + * @returns A pointer to the Time IE, nullptr if not found. * */ TimeIe *GetTimeIe(void) { return const_cast(const_cast(this)->GetTimeIe()); } @@ -886,7 +886,7 @@ public: /** * This method returns a pointer to the vendor specific Time IE. * - * @returns A pointer to the Time IE, NULL if not found. + * @returns A pointer to the Time IE, nullptr if not found. * */ const TimeIe *GetTimeIe(void) const; @@ -910,7 +910,7 @@ public: * * @param[in] aIeId The Element Id of the Header IE. * - * @returns A pointer to the Header IE, NULL if not found. + * @returns A pointer to the Header IE, nullptr if not found. * */ uint8_t *GetHeaderIe(uint8_t aIeId) @@ -923,7 +923,7 @@ public: * * @param[in] aIeId The Element Id of the Header IE. * - * @returns A pointer to the Header IE, NULL if not found. + * @returns A pointer to the Header IE, nullptr if not found. * */ const uint8_t *GetHeaderIe(uint8_t aIeId) const; diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index 61bbb084b..9a4e65065 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -57,8 +57,8 @@ SubMac::SubMac(Instance &aInstance) , mEnergyScanEndTime(0) , mTransmitFrame(Get().GetTransmitBuffer()) , mCallbacks(aInstance) - , mPcapCallback(NULL) - , mPcapCallbackContext(NULL) + , mPcapCallback(nullptr) + , mPcapCallbackContext(nullptr) , mFrameCounter(0) , mKeyId(0) , mTimer(aInstance, SubMac::HandleTimer, this) @@ -197,12 +197,12 @@ exit: void SubMac::HandleReceiveDone(RxFrame *aFrame, otError aError) { - if (mPcapCallback && (aFrame != NULL) && (aError == OT_ERROR_NONE)) + if (mPcapCallback && (aFrame != nullptr) && (aError == OT_ERROR_NONE)) { mPcapCallback(aFrame, false, mPcapCallbackContext); } - if (!ShouldHandleTransmitSecurity() && aFrame != NULL && aFrame->mInfo.mRxInfo.mAckedWithSecEnhAck) + if (!ShouldHandleTransmitSecurity() && aFrame != nullptr && aFrame->mInfo.mRxInfo.mAckedWithSecEnhAck) { UpdateFrameCounter(aFrame->mInfo.mRxInfo.mAckFrameCounter); } @@ -239,7 +239,7 @@ exit: void SubMac::ProcessTransmitSecurity(void) { - const ExtAddress *extAddress = NULL; + const ExtAddress *extAddress = nullptr; uint8_t keyIdMode; VerifyOrExit(ShouldHandleTransmitSecurity(), OT_NOOP); @@ -536,7 +536,7 @@ void SubMac::HandleTimer(void) case kStateTransmit: otLogDebgMac("Ack timer timed out"); IgnoreError(Get().Receive(mTransmitFrame.GetChannel())); - HandleTransmitDone(mTransmitFrame, NULL, OT_ERROR_NO_ACK); + HandleTransmitDone(mTransmitFrame, nullptr, OT_ERROR_NO_ACK); break; case kStateEnergyScan: diff --git a/src/core/mac/sub_mac.hpp b/src/core/mac/sub_mac.hpp index 57e6d5556..05875c967 100644 --- a/src/core/mac/sub_mac.hpp +++ b/src/core/mac/sub_mac.hpp @@ -102,7 +102,7 @@ public: /** * This method notifies user of `SubMac` of a received frame. * - * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed. * @param[in] aError OT_ERROR_NONE when successfully received a frame, * OT_ERROR_ABORT when reception was aborted and a frame was not received, * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. @@ -130,7 +130,7 @@ public: * of a frame transmission, this method is invoked on all frame transmission attempts. * * @param[in] aFrame The transmitted frame. - * @param[in] aAckFrame A pointer to the ACK frame, or NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted successfully, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel, @@ -151,7 +151,7 @@ public: * the received ACK frame. * * @param[in] aFrame The transmitted frame. - * @param[in] aAckFrame A pointer to the ACK frame, NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel, @@ -245,7 +245,7 @@ public: * This method registers a callback to provide received packet capture for IEEE 802.15.4 frames. * * @param[in] aPcapCallback A pointer to a function that is called when receiving an IEEE 802.15.4 link frame - * or NULL to disable the callback. + * or nullptr to disable the callback. * @param[in] aCallbackContext A pointer to application-specific context. * */ diff --git a/src/core/meshcop/announce_begin_client.cpp b/src/core/meshcop/announce_begin_client.cpp index 610227d58..cff05ee20 100644 --- a/src/core/meshcop/announce_begin_client.cpp +++ b/src/core/meshcop/announce_begin_client.cpp @@ -61,10 +61,10 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, otError error = OT_ERROR_NONE; MeshCoP::ChannelMaskTlv channelMask; Ip6::MessageInfo messageInfo; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; VerifyOrExit(Get().IsActive(), error = OT_ERROR_INVALID_STATE); - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, @@ -91,7 +91,7 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index b2a057fff..e0952d70a 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -165,16 +165,16 @@ static Coap::Message::Code CoapCodeFromError(otError aError) static void SendErrorMessage(Coap::CoapSecure &aCoapSecure, ForwardContext &aForwardContext, otError aError) { otError error = OT_ERROR_NONE; - Coap::Message *message = NULL; + Coap::Message *message = nullptr; - VerifyOrExit((message = NewMeshCoPMessage(aCoapSecure)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(aCoapSecure)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = aForwardContext.ToHeader(*message, CoapCodeFromError(aError))); SuccessOrExit(error = aCoapSecure.SendMessage(*message, aCoapSecure.GetPeerAddress())); exit: if (error != OT_ERROR_NONE) { - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -189,9 +189,9 @@ static void SendErrorMessage(Coap::CoapSecure & aCoapSecure, otError aError) { otError error = OT_ERROR_NONE; - Coap::Message *message = NULL; + Coap::Message *message = nullptr; - VerifyOrExit((message = NewMeshCoPMessage(aCoapSecure)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(aCoapSecure)) != nullptr, error = OT_ERROR_NO_BUFS); if (aRequest.IsNonConfirmable() || aSeparate) { @@ -214,7 +214,7 @@ static void SendErrorMessage(Coap::CoapSecure & aCoapSecure, exit: if (error != OT_ERROR_NONE) { - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -234,11 +234,11 @@ void BorderAgent::HandleCoapResponse(void * aContext, BorderAgent & borderAgent = forwardContext.GetBorderAgent(); Instance & instance = borderAgent.GetInstance(); const Coap::Message *response = static_cast(aMessage); - Coap::Message * message = NULL; + Coap::Message * message = nullptr; otError error; SuccessOrExit(error = aResult); - VerifyOrExit((message = NewMeshCoPMessage(instance.Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(instance.Get())) != nullptr, error = OT_ERROR_NO_BUFS); if (forwardContext.IsPetition() && response->GetCode() == OT_COAP_CODE_CHANGED) { @@ -271,7 +271,7 @@ void BorderAgent::HandleCoapResponse(void * aContext, exit: if (error != OT_ERROR_NONE) { - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -390,7 +390,7 @@ exit: void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage) { - Message * message = NULL; + Message * message = nullptr; Ip6::MessageInfo messageInfo; uint16_t offset; otError error; @@ -401,7 +401,7 @@ void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage) SuccessOrExit(error = Tlv::FindTlvOffset(aMessage, Tlv::kUdpEncapsulation, offset)); VerifyOrExit(aMessage.Read(offset, sizeof(tlv), &tlv) == sizeof(tlv), error = OT_ERROR_PARSE); - VerifyOrExit((message = Get().NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetLength(tlv.GetUdpLength())); aMessage.CopyTo(offset + sizeof(tlv), 0, tlv.GetUdpLength(), *message); @@ -421,7 +421,7 @@ exit: { otLogWarnMeshCoP("Failed to send proxy stream: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -431,14 +431,14 @@ exit: bool BorderAgent::HandleUdpReceive(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error; - Coap::Message *message = NULL; + Coap::Message *message = nullptr; VerifyOrExit(aMessageInfo.GetSockAddr() == mCommissionerAloc.GetAddress(), error = OT_ERROR_DESTINATION_ADDRESS_FILTERED); VerifyOrExit(aMessage.GetLength() > 0, error = OT_ERROR_NONE); - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_PROXY_RX)); @@ -468,7 +468,7 @@ bool BorderAgent::HandleUdpReceive(const Message &aMessage, const Ip6::MessageIn otLogInfoMeshCoP("Sent to commissioner on %s", OT_URI_PATH_PROXY_RX); exit: - if (message != NULL && error != OT_ERROR_NONE) + if (message != nullptr && error != OT_ERROR_NONE) { otLogWarnMeshCoP("Failed notify commissioner on %s", OT_URI_PATH_PROXY_RX); message->Free(); @@ -479,11 +479,11 @@ exit: void BorderAgent::HandleRelayReceive(const Coap::Message &aMessage) { - Coap::Message *message = NULL; + Coap::Message *message = nullptr; otError error; VerifyOrExit(aMessage.IsNonConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, error = OT_ERROR_DROP); - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_RELAY_RX)); @@ -497,7 +497,7 @@ void BorderAgent::HandleRelayReceive(const Coap::Message &aMessage) otLogInfoMeshCoP("Sent to commissioner on %s", OT_URI_PATH_RELAY_RX); exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -542,7 +542,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage) { otError error = OT_ERROR_NONE; uint16_t joinerRouterRloc; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; uint16_t offset = 0; @@ -550,7 +550,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage) SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerRouterLocator, joinerRouterRloc)); - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_RELAY_TX)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -574,7 +574,7 @@ exit: { otLogWarnMeshCoP("Failed to sent to joiner router request " OT_URI_PATH_RELAY_TX " %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -588,12 +588,12 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage, bool aSeparate) { otError error = OT_ERROR_NONE; - ForwardContext * forwardContext = NULL; + ForwardContext * forwardContext = nullptr; Ip6::MessageInfo messageInfo; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; uint16_t offset = 0; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); if (aSeparate) { @@ -601,7 +601,7 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage, } forwardContext = static_cast(GetInstance().HeapCAlloc(1, sizeof(ForwardContext))); - VerifyOrExit(forwardContext != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(forwardContext != nullptr, error = OT_ERROR_NO_BUFS); forwardContext = new (forwardContext) ForwardContext(*this, aMessage, aPetition, aSeparate); @@ -625,19 +625,19 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage, SuccessOrExit(error = Get().SendMessage(*message, messageInfo, HandleCoapResponse, forwardContext)); // HandleCoapResponse is responsible to free this forward context. - forwardContext = NULL; + forwardContext = nullptr; otLogInfoMeshCoP("Forwarded request to leader on %s", aPath); exit: if (error != OT_ERROR_NONE) { - if (forwardContext != NULL) + if (forwardContext != nullptr) { GetInstance().HeapFree(forwardContext); } - if (message != NULL) + if (message != nullptr) { message->Free(); } diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index b2227fd69..f69e1ec5a 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -70,9 +70,9 @@ Commissioner::Commissioner(Instance &aInstance) , mAnnounceBegin(aInstance) , mEnergyScan(aInstance) , mPanIdQuery(aInstance) - , mStateCallback(NULL) - , mJoinerCallback(NULL) - , mCallbackContext(NULL) + , mStateCallback(nullptr) + , mJoinerCallback(nullptr) + , mCallbackContext(nullptr) , mState(OT_COMMISSIONER_STATE_DISABLED) { memset(mJoiners, 0, sizeof(mJoiners)); @@ -258,7 +258,7 @@ otError Commissioner::SendCommissionerSet(void) dataset.mIsSteeringDataSet = true; - SuccessOrExit(error = SendMgmtCommissionerSetRequest(dataset, NULL, 0)); + SuccessOrExit(error = SendMgmtCommissionerSetRequest(dataset, nullptr, 0)); exit: return error; @@ -291,7 +291,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64, const char *aPskd continue; } - if (aEui64 != NULL) + if (aEui64 != nullptr) { joiner->mEui64 = *aEui64; joiner->mAny = false; @@ -309,7 +309,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64, const char *aPskd IgnoreError(SendCommissionerSet()); - otLogInfoMeshCoP("Added Joiner (%s, %s)", (aEui64 != NULL) ? aEui64->ToString().AsCString() : "*", aPskd); + otLogInfoMeshCoP("Added Joiner (%s, %s)", (aEui64 != nullptr) ? aEui64->ToString().AsCString() : "*", aPskd); ExitNow(error = OT_ERROR_NONE); } @@ -361,7 +361,7 @@ otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, uint32_t aDela continue; } - if (aEui64 != NULL) + if (aEui64 != nullptr) { if (joiner->mEui64 != *aEui64) { @@ -394,7 +394,7 @@ otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, uint32_t aDela IgnoreError(SendCommissionerSet()); } - otLogInfoMeshCoP("Removed Joiner (%s)", (aEui64 != NULL) ? aEui64->ToString().AsCString() : "*"); + otLogInfoMeshCoP("Removed Joiner (%s)", (aEui64 != nullptr) ? aEui64->ToString().AsCString() : "*"); ComputeJoinerId(joiner->mEui64, joinerId); SignalJoinerEvent(OT_COMMISSIONER_JOINER_REMOVED, joinerId); @@ -412,7 +412,7 @@ otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl) otError error = OT_ERROR_NONE; uint8_t len; - if (aProvisioningUrl == NULL) + if (aProvisioningUrl == nullptr) { mProvisioningUrl[0] = '\0'; ExitNow(); @@ -526,7 +526,7 @@ otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8 Ip6::MessageInfo messageInfo; MeshCoP::Tlv tlv; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_COMMISSIONER_GET)); @@ -553,7 +553,7 @@ otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8 exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -591,7 +591,7 @@ otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDatase Coap::Message * message; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_COMMISSIONER_SET)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -639,7 +639,7 @@ otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDatase exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -672,13 +672,13 @@ exit: otError Commissioner::SendPetition(void) { otError error = OT_ERROR_NONE; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; CommissionerIdTlv commissionerId; mTransmitAttempts++; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_LEADER_PETITION)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -698,7 +698,7 @@ otError Commissioner::SendPetition(void) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -775,10 +775,10 @@ void Commissioner::SendKeepAlive(void) void Commissioner::SendKeepAlive(uint16_t aSessionId) { otError error = OT_ERROR_NONE; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_LEADER_KEEP_ALIVE)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -803,7 +803,7 @@ exit: { otLogWarnMeshCoP("Failed to send keep alive: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -999,7 +999,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Message &aRequest, State Coap::Message * message; Mac::ExtAddress joinerId; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -1036,7 +1036,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Message &aRequest, State exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -1057,7 +1057,7 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf uint16_t offset; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_RELAY_TX)); @@ -1090,7 +1090,7 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index fbfeb421c..3e51fc920 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -112,7 +112,7 @@ public: /** * This method adds a Joiner entry. * - * @param[in] aEui64 A pointer to the Joiner's IEEE EUI-64 or NULL for any Joiner. + * @param[in] aEui64 A pointer to the Joiner's IEEE EUI-64 or nullptr for any Joiner. * @param[in] aPskd A pointer to the PSKd. * @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds. * @@ -138,7 +138,7 @@ public: /** * This method removes a Joiner entry. * - * @param[in] aEui64 A pointer to the Joiner's IEEE EUI-64 or NULL for any Joiner. + * @param[in] aEui64 A pointer to the Joiner's IEEE EUI-64 or nullptr for any Joiner. * @param[in] aDelay The delay to remove Joiner (in seconds). * @param[in] aFlags The flags for removing the Joiner. * @@ -161,7 +161,7 @@ public: /** * This method sets the Provisioning URL. * - * @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be NULL to set URL to empty string). + * @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be nullptr to set URL to empty string). * * @retval OT_ERROR_NONE Successfully set the Provisioning URL. * @retval OT_ERROR_INVALID_ARGS @p aProvisioningUrl is invalid (too long). diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp index 7fb165878..4ca43ce9d 100644 --- a/src/core/meshcop/dataset.cpp +++ b/src/core/meshcop/dataset.cpp @@ -287,18 +287,18 @@ otError Dataset::SetFrom(const otOperationalDataset &aDataset) const Timestamp *Dataset::GetTimestamp(void) const { - const Timestamp *timestamp = NULL; + const Timestamp *timestamp = nullptr; if (mType == kActive) { const ActiveTimestampTlv *tlv = GetTlv(); - VerifyOrExit(tlv != NULL, OT_NOOP); + VerifyOrExit(tlv != nullptr, OT_NOOP); timestamp = static_cast(tlv); } else { const PendingTimestampTlv *tlv = GetTlv(); - VerifyOrExit(tlv != NULL, OT_NOOP); + VerifyOrExit(tlv != nullptr, OT_NOOP); timestamp = static_cast(tlv); } @@ -319,14 +319,14 @@ otError Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength) Tlv * old = GetTlv(aType); Tlv tlv; - if (old != NULL) + if (old != nullptr) { bytesAvailable += sizeof(Tlv) + old->GetLength(); } VerifyOrExit(sizeof(Tlv) + aLength <= bytesAvailable, error = OT_ERROR_NO_BUFS); - if (old != NULL) + if (old != nullptr) { RemoveTlv(old); } @@ -381,7 +381,7 @@ void Dataset::RemoveTlv(Tlv::Type aType) { Tlv *tlv; - VerifyOrExit((tlv = GetTlv(aType)) != NULL, OT_NOOP); + VerifyOrExit((tlv = GetTlv(aType)) != nullptr, OT_NOOP); RemoveTlv(tlv); exit: diff --git a/src/core/meshcop/dataset.hpp b/src/core/meshcop/dataset.hpp index dd8a75ef2..4a3be2f64 100644 --- a/src/core/meshcop/dataset.hpp +++ b/src/core/meshcop/dataset.hpp @@ -100,7 +100,7 @@ public: * * @param[in] aType A TLV type. * - * @returns A pointer to the TLV or NULL if none is found. + * @returns A pointer to the TLV or nullptr if none is found. * */ Tlv *GetTlv(Tlv::Type aType) { return const_cast(const_cast(this)->GetTlv(aType)); } @@ -110,7 +110,7 @@ public: * * @param[in] aType The TLV type. * - * @returns A pointer to the TLV or NULL if none is found. + * @returns A pointer to the TLV or nullptr if none is found. * */ const Tlv *GetTlv(Tlv::Type aType) const; @@ -118,7 +118,7 @@ public: /** * This template method returns a pointer to the TLV with a given template type `TlvType` * - * @returns A pointer to the TLV or NULL if none is found. + * @returns A pointer to the TLV or nullptr if none is found. * */ template TlvType *GetTlv(void) @@ -129,7 +129,7 @@ public: /** * This template method returns a pointer to the TLV with a given template type `TlvType` * - * @returns A pointer to the TLV or NULL if none is found. + * @returns A pointer to the TLV or nullptr if none is found. * */ template const TlvType *GetTlv(void) const @@ -329,7 +329,7 @@ public: * @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format. * */ - otError ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated = NULL) const; + otError ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated = nullptr) const; /** * This method converts a Pending Dataset to an Active Dataset. diff --git a/src/core/meshcop/dataset_local.cpp b/src/core/meshcop/dataset_local.cpp index 590d0ea03..37cd5a5fc 100644 --- a/src/core/meshcop/dataset_local.cpp +++ b/src/core/meshcop/dataset_local.cpp @@ -79,7 +79,7 @@ otError DatasetLocal::Restore(Dataset &aDataset) mSaved = true; timestamp = aDataset.GetTimestamp(); - if (timestamp != NULL) + if (timestamp != nullptr) { mTimestamp = *timestamp; mTimestampPresent = true; @@ -196,7 +196,7 @@ otError DatasetLocal::Save(const Dataset &aDataset) timestamp = aDataset.GetTimestamp(); - if (timestamp != NULL) + if (timestamp != nullptr) { mTimestamp = *timestamp; mTimestampPresent = true; @@ -214,8 +214,8 @@ exit: int DatasetLocal::Compare(const Timestamp *aCompare) { - return (aCompare == NULL) ? (!mTimestampPresent ? 0 : -1) - : (!mTimestampPresent ? 1 : mTimestamp.Compare(*aCompare)); + return (aCompare == nullptr) ? (!mTimestampPresent ? 0 : -1) + : (!mTimestampPresent ? 1 : mTimestamp.Compare(*aCompare)); } } // namespace MeshCoP diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index f5b5e8df2..71efbd9d0 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -67,7 +67,7 @@ DatasetManager::DatasetManager(Instance & aInstance, const Timestamp *DatasetManager::GetTimestamp(void) const { - return mTimestampValid ? &mTimestamp : NULL; + return mTimestampValid ? &mTimestamp : nullptr; } int DatasetManager::Compare(const Timestamp &aTimestamp) const @@ -97,7 +97,7 @@ otError DatasetManager::Restore(void) timestamp = dataset.GetTimestamp(); - if (timestamp != NULL) + if (timestamp != nullptr) { mTimestamp = *timestamp; mTimestampValid = true; @@ -146,7 +146,7 @@ otError DatasetManager::Save(const Dataset &aDataset) timestamp = aDataset.GetTimestamp(); - if (timestamp != NULL) + if (timestamp != nullptr) { mTimestamp = *timestamp; mTimestampValid = true; @@ -235,7 +235,7 @@ otError DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const SuccessOrExit(error = mLocal.Read(dataset)); channelMaskTlv = dataset.GetTlv(); - VerifyOrExit(channelMaskTlv != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(channelMaskTlv != nullptr, error = OT_ERROR_NOT_FOUND); VerifyOrExit((mask = channelMaskTlv->GetChannelMask()) != 0, OT_NOOP); aChannelMask.SetMask(mask & Get().GetSupportedChannelMask().GetMask()); @@ -254,7 +254,7 @@ void DatasetManager::HandleTimer(void) void DatasetManager::SendSet(void) { otError error; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; Dataset dataset(mLocal.GetType()); @@ -270,14 +270,14 @@ void DatasetManager::SendSet(void) const ActiveTimestampTlv *tlv = pendingDataset.GetTlv(); const Timestamp * pendingActiveTimestamp = static_cast(tlv); - if (pendingActiveTimestamp != NULL && mLocal.Compare(pendingActiveTimestamp) == 0) + if (pendingActiveTimestamp != nullptr && mLocal.Compare(pendingActiveTimestamp) == 0) { // stop registration attempts during dataset transition ExitNow(error = OT_ERROR_INVALID_STATE); } } - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, mUriSet)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -308,7 +308,7 @@ exit: default: otLogWarnMeshCoP("Failed to send %s to leader: %s", mUriSet, otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -391,7 +391,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest, IgnoreError(mLocal.Read(dataset)); - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -417,7 +417,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest, continue; } - if ((tlv = dataset.GetTlv(static_cast(aTlvs[index]))) != NULL) + if ((tlv = dataset.GetTlv(static_cast(aTlvs[index]))) != nullptr) { SuccessOrExit(error = tlv->AppendTo(*message)); } @@ -436,7 +436,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -448,7 +448,7 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con Coap::Message * message; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, mUriSet)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -584,7 +584,7 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -666,7 +666,7 @@ otError DatasetManager::SendGetRequest(const otOperationalDatasetComponents &aDa datasetTlvs[length++] = Tlv::kChannelMask; } - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, mUriGet)); @@ -692,7 +692,7 @@ otError DatasetManager::SendGetRequest(const otOperationalDatasetComponents &aDa } } - if (aAddress != NULL) + if (aAddress != nullptr) { messageInfo.SetPeerAddr(*static_cast(aAddress)); } @@ -709,7 +709,7 @@ otError DatasetManager::SendGetRequest(const otOperationalDatasetComponents &aDa exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -840,7 +840,7 @@ void PendingDataset::StartDelayTimer(void) mDelayTimer.Stop(); - if ((delayTimer = dataset.GetTlv()) != NULL) + if ((delayTimer = dataset.GetTlv()) != nullptr) { uint32_t delay = delayTimer->GetDelayTimer(); @@ -869,7 +869,7 @@ void PendingDataset::HandleDelayTimer(void) // if the Delay Timer value is larger than what our Timer implementation can handle, we have to compute // the remainder and wait some more. - if ((delayTimer = dataset.GetTlv()) != NULL) + if ((delayTimer = dataset.GetTlv()) != nullptr) { uint32_t elapsed = mDelayTimer.GetFireTime() - dataset.GetUpdateTime(); uint32_t delay = delayTimer->GetDelayTimer(); diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 97fcb9555..bafce01a1 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -167,7 +167,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf // no change to master key, active timestamp must be ahead const Timestamp *localActiveTimestamp = Get().GetTimestamp(); - VerifyOrExit(localActiveTimestamp == NULL || localActiveTimestamp->Compare(activeTimestamp) > 0, OT_NOOP); + VerifyOrExit(localActiveTimestamp == nullptr || localActiveTimestamp->Compare(activeTimestamp) > 0, OT_NOOP); } // check commissioner session id @@ -180,7 +180,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf localId = static_cast( Get().GetCommissioningDataSubTlv(Tlv::kCommissionerSessionId)); - VerifyOrExit(localId != NULL && localId->GetCommissionerSessionId() == sessionId, OT_NOOP); + VerifyOrExit(localId != nullptr && localId->GetCommissionerSessionId() == sessionId, OT_NOOP); } // verify an MGMT_ACTIVE_SET.req from a Commissioner does not affect connectivity @@ -251,7 +251,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf localSessionId = static_cast( Get().GetCommissioningDataSubTlv(Tlv::kCommissionerSessionId)); - VerifyOrExit(localSessionId != NULL, OT_NOOP); + VerifyOrExit(localSessionId != nullptr, OT_NOOP); SuccessOrExit( Get().GetCommissionerAloc(destination, localSessionId->GetCommissionerSessionId())); @@ -276,7 +276,7 @@ void DatasetManager::SendSetResponse(const Coap::Message & aRequest, otError error = OT_ERROR_NONE; Coap::Message *message; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -289,7 +289,7 @@ void DatasetManager::SendSetResponse(const Coap::Message & aRequest, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -370,7 +370,7 @@ otError ActiveDataset::GenerateLocal(void) IgnoreError(mLocal.Read(dataset)); - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { ActiveTimestampTlv activeTimestampTlv; activeTimestampTlv.Init(); @@ -379,7 +379,7 @@ otError ActiveDataset::GenerateLocal(void) IgnoreError(dataset.SetTlv(activeTimestampTlv)); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { ChannelTlv tlv; tlv.Init(); @@ -387,7 +387,7 @@ otError ActiveDataset::GenerateLocal(void) IgnoreError(dataset.SetTlv(tlv)); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { ChannelMaskTlv tlv; tlv.Init(); @@ -395,36 +395,36 @@ otError ActiveDataset::GenerateLocal(void) IgnoreError(dataset.SetTlv(tlv)); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { IgnoreError( dataset.SetTlv(Tlv::kExtendedPanId, &Get().GetExtendedPanId(), sizeof(Mac::ExtendedPanId))); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { IgnoreError(dataset.SetTlv(Tlv::kMeshLocalPrefix, &Get().GetMeshLocalPrefix(), sizeof(Mle::MeshLocalPrefix))); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { IgnoreError(dataset.SetTlv(Tlv::kNetworkMasterKey, &Get().GetMasterKey(), sizeof(MasterKey))); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { Mac::NameData nameData = Get().GetNetworkName().GetAsData(); IgnoreError(dataset.SetTlv(Tlv::kNetworkName, nameData.GetBuffer(), nameData.GetLength())); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { IgnoreError(dataset.SetUint16Tlv(Tlv::kPanId, Get().GetPanId())); } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { if (Get().IsPskcSet()) { @@ -440,7 +440,7 @@ otError ActiveDataset::GenerateLocal(void) } } - if (dataset.GetTlv() == NULL) + if (dataset.GetTlv() == nullptr) { SecurityPolicyTlv tlv; tlv.Init(); diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index e8263101e..0b88f0ca2 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -65,31 +65,31 @@ Dtls::Dtls(Instance &aInstance, bool aLayerTwoSecurity) , mTimerIntermediate(0) , mTimerSet(false) , mLayerTwoSecurity(aLayerTwoSecurity) - , mReceiveMessage(NULL) - , mConnectedHandler(NULL) - , mReceiveHandler(NULL) - , mSendHandler(NULL) - , mContext(NULL) + , mReceiveMessage(nullptr) + , mConnectedHandler(nullptr) + , mReceiveHandler(nullptr) + , mSendHandler(nullptr) + , mContext(nullptr) , mSocket(Get()) - , mTransportCallback(NULL) - , mTransportContext(NULL) + , mTransportCallback(nullptr) + , mTransportContext(nullptr) , mMessageSubType(Message::kSubTypeNone) , mMessageDefaultSubType(Message::kSubTypeNone) { #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED - mPreSharedKey = NULL; - mPreSharedKeyIdentity = NULL; + mPreSharedKey = nullptr; + mPreSharedKeyIdentity = nullptr; mPreSharedKeyIdLength = 0; mPreSharedKeyLength = 0; #endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - mCaChainSrc = NULL; + mCaChainSrc = nullptr; mCaChainLength = 0; - mOwnCertSrc = NULL; + mOwnCertSrc = nullptr; mOwnCertLength = 0; - mPrivateKeySrc = NULL; + mPrivateKeySrc = nullptr; mPrivateKeyLength = 0; memset(&mCaChain, 0, sizeof(mCaChain)); memset(&mOwnCert, 0, sizeof(mOwnCert)); @@ -218,7 +218,7 @@ otError Dtls::Bind(uint16_t aPort) Ip6::SockAddr sockaddr; VerifyOrExit(mState == kStateOpen, error = OT_ERROR_INVALID_STATE); - VerifyOrExit(mTransportCallback == NULL, error = OT_ERROR_ALREADY); + VerifyOrExit(mTransportCallback == nullptr, error = OT_ERROR_ALREADY); sockaddr.mPort = aPort; SuccessOrExit(error = mSocket.Bind(sockaddr)); @@ -233,7 +233,7 @@ otError Dtls::Bind(TransportCallback aCallback, void *aContext) VerifyOrExit(mState == kStateOpen, error = OT_ERROR_INVALID_STATE); VerifyOrExit(!mSocket.IsBound(), error = OT_ERROR_ALREADY); - VerifyOrExit(mTransportCallback == NULL, error = OT_ERROR_ALREADY); + VerifyOrExit(mTransportCallback == nullptr, error = OT_ERROR_ALREADY); mTransportCallback = aCallback; mTransportContext = aContext; @@ -304,7 +304,7 @@ otError Dtls::Setup(bool aClient) rval = mbedtls_ssl_setup(&mSsl, &mConf); VerifyOrExit(rval == 0, OT_NOOP); - mbedtls_ssl_set_bio(&mSsl, this, &Dtls::HandleMbedtlsTransmit, HandleMbedtlsReceive, NULL); + mbedtls_ssl_set_bio(&mSsl, this, &Dtls::HandleMbedtlsTransmit, HandleMbedtlsReceive, nullptr); mbedtls_ssl_set_timer_cb(&mSsl, this, &Dtls::HandleMbedtlsSetTimer, HandleMbedtlsGetTimer); if (mCipherSuites[0] == MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8) @@ -319,7 +319,7 @@ otError Dtls::Setup(bool aClient) #endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE VerifyOrExit(rval == 0, OT_NOOP); - mReceiveMessage = NULL; + mReceiveMessage = nullptr; mMessageSubType = Message::kSubTypeNone; mState = kStateConnecting; @@ -357,21 +357,21 @@ int Dtls::SetApplicationCoapSecureKeys(void) { case MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - if (mCaChainSrc != NULL) + if (mCaChainSrc != nullptr) { rval = mbedtls_x509_crt_parse(&mCaChain, static_cast(mCaChainSrc), static_cast(mCaChainLength)); VerifyOrExit(rval == 0, OT_NOOP); - mbedtls_ssl_conf_ca_chain(&mConf, &mCaChain, NULL); + mbedtls_ssl_conf_ca_chain(&mConf, &mCaChain, nullptr); } - if (mOwnCertSrc != NULL && mPrivateKeySrc != NULL) + if (mOwnCertSrc != nullptr && mPrivateKeySrc != nullptr) { rval = mbedtls_x509_crt_parse(&mOwnCert, static_cast(mOwnCertSrc), static_cast(mOwnCertLength)); VerifyOrExit(rval == 0, OT_NOOP); rval = mbedtls_pk_parse_key(&mPrivateKey, static_cast(mPrivateKeySrc), - static_cast(mPrivateKeyLength), NULL, 0); + static_cast(mPrivateKeyLength), nullptr, 0); VerifyOrExit(rval == 0, OT_NOOP); rval = mbedtls_ssl_conf_own_cert(&mConf, &mOwnCert, &mPrivateKey); VerifyOrExit(rval == 0, OT_NOOP); @@ -410,8 +410,8 @@ void Dtls::Close(void) Disconnect(); mState = kStateClosed; - mTransportCallback = NULL; - mTransportContext = NULL; + mTransportCallback = nullptr; + mTransportContext = nullptr; mTimerSet = false; IgnoreError(mSocket.Close()); @@ -459,10 +459,10 @@ void Dtls::SetCertificate(const uint8_t *aX509Certificate, uint32_t aPrivateKeyLength) { OT_ASSERT(aX509CertLength > 0); - OT_ASSERT(aX509Certificate != NULL); + OT_ASSERT(aX509Certificate != nullptr); OT_ASSERT(aPrivateKeyLength > 0); - OT_ASSERT(aPrivateKey != NULL); + OT_ASSERT(aPrivateKey != nullptr); mOwnCertSrc = aX509Certificate; mOwnCertLength = aX509CertLength; @@ -476,7 +476,7 @@ void Dtls::SetCertificate(const uint8_t *aX509Certificate, void Dtls::SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength) { OT_ASSERT(aX509CaCertChainLength > 0); - OT_ASSERT(aX509CaCertificateChain != NULL); + OT_ASSERT(aX509CaCertificateChain != nullptr); mCaChainSrc = aX509CaCertificateChain; mCaChainLength = aX509CaCertChainLength; @@ -488,8 +488,8 @@ void Dtls::SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_ void Dtls::SetPreSharedKey(const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength) { - OT_ASSERT(aPsk != NULL); - OT_ASSERT(aPskIdentity != NULL); + OT_ASSERT(aPsk != nullptr); + OT_ASSERT(aPskIdentity != nullptr); OT_ASSERT(aPskLength > 0); OT_ASSERT(aPskIdLength > 0); @@ -559,7 +559,7 @@ void Dtls::Receive(Message &aMessage) Process(); - mReceiveMessage = NULL; + mReceiveMessage = nullptr; } int Dtls::HandleMbedtlsTransmit(void *aContext, const unsigned char *aBuf, size_t aLength) @@ -627,7 +627,7 @@ int Dtls::HandleMbedtlsReceive(unsigned char *aBuf, size_t aLength) } #endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE - VerifyOrExit(mReceiveMessage != NULL && (rval = mReceiveMessage->GetLength() - mReceiveMessage->GetOffset()) > 0, + VerifyOrExit(mReceiveMessage != nullptr && (rval = mReceiveMessage->GetLength() - mReceiveMessage->GetOffset()) > 0, rval = MBEDTLS_ERR_SSL_WANT_READ); if (aLength > static_cast(rval)) @@ -772,7 +772,7 @@ void Dtls::HandleTimer(void) mState = kStateOpen; mTimer.Stop(); - if (mConnectedHandler != NULL) + if (mConnectedHandler != nullptr) { mConnectedHandler(mContext, false); } @@ -800,7 +800,7 @@ void Dtls::Process(void) { mState = kStateConnected; - if (mConnectedHandler != NULL) + if (mConnectedHandler != nullptr) { mConnectedHandler(mContext, true); } @@ -905,9 +905,9 @@ void Dtls::HandleMbedtlsDebug(void *ctx, int level, const char *, int, const cha otError Dtls::HandleDtlsSend(const uint8_t *aBuf, uint16_t aLength, Message::SubType aMessageSubType) { otError error = OT_ERROR_NONE; - ot::Message *message = NULL; + ot::Message *message = nullptr; - VerifyOrExit((message = mSocket.NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = mSocket.NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(aMessageSubType); message->SetLinkSecurityEnabled(mLayerTwoSecurity); @@ -930,7 +930,7 @@ otError Dtls::HandleDtlsSend(const uint8_t *aBuf, uint16_t aLength, Message::Sub exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } diff --git a/src/core/meshcop/energy_scan_client.cpp b/src/core/meshcop/energy_scan_client.cpp index ffda298df..65971d5b1 100644 --- a/src/core/meshcop/energy_scan_client.cpp +++ b/src/core/meshcop/energy_scan_client.cpp @@ -51,8 +51,8 @@ namespace ot { EnergyScanClient::EnergyScanClient(Instance &aInstance) : InstanceLocator(aInstance) - , mCallback(NULL) - , mContext(NULL) + , mCallback(nullptr) + , mContext(nullptr) , mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this) { Get().AddResource(mEnergyScan); @@ -69,10 +69,10 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelM otError error = OT_ERROR_NONE; MeshCoP::ChannelMaskTlv channelMask; Ip6::MessageInfo messageInfo; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; VerifyOrExit(Get().IsActive(), error = OT_ERROR_INVALID_STATE); - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, @@ -102,7 +102,7 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelM exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -136,7 +136,7 @@ void EnergyScanClient::HandleReport(Coap::Message &aMessage, const Ip6::MessageI SuccessOrExit(MeshCoP::Tlv::FindTlv(aMessage, MeshCoP::Tlv::kEnergyList, sizeof(energyList), energyList.tlv)); VerifyOrExit(energyList.tlv.IsValid(), OT_NOOP); - if (mCallback != NULL) + if (mCallback != nullptr) { mCallback(mask, energyList.list, energyList.tlv.GetLength(), mContext); } diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 0d2e41202..33da42cbe 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -58,10 +58,10 @@ namespace MeshCoP { Joiner::Joiner(Instance &aInstance) : InstanceLocator(aInstance) , mState(OT_JOINER_STATE_IDLE) - , mCallback(NULL) - , mContext(NULL) + , mCallback(nullptr) + , mContext(nullptr) , mJoinerRouterIndex(0) - , mFinalizeMessage(NULL) + , mFinalizeMessage(nullptr) , mTimer(aInstance, Joiner::HandleTimer, this) , mJoinerEntrust(OT_URI_PATH_JOINER_ENTRUST, &Joiner::HandleJoinerEntrust, this) { @@ -124,7 +124,7 @@ otError Joiner::Start(const char * aPskd, SuccessOrExit(error = Get().Discover(Mac::ChannelMask(0), Get().GetPanId(), /* aJoiner */ true, /* aEnableFiltering */ true, - /* aFilterIndexes (use hash of factory EUI64) */ NULL, + /* aFilterIndexes (use hash of factory EUI64) */ nullptr, HandleDiscoverResult, this)); mCallback = aCallback; mContext = aContext; @@ -145,8 +145,8 @@ void Joiner::Stop(void) { otLogInfoMeshCoP("Joiner stopped"); - // Callback is set to `NULL` to skip calling it from `Finish()` - mCallback = NULL; + // Callback is set to `nullptr` to skip calling it from `Finish()` + mCallback = nullptr; Finish(OT_ERROR_ABORT); } @@ -230,7 +230,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) VerifyOrExit(mState == OT_JOINER_STATE_DISCOVER, OT_NOOP); - if (aResult != NULL) + if (aResult != nullptr) { SaveDiscoveredJoinerRouter(*aResult); } @@ -396,7 +396,7 @@ otError Joiner::PrepareJoinerFinalizeMessage(const char *aProvisioningUrl, VendorStackVersionTlv vendorStackVersionTlv; ProvisioningUrlTlv provisioningUrlTlv; - VerifyOrExit((mFinalizeMessage = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((mFinalizeMessage = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); mFinalizeMessage->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = mFinalizeMessage->AppendUriPathOptions(OT_URI_PATH_JOINER_FINALIZE)); @@ -424,7 +424,7 @@ otError Joiner::PrepareJoinerFinalizeMessage(const char *aProvisioningUrl, vendorStackVersionTlv.SetRevision(OPENTHREAD_CONFIG_STACK_VERSION_REV); SuccessOrExit(error = vendorStackVersionTlv.AppendTo(*mFinalizeMessage)); - if (aVendorData != NULL) + if (aVendorData != nullptr) { VendorDataTlv vendorDataTlv; vendorDataTlv.Init(); @@ -451,10 +451,10 @@ exit: void Joiner::FreeJoinerFinalizeMessage(void) { - VerifyOrExit(mState == OT_JOINER_STATE_IDLE && mFinalizeMessage != NULL, OT_NOOP); + VerifyOrExit(mState == OT_JOINER_STATE_IDLE && mFinalizeMessage != nullptr, OT_NOOP); mFinalizeMessage->Free(); - mFinalizeMessage = NULL; + mFinalizeMessage = nullptr; exit: return; @@ -462,14 +462,14 @@ exit: void Joiner::SendJoinerFinalize(void) { - OT_ASSERT(mFinalizeMessage != NULL); + OT_ASSERT(mFinalizeMessage != nullptr); #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE LogCertMessage("[THCI] direction=send | type=JOIN_FIN.req |", *mFinalizeMessage); #endif SuccessOrExit(Get().SendMessage(*mFinalizeMessage, Joiner::HandleJoinerFinalizeResponse, this)); - mFinalizeMessage = NULL; + mFinalizeMessage = nullptr; otLogInfoMeshCoP("Joiner sent finalize"); @@ -566,7 +566,7 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Message &aRequest, const Ip6: Coap::Message * message; Ip6::MessageInfo responseInfo(aRequestInfo); - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); message->SetSubType(Message::kSubTypeJoinerEntrust); @@ -580,7 +580,7 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Message &aRequest, const Ip6: exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } diff --git a/src/core/meshcop/joiner.hpp b/src/core/meshcop/joiner.hpp index 168edb9a0..f0ef074eb 100644 --- a/src/core/meshcop/joiner.hpp +++ b/src/core/meshcop/joiner.hpp @@ -67,11 +67,11 @@ public: * This method starts the Joiner service. * * @param[in] aPskd A pointer to the PSKd. - * @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be NULL). - * @param[in] aVendorName A pointer to the Vendor Name (may be NULL). - * @param[in] aVendorModel A pointer to the Vendor Model (may be NULL). - * @param[in] aVendorSwVersion A pointer to the Vendor SW Version (may be NULL). - * @param[in] aVendorData A pointer to the Vendor Data (may be NULL). + * @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be nullptr). + * @param[in] aVendorName A pointer to the Vendor Name (may be nullptr). + * @param[in] aVendorModel A pointer to the Vendor Model (may be nullptr). + * @param[in] aVendorSwVersion A pointer to the Vendor SW Version (may be nullptr). + * @param[in] aVendorData A pointer to the Vendor Data (may be nullptr). * @param[in] aCallback A pointer to a function that is called when the join operation completes. * @param[in] aContext A pointer to application-specific context. * diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index da9d49292..9ba1288d8 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -118,7 +118,7 @@ uint16_t JoinerRouter::GetJoinerUdpPort(void) joinerUdpPort = static_cast( Get().GetCommissioningDataSubTlv(Tlv::kJoinerUdpPort)); - VerifyOrExit(joinerUdpPort != NULL, OT_NOOP); + VerifyOrExit(joinerUdpPort != nullptr, OT_NOOP); rval = joinerUdpPort->GetUdpPort(); @@ -142,7 +142,7 @@ void JoinerRouter::HandleUdpReceive(void *aContext, otMessage *aMessage, const o void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; ExtendedTlv tlv; uint16_t borderAgentRloc; @@ -152,7 +152,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a SuccessOrExit(error = GetBorderAgentRloc(Get(), borderAgentRloc)); - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_RELAY_RX)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -180,7 +180,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -202,7 +202,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa Kek kek; uint16_t offset; uint16_t length; - Message * message = NULL; + Message * message = nullptr; Message::Settings settings(Message::kNoLinkSecurity, Message::kPriorityNet); Ip6::MessageInfo messageInfo; @@ -215,7 +215,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length)); - VerifyOrExit((message = mSocket.NewMessage(0, settings)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = mSocket.NewMessage(0, settings)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetLength(length)); aMessage.CopyTo(offset, 0, length, *message); @@ -233,7 +233,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa } exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -245,7 +245,7 @@ void JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessageInf Message * message = Get().New(Message::kTypeOther, 0); JoinerEntrustMetadata metadata; - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); metadata.mMessageInfo = aMessageInfo; metadata.mMessageInfo.SetPeerPort(kCoapUdpPort); @@ -267,7 +267,7 @@ exit: { otLogNoteMeshCoP("Failed to schedule joiner entrust: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -289,7 +289,7 @@ void JoinerRouter::SendDelayedJoinerEntrust(void) JoinerEntrustMetadata metadata; Message * message = mDelayedJoinEnts.GetHead(); - VerifyOrExit(message != NULL, OT_NOOP); + VerifyOrExit(message != nullptr, OT_NOOP); VerifyOrExit(!mTimer.IsRunning(), OT_NOOP); metadata.ReadFrom(*message); @@ -327,7 +327,7 @@ otError JoinerRouter::SendJoinerEntrust(const Ip6::MessageInfo &aMessageInfo) Coap::Message *message; message = PrepareJoinerEntrustMessage(); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); IgnoreError(Get().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this)); @@ -341,7 +341,7 @@ otError JoinerRouter::SendJoinerEntrust(const Ip6::MessageInfo &aMessageInfo) mExpectJoinEntRsp = true; exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -352,13 +352,13 @@ exit: Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) { otError error; - Coap::Message *message = NULL; + Coap::Message *message = nullptr; Dataset dataset(Dataset::kActive); NetworkNameTlv networkName; const Tlv * tlv; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_JOINER_ENTRUST)); @@ -380,7 +380,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) IgnoreError(Get().Read(dataset)); - if ((tlv = dataset.GetTlv()) != NULL) + if ((tlv = dataset.GetTlv()) != nullptr) { SuccessOrExit(error = tlv->AppendTo(*message)); } @@ -391,7 +391,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) SuccessOrExit(error = activeTimestamp.AppendTo(*message)); } - if ((tlv = dataset.GetTlv()) != NULL) + if ((tlv = dataset.GetTlv()) != nullptr) { SuccessOrExit(error = tlv->AppendTo(*message)); } @@ -402,7 +402,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) SuccessOrExit(error = channelMask.AppendTo(*message)); } - if ((tlv = dataset.GetTlv()) != NULL) + if ((tlv = dataset.GetTlv()) != nullptr) { SuccessOrExit(error = tlv->AppendTo(*message)); } @@ -413,7 +413,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) SuccessOrExit(error = pskc.AppendTo(*message)); } - if ((tlv = dataset.GetTlv()) != NULL) + if ((tlv = dataset.GetTlv()) != nullptr) { SuccessOrExit(error = tlv->AppendTo(*message)); } @@ -429,10 +429,10 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); - message = NULL; + message = nullptr; } return message; @@ -456,7 +456,7 @@ void JoinerRouter::HandleJoinerEntrustResponse(Coap::Message * aMessage, mExpectJoinEntRsp = false; SendDelayedJoinerEntrust(); - VerifyOrExit(aResult == OT_ERROR_NONE && aMessage != NULL, OT_NOOP); + VerifyOrExit(aResult == OT_ERROR_NONE && aMessage != nullptr, OT_NOOP); VerifyOrExit(aMessage->GetCode() == OT_COAP_CODE_CHANGED, OT_NOOP); diff --git a/src/core/meshcop/meshcop.cpp b/src/core/meshcop/meshcop.cpp index 0be925845..0bb5906ec 100644 --- a/src/core/meshcop/meshcop.cpp +++ b/src/core/meshcop/meshcop.cpp @@ -140,7 +140,7 @@ otError GetBorderAgentRloc(ThreadNetif &aNetif, uint16_t &aRloc) borderAgentLocator = static_cast( aNetif.Get().GetCommissioningDataSubTlv(Tlv::kBorderAgentLocator)); - VerifyOrExit(borderAgentLocator != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(borderAgentLocator != nullptr, error = OT_ERROR_NOT_FOUND); aRloc = borderAgentLocator->GetBorderAgentLocator(); diff --git a/src/core/meshcop/meshcop_leader.cpp b/src/core/meshcop/meshcop_leader.cpp index 50416142d..9492f2d35 100644 --- a/src/core/meshcop/meshcop_leader.cpp +++ b/src/core/meshcop/meshcop_leader.cpp @@ -127,7 +127,7 @@ void Leader::SendPetitionResponse(const Coap::Message & aRequest, otError error = OT_ERROR_NONE; Coap::Message *message; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -154,7 +154,7 @@ exit: { otLogInfoMeshCoP("Failed to send petition response: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -183,7 +183,7 @@ void Leader::HandleKeepAlive(Coap::Message &aMessage, const Ip6::MessageInfo &aM borderAgentLocator = static_cast( Get().GetCommissioningDataSubTlv(Tlv::kBorderAgentLocator)); - if ((borderAgentLocator == NULL) || (sessionId != mSessionId)) + if ((borderAgentLocator == nullptr) || (sessionId != mSessionId)) { responseState = StateTlv::kReject; } @@ -219,7 +219,7 @@ void Leader::SendKeepAliveResponse(const Coap::Message & aRequest, otError error = OT_ERROR_NONE; Coap::Message *message; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -236,7 +236,7 @@ exit: { otLogWarnMeshCoP("Failed to send keep alive response: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -249,7 +249,7 @@ void Leader::SendDatasetChanged(const Ip6::Address &aAddress) Ip6::MessageInfo messageInfo; Coap::Message * message; - VerifyOrExit((message = NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DATASET_CHANGED)); @@ -266,7 +266,7 @@ exit: { otLogWarnMeshCoP("Failed to send dataset changed: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } diff --git a/src/core/meshcop/meshcop_tlvs.cpp b/src/core/meshcop/meshcop_tlvs.cpp index 7481d75a3..e209f9c27 100644 --- a/src/core/meshcop/meshcop_tlvs.cpp +++ b/src/core/meshcop/meshcop_tlvs.cpp @@ -91,11 +91,11 @@ const Tlv *Tlv::FindTlv(const uint8_t *aTlvsStart, uint16_t aTlvsLength, Type aT for (tlv = reinterpret_cast(aTlvsStart); tlv < end; tlv = tlv->GetNext()) { - VerifyOrExit((tlv + 1) <= end, tlv = NULL); + VerifyOrExit((tlv + 1) <= end, tlv = nullptr); VerifyOrExit(!tlv->IsExtended() || (reinterpret_cast(tlv) + 1 <= reinterpret_cast(end)), - tlv = NULL); - VerifyOrExit(tlv->GetNext() <= end, tlv = NULL); + tlv = nullptr); + VerifyOrExit(tlv->GetNext() <= end, tlv = nullptr); if (tlv->GetType() == aType) { @@ -103,7 +103,7 @@ const Tlv *Tlv::FindTlv(const uint8_t *aTlvsStart, uint16_t aTlvsLength, Type aT } } - tlv = NULL; + tlv = nullptr; exit: return tlv; @@ -173,12 +173,12 @@ void ChannelTlv::SetChannel(uint16_t aChannel) const ChannelMaskEntryBase *ChannelMaskBaseTlv::GetFirstEntry(void) const { - const ChannelMaskEntryBase *entry = NULL; + const ChannelMaskEntryBase *entry = nullptr; VerifyOrExit(GetLength() >= sizeof(ChannelMaskEntryBase), OT_NOOP); entry = reinterpret_cast(GetValue()); - VerifyOrExit(GetLength() >= entry->GetEntrySize(), entry = NULL); + VerifyOrExit(GetLength() >= entry->GetEntrySize(), entry = nullptr); exit: return entry; @@ -199,7 +199,7 @@ void ChannelMaskTlv::SetChannelMask(uint32_t aChannelMask) #if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT if (aChannelMask & OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK) { - OT_ASSERT(entry != NULL); + OT_ASSERT(entry != nullptr); entry->Init(); entry->SetChannelPage(OT_RADIO_CHANNEL_PAGE_2); entry->SetMask(aChannelMask & OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK); @@ -213,7 +213,7 @@ void ChannelMaskTlv::SetChannelMask(uint32_t aChannelMask) #if OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT if (aChannelMask & OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK) { - OT_ASSERT(entry != NULL); + OT_ASSERT(entry != nullptr); entry->Init(); entry->SetChannelPage(OT_RADIO_CHANNEL_PAGE_0); entry->SetMask(aChannelMask & OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK); diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 497f81dbb..92a8fa8f1 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -204,7 +204,7 @@ public: * @param[in] aTlvsLength The length (number of bytes) in TLV sequence. * @param[in] aType The TLV Type to search for. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ static Tlv *FindTlv(uint8_t *aTlvsStart, uint16_t aTlvsLength, Type aType) @@ -219,7 +219,7 @@ public: * @param[in] aTlvsLength The length (number of bytes) in TLV sequence. * @param[in] aType The TLV Type to search for. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ static const Tlv *FindTlv(const uint8_t *aTlvsStart, uint16_t aTlvsLength, Type aType); @@ -231,7 +231,7 @@ public: * @param[in] aTlvsStart A pointer to the start of the sequence of TLVs to search within. * @param[in] aTlvsLength The length (number of bytes) in TLV sequence. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ template static TlvType *FindTlv(uint8_t *aTlvsStart, uint16_t aTlvsLength) @@ -246,7 +246,7 @@ public: * @param[in] aTlvsStart A pointer to the start of the sequence of TLVs to search within. * @param[in] aTlvsLength The length (number of bytes) in TLV sequence. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ template static const TlvType *FindTlv(const uint8_t *aTlvsStart, uint16_t aTlvsLength) @@ -1477,7 +1477,7 @@ public: /** * This method gets the first Channel Mask Entry in the Channel Mask TLV. * - * @returns A pointer to first Channel Mask Entry or NULL if not found. + * @returns A pointer to first Channel Mask Entry or nullptr if not found. * */ const ChannelMaskEntryBase *GetFirstEntry(void) const; @@ -1485,7 +1485,7 @@ public: /** * This method gets the first Channel Mask Entry in the Channel Mask TLV. * - * @returns A pointer to first Channel Mask Entry or NULL if not found. + * @returns A pointer to first Channel Mask Entry or nullptr if not found. * */ ChannelMaskEntryBase *GetFirstEntry(void); @@ -1693,7 +1693,7 @@ public: */ void SetVendorName(const char *aVendorName) { - uint16_t len = (aVendorName == NULL) ? 0 : StringLength(aVendorName, sizeof(mVendorName)); + uint16_t len = (aVendorName == nullptr) ? 0 : StringLength(aVendorName, sizeof(mVendorName)); SetLength(static_cast(len)); @@ -1762,7 +1762,7 @@ public: */ void SetVendorModel(const char *aVendorModel) { - uint16_t len = (aVendorModel == NULL) ? 0 : StringLength(aVendorModel, sizeof(mVendorModel)); + uint16_t len = (aVendorModel == nullptr) ? 0 : StringLength(aVendorModel, sizeof(mVendorModel)); SetLength(static_cast(len)); @@ -1831,7 +1831,7 @@ public: */ void SetVendorSwVersion(const char *aVendorSwVersion) { - uint16_t len = (aVendorSwVersion == NULL) ? 0 : StringLength(aVendorSwVersion, sizeof(mVendorSwVersion)); + uint16_t len = (aVendorSwVersion == nullptr) ? 0 : StringLength(aVendorSwVersion, sizeof(mVendorSwVersion)); SetLength(static_cast(len)); @@ -1900,7 +1900,7 @@ public: */ void SetVendorData(const char *aVendorData) { - uint16_t len = (aVendorData == NULL) ? 0 : StringLength(aVendorData, sizeof(mVendorData)); + uint16_t len = (aVendorData == nullptr) ? 0 : StringLength(aVendorData, sizeof(mVendorData)); SetLength(static_cast(len)); diff --git a/src/core/meshcop/panid_query_client.cpp b/src/core/meshcop/panid_query_client.cpp index 9a5684a09..217ef781f 100644 --- a/src/core/meshcop/panid_query_client.cpp +++ b/src/core/meshcop/panid_query_client.cpp @@ -50,8 +50,8 @@ namespace ot { PanIdQueryClient::PanIdQueryClient(Instance &aInstance) : InstanceLocator(aInstance) - , mCallback(NULL) - , mContext(NULL) + , mCallback(nullptr) + , mContext(nullptr) , mPanIdQuery(OT_URI_PATH_PANID_CONFLICT, &PanIdQueryClient::HandleConflict, this) { Get().AddResource(mPanIdQuery); @@ -66,10 +66,10 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, otError error = OT_ERROR_NONE; MeshCoP::ChannelMaskTlv channelMask; Ip6::MessageInfo messageInfo; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; VerifyOrExit(Get().IsActive(), error = OT_ERROR_INVALID_STATE); - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, @@ -97,7 +97,7 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -125,7 +125,7 @@ void PanIdQueryClient::HandleConflict(Coap::Message &aMessage, const Ip6::Messag VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0, OT_NOOP); - if (mCallback != NULL) + if (mCallback != nullptr) { mCallback(panId, mask, mContext); } diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index bf3e19417..a6aeb0ce0 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -54,9 +54,9 @@ namespace Dhcp6 { Dhcp6Client::Dhcp6Client(Instance &aInstance) : InstanceLocator(aInstance) , mSocket(Get()) - , mTrickleTimer(aInstance, Dhcp6Client::HandleTrickleTimer, NULL, this) + , mTrickleTimer(aInstance, Dhcp6Client::HandleTrickleTimer, nullptr, this) , mStartTime(0) - , mIdentityAssociationCurrent(NULL) + , mIdentityAssociationCurrent(nullptr) { memset(mIdentityAssociations, 0, sizeof(mIdentityAssociations)); } @@ -114,7 +114,7 @@ void Dhcp6Client::UpdateAddresses(void) while (Get().GetNextOnMeshPrefix(iterator, config) == OT_ERROR_NONE) { - IdentityAssociation *ia = NULL; + IdentityAssociation *ia = nullptr; if (!config.mDhcp) { @@ -128,7 +128,7 @@ void Dhcp6Client::UpdateAddresses(void) if (mIdentityAssociations[i].mStatus == kIaStatusInvalid) { // record an available ia - if (ia == NULL) + if (ia == nullptr) { ia = &mIdentityAssociations[i]; } @@ -142,7 +142,7 @@ void Dhcp6Client::UpdateAddresses(void) if (!found) { - if (ia != NULL) + if (ia != nullptr) { ia->mPrefixAgentRloc = config.mRloc16; ia->mNetifAddress.mAddress = config.mPrefix.mPrefix; @@ -189,7 +189,7 @@ bool Dhcp6Client::ProcessNextIdentityAssociation() bool rval = false; // not interrupt in-progress solicit - VerifyOrExit(mIdentityAssociationCurrent == NULL || mIdentityAssociationCurrent->mStatus != kIaStatusSoliciting, + VerifyOrExit(mIdentityAssociationCurrent == nullptr || mIdentityAssociationCurrent->mStatus != kIaStatusSoliciting, OT_NOOP); mTrickleTimer.Stop(); @@ -227,7 +227,7 @@ bool Dhcp6Client::HandleTrickleTimer(void) { bool rval = true; - VerifyOrExit(mIdentityAssociationCurrent != NULL, rval = false); + VerifyOrExit(mIdentityAssociationCurrent != nullptr, rval = false); switch (mIdentityAssociationCurrent->mStatus) { @@ -242,7 +242,7 @@ bool Dhcp6Client::HandleTrickleTimer(void) break; case kIaStatusSolicitReplied: - mIdentityAssociationCurrent = NULL; + mIdentityAssociationCurrent = nullptr; if (!ProcessNextIdentityAssociation()) { @@ -267,7 +267,7 @@ void Dhcp6Client::Solicit(uint16_t aRloc16) Message * message; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = mSocket.NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = mSocket.NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message)); SuccessOrExit(error = AppendElapsedTime(*message)); @@ -290,7 +290,7 @@ void Dhcp6Client::Solicit(uint16_t aRloc16) exit: - if (message != NULL) + if (message != nullptr) { otLogWarnIp6("Failed to send DHCPv6 Solicit: %s", otThreadErrorToString(error)); @@ -342,7 +342,7 @@ otError Dhcp6Client::AppendIaNa(Message &aMessage, uint16_t aRloc16) uint16_t length = 0; IaNa option; - VerifyOrExit(mIdentityAssociationCurrent != NULL, error = OT_ERROR_DROP); + VerifyOrExit(mIdentityAssociationCurrent != nullptr, error = OT_ERROR_DROP); for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i) { diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index 52499e8fc..3cef3dabc 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -147,7 +147,7 @@ void Dhcp6Server::Stop(void) void Dhcp6Server::AddPrefixAgent(const otIp6Prefix &aIp6Prefix, const Lowpan::Context &aContext) { otError error = OT_ERROR_NONE; - PrefixAgent *newEntry = NULL; + PrefixAgent *newEntry = nullptr; for (size_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { @@ -162,7 +162,7 @@ void Dhcp6Server::AddPrefixAgent(const otIp6Prefix &aIp6Prefix, const Lowpan::Co } } - VerifyOrExit(newEntry != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(newEntry != nullptr, error = OT_ERROR_NO_BUFS); newEntry->Set(aIp6Prefix, Get().GetMeshLocalPrefix(), aContext.mContextId); Get().AddUnicastAddress(newEntry->GetAloc()); @@ -335,7 +335,7 @@ otError Dhcp6Server::SendReply(otIp6Address &aDst, uint8_t *aTransactionId, Clie Ip6::MessageInfo messageInfo; Message * message; - VerifyOrExit((message = mSocket.NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = mSocket.NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, aTransactionId)); SuccessOrExit(error = AppendServerIdentifier(*message)); SuccessOrExit(error = AppendClientIdentifier(*message, aClientId)); @@ -350,7 +350,7 @@ otError Dhcp6Server::SendReply(otIp6Address &aDst, uint8_t *aTransactionId, Clie exit: - if (message != NULL && error != OT_ERROR_NONE) + if (message != nullptr && error != OT_ERROR_NONE) { message->Free(); } diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index a58b891b1..a8afec9f0 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -49,9 +49,9 @@ namespace ot { namespace Dns { QueryMetadata::QueryMetadata(void) - : mHostname(NULL) - , mResponseHandler(NULL) - , mResponseContext(NULL) + : mHostname(nullptr) + , mResponseHandler(nullptr) + , mResponseContext(nullptr) , mTransmissionTime() , mDestinationPort(0) , mRetransmissionCount(0) @@ -61,7 +61,7 @@ QueryMetadata::QueryMetadata(void) } QueryMetadata::QueryMetadata(otDnsResponseHandler aHandler, void *aContext) - : mHostname(NULL) + : mHostname(nullptr) , mResponseHandler(aHandler) , mResponseContext(aContext) , mTransmissionTime() @@ -98,13 +98,13 @@ otError Client::Stop(void) QueryMetadata queryMetadata; // Remove all pending queries. - while (message != NULL) + while (message != nullptr) { messageToRemove = message; message = message->GetNext(); queryMetadata.ReadFrom(*messageToRemove); - FinalizeDnsTransaction(*messageToRemove, queryMetadata, NULL, 0, OT_ERROR_ABORT); + FinalizeDnsTransaction(*messageToRemove, queryMetadata, nullptr, 0, OT_ERROR_ABORT); } return mSocket.Close(); @@ -114,13 +114,13 @@ otError Client::Query(const otDnsQuery *aQuery, otDnsResponseHandler aHandler, v { otError error; QueryMetadata queryMetadata(aHandler, aContext); - Message * message = NULL; - Message * messageCopy = NULL; + Message * message = nullptr; + Message * messageCopy = nullptr; Header header; QuestionAaaa question; const Ip6::MessageInfo *messageInfo; - VerifyOrExit(aQuery->mHostname != NULL && aQuery->mMessageInfo != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aQuery->mHostname != nullptr && aQuery->mMessageInfo != nullptr, error = OT_ERROR_INVALID_ARGS); header.SetMessageId(mMessageId++); header.SetType(Header::kTypeQuery); @@ -133,7 +133,7 @@ otError Client::Query(const otDnsQuery *aQuery, otDnsResponseHandler aHandler, v header.SetQuestionCount(1); - VerifyOrExit((message = NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMessage(header)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendCompressedHostname(*message, aQuery->mHostname)); SuccessOrExit(error = question.AppendTo(*message)); @@ -147,7 +147,7 @@ otError Client::Query(const otDnsQuery *aQuery, otDnsResponseHandler aHandler, v queryMetadata.mDestinationAddress = messageInfo->GetPeerAddr(); queryMetadata.mRetransmissionCount = 0; - VerifyOrExit((messageCopy = CopyAndEnqueueMessage(*message, queryMetadata)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = CopyAndEnqueueMessage(*message, queryMetadata)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = SendMessage(*message, *messageInfo)); exit: @@ -170,9 +170,9 @@ exit: Message *Client::NewMessage(const Header &aHeader) { - Message *message = NULL; + Message *message = nullptr; - VerifyOrExit((message = mSocket.NewMessage(sizeof(aHeader))) != NULL, OT_NOOP); + VerifyOrExit((message = mSocket.NewMessage(sizeof(aHeader))) != nullptr, OT_NOOP); IgnoreError(message->Prepend(&aHeader, sizeof(aHeader))); message->SetOffset(0); @@ -183,10 +183,10 @@ exit: Message *Client::CopyAndEnqueueMessage(const Message &aMessage, const QueryMetadata &aQueryMetadata) { otError error = OT_ERROR_NONE; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; // Create a message copy for further retransmissions. - VerifyOrExit((messageCopy = aMessage.Clone()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = aMessage.Clone()) != nullptr, error = OT_ERROR_NO_BUFS); // Append the copy with retransmission data and add it to the queue. SuccessOrExit(error = aQueryMetadata.AppendTo(*messageCopy)); @@ -196,10 +196,10 @@ Message *Client::CopyAndEnqueueMessage(const Message &aMessage, const QueryMetad exit: - if (error != OT_ERROR_NONE && messageCopy != NULL) + if (error != OT_ERROR_NONE && messageCopy != nullptr) { messageCopy->Free(); - messageCopy = NULL; + messageCopy = nullptr; } return messageCopy; @@ -209,7 +209,7 @@ void Client::DequeueMessage(Message &aMessage) { mPendingQueries.Dequeue(aMessage); - if (mRetransmissionTimer.IsRunning() && (mPendingQueries.GetHead() == NULL)) + if (mRetransmissionTimer.IsRunning() && (mPendingQueries.GetHead() == nullptr)) { // No more requests pending, stop the timer. mRetransmissionTimer.Stop(); @@ -227,10 +227,10 @@ otError Client::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMessageI void Client::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; // Create a message copy for lower layers. - VerifyOrExit((messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(QueryMetadata))) != NULL, + VerifyOrExit((messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(QueryMetadata))) != nullptr, error = OT_ERROR_NO_BUFS); // Send the copy. @@ -242,7 +242,7 @@ exit: { otLogWarnIp6("Failed to send DNS request: %s", otThreadErrorToString(error)); - if (messageCopy != NULL) + if (messageCopy != nullptr) { messageCopy->Free(); } @@ -363,7 +363,7 @@ Message *Client::FindRelatedQuery(const Header &aResponseHeader, QueryMetadata & uint16_t messageId; Message *message = mPendingQueries.GetHead(); - while (message != NULL) + while (message != nullptr) { // Partially read DNS header to obtain message ID only. uint16_t count = message->Read(message->GetOffset(), sizeof(messageId), &messageId); @@ -392,7 +392,7 @@ void Client::FinalizeDnsTransaction(Message & aQuery, { DequeueMessage(aQuery); - if (aQueryMetadata.mResponseHandler != NULL) + if (aQueryMetadata.mResponseHandler != nullptr) { aQueryMetadata.mResponseHandler(aQueryMetadata.mResponseContext, aQueryMetadata.mHostname, aAddress, aTtl, aResult); @@ -413,7 +413,7 @@ void Client::HandleRetransmissionTimer(void) Message * nextMessage; Ip6::MessageInfo messageInfo; - for (message = mPendingQueries.GetHead(); message != NULL; message = nextMessage) + for (message = mPendingQueries.GetHead(); message != nullptr; message = nextMessage) { nextMessage = message->GetNext(); @@ -424,7 +424,7 @@ void Client::HandleRetransmissionTimer(void) if (queryMetadata.mRetransmissionCount >= kMaxRetransmit) { // No expected response. - FinalizeDnsTransaction(*message, queryMetadata, NULL, 0, OT_ERROR_RESPONSE_TIMEOUT); + FinalizeDnsTransaction(*message, queryMetadata, nullptr, 0, OT_ERROR_RESPONSE_TIMEOUT); continue; } @@ -470,7 +470,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag Header responseHeader; QueryMetadata queryMetadata; ResourceRecordAaaa record; - Message * message = NULL; + Message * message = nullptr; uint16_t offset; VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(responseHeader), &responseHeader) == sizeof(responseHeader), @@ -482,7 +482,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag aMessage.MoveOffset(sizeof(responseHeader)); offset = aMessage.GetOffset(); - VerifyOrExit((message = FindRelatedQuery(responseHeader, queryMetadata)) != NULL, OT_NOOP); + VerifyOrExit((message = FindRelatedQuery(responseHeader, queryMetadata)) != nullptr, OT_NOOP); VerifyOrExit(responseHeader.GetResponseCode() == Header::kResponseSuccess, error = OT_ERROR_FAILED); @@ -517,9 +517,9 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag exit: - if (message != NULL && error != OT_ERROR_NONE) + if (message != nullptr && error != OT_ERROR_NONE) { - FinalizeDnsTransaction(*message, queryMetadata, NULL, 0, error); + FinalizeDnsTransaction(*message, queryMetadata, nullptr, 0, error); } } diff --git a/src/core/net/icmp6.cpp b/src/core/net/icmp6.cpp index f9cb56a0e..a2ae84ab7 100644 --- a/src/core/net/icmp6.cpp +++ b/src/core/net/icmp6.cpp @@ -94,7 +94,7 @@ otError Icmp::SendError(IcmpHeader::Type aType, { otError error = OT_ERROR_NONE; MessageInfo messageInfoLocal; - Message * message = NULL; + Message * message = nullptr; IcmpHeader icmp6Header; Header ip6Header; Message::Settings settings(Message::kWithLinkSecurity, Message::kPriorityNet); @@ -113,7 +113,7 @@ otError Icmp::SendError(IcmpHeader::Type aType, messageInfoLocal = aMessageInfo; - VerifyOrExit((message = Get().NewMessage(0, settings)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage(0, settings)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetLength(sizeof(icmp6Header) + sizeof(ip6Header))); message->Write(sizeof(icmp6Header), sizeof(ip6Header), &ip6Header); @@ -129,7 +129,7 @@ otError Icmp::SendError(IcmpHeader::Type aType, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -197,7 +197,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe { otError error = OT_ERROR_NONE; IcmpHeader icmp6Header; - Message * replyMessage = NULL; + Message * replyMessage = nullptr; MessageInfo replyMessageInfo; uint16_t payloadLength; @@ -209,7 +209,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe icmp6Header.Init(); icmp6Header.SetType(IcmpHeader::kTypeEchoReply); - if ((replyMessage = Get().NewMessage(0)) == NULL) + if ((replyMessage = Get().NewMessage(0)) == nullptr) { otLogDebgIcmp("Failed to allocate a new message"); ExitNow(); @@ -236,7 +236,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe exit: - if (error != OT_ERROR_NONE && replyMessage != NULL) + if (error != OT_ERROR_NONE && replyMessage != nullptr) { replyMessage->Free(); } diff --git a/src/core/net/icmp6.hpp b/src/core/net/icmp6.hpp index 8fa524c6b..690fb36be 100644 --- a/src/core/net/icmp6.hpp +++ b/src/core/net/icmp6.hpp @@ -228,7 +228,7 @@ public: { mReceiveCallback = aCallback; mContext = aContext; - mNext = NULL; + mNext = nullptr; } private: @@ -258,7 +258,7 @@ public: * * @param[in] aReserved The number of header bytes to reserve after the ICMP header. * - * @returns A pointer to the message or NULL if no buffers are available. + * @returns A pointer to the message or nullptr if no buffers are available. * */ Message *NewMessage(uint16_t aReserved); diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index b704a5964..e7774fd44 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -54,8 +54,8 @@ Ip6::Ip6(Instance &aInstance) : InstanceLocator(aInstance) , mForwardingEnabled(false) , mIsReceiveIp6FilterEnabled(false) - , mReceiveIp6DatagramCallback(NULL) - , mReceiveIp6DatagramCallbackContext(NULL) + , mReceiveIp6DatagramCallback(nullptr) + , mReceiveIp6DatagramCallbackContext(nullptr) , mSendQueue() , mSendQueueTask(aInstance, HandleSendQueue, this) , mIcmp(aInstance) @@ -77,12 +77,12 @@ Message *Ip6::NewMessage(const uint8_t *aData, uint16_t aDataLength, const Messa { Message *message = Get().New(Message::kTypeIp6, 0, aSettings); - VerifyOrExit(message != NULL, OT_NOOP); + VerifyOrExit(message != nullptr, OT_NOOP); if (message->Append(aData, aDataLength) != OT_ERROR_NONE) { message->Free(); - message = NULL; + message = nullptr; } exit: @@ -91,7 +91,7 @@ exit: Message *Ip6::NewMessage(const uint8_t *aData, uint16_t aDataLength) { - Message * message = NULL; + Message * message = nullptr; Message::Priority priority; SuccessOrExit(GetDatagramPriority(aData, aDataLength, priority)); @@ -161,7 +161,7 @@ otError Ip6::GetDatagramPriority(const uint8_t *aData, uint16_t aDataLen, Messag otError error = OT_ERROR_NONE; const Header *header; - VerifyOrExit((aData != NULL) && (aDataLen >= sizeof(Header)), error = OT_ERROR_INVALID_ARGS); + VerifyOrExit((aData != nullptr) && (aDataLen >= sizeof(Header)), error = OT_ERROR_INVALID_ARGS); header = reinterpret_cast(aData); VerifyOrExit(header->IsValid(), error = OT_ERROR_PARSE); @@ -242,7 +242,7 @@ otError Ip6::AddTunneledMplOption(Message &aMessage, Header &aHeader, MessageInf tunnelHeader.SetDestination(messageInfo.GetPeerAddr()); tunnelHeader.SetNextHeader(kProtoIp6); - VerifyOrExit((source = SelectSourceAddress(messageInfo)) != NULL, error = OT_ERROR_INVALID_SOURCE_ADDRESS); + VerifyOrExit((source = SelectSourceAddress(messageInfo)) != nullptr, error = OT_ERROR_INVALID_SOURCE_ADDRESS); tunnelHeader.SetSource(source->GetAddress()); @@ -282,7 +282,7 @@ otError Ip6::InsertMplOption(Message &aMessage, Header &aHeader, MessageInfo &aM aMessage.Write(0, sizeof(hbh), &hbh); // make space for MPL Option + padding by shifting hop-by-hop option header - SuccessOrExit(error = aMessage.Prepend(NULL, 8)); + SuccessOrExit(error = aMessage.Prepend(nullptr, 8)); aMessage.CopyTo(8, 0, hbhLength, aMessage); // insert MPL Option @@ -313,11 +313,11 @@ otError Ip6::InsertMplOption(Message &aMessage, Header &aHeader, MessageInfo &aM if (aHeader.GetDestination().IsMulticastLargerThanRealmLocal() && Get().HasSleepyChildrenSubscribed(aHeader.GetDestination())) { - Message *messageCopy = NULL; + Message *messageCopy = nullptr; - if ((messageCopy = aMessage.Clone()) != NULL) + if ((messageCopy = aMessage.Clone()) != nullptr) { - IgnoreError(HandleDatagram(*messageCopy, NULL, NULL, true)); + IgnoreError(HandleDatagram(*messageCopy, nullptr, nullptr, true)); otLogInfoIp6("Message copy for indirect transmission to sleepy children"); } else @@ -480,7 +480,7 @@ otError Ip6::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, uint8_t if (aMessageInfo.GetSockAddr().IsUnspecified() || aMessageInfo.GetSockAddr().IsMulticast()) { - VerifyOrExit((source = SelectSourceAddress(aMessageInfo)) != NULL, error = OT_ERROR_INVALID_SOURCE_ADDRESS); + VerifyOrExit((source = SelectSourceAddress(aMessageInfo)) != nullptr, error = OT_ERROR_INVALID_SOURCE_ADDRESS); header.SetSource(source->GetAddress()); } else @@ -519,9 +519,9 @@ otError Ip6::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, uint8_t #if OPENTHREAD_FTD if (Get().HasSleepyChildrenSubscribed(header.GetDestination())) { - Message *messageCopy = NULL; + Message *messageCopy = nullptr; - if ((messageCopy = aMessage.Clone()) != NULL) + if ((messageCopy = aMessage.Clone()) != nullptr) { otLogInfoIp6("Message copy for indirect transmission to sleepy children"); EnqueueDatagram(*messageCopy); @@ -562,10 +562,10 @@ void Ip6::HandleSendQueue(void) { Message *message; - while ((message = mSendQueue.GetHead()) != NULL) + while ((message = mSendQueue.GetHead()) != nullptr) { mSendQueue.Dequeue(*message); - IgnoreError(HandleDatagram(*message, NULL, NULL, false)); + IgnoreError(HandleDatagram(*message, nullptr, nullptr, false)); } } @@ -638,7 +638,7 @@ otError Ip6::FragmentDatagram(Message &aMessage, uint8_t aIpProto) otError error = OT_ERROR_NONE; Header header; FragmentHeader fragmentHeader; - Message * fragment = NULL; + Message * fragment = nullptr; uint16_t fragmentCnt = 0; uint16_t payloadFragment = 0; uint16_t offset = 0; @@ -678,7 +678,7 @@ otError Ip6::FragmentDatagram(Message &aMessage, uint8_t aIpProto) offset = fragmentCnt * FragmentHeader::BytesToFragmentOffset(maxPayloadFragment); fragmentHeader.SetOffset(offset); - VerifyOrExit((fragment = NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((fragment = NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = fragment->SetLength(aMessage.GetOffset() + sizeof(fragmentHeader) + payloadFragment)); header.SetPayloadLength(payloadFragment + sizeof(fragmentHeader)); @@ -697,7 +697,7 @@ otError Ip6::FragmentDatagram(Message &aMessage, uint8_t aIpProto) EnqueueDatagram(*fragment); fragmentCnt++; - fragment = NULL; + fragment = nullptr; otLogInfoIp6("Fragment %d with %d bytes sent", fragmentCnt, payloadFragment); } @@ -711,7 +711,7 @@ exit: otLogWarnIp6("No buffer for Ip6 fragmentation"); } - if (error != OT_ERROR_NONE && fragment != NULL) + if (error != OT_ERROR_NONE && fragment != nullptr) { fragment->Free(); } @@ -724,7 +724,7 @@ otError Ip6::HandleFragment(Message &aMessage, Netif *aNetif, MessageInfo &aMess otError error = OT_ERROR_NONE; Header header, headerBuffer; FragmentHeader fragmentHeader; - Message * message = NULL; + Message * message = nullptr; uint16_t offset = 0; uint16_t payloadFragment = 0; int assertValue = 0; @@ -768,9 +768,9 @@ otError Ip6::HandleFragment(Message &aMessage, Netif *aNetif, MessageInfo &aMess ExitNow(error = OT_ERROR_NO_BUFS); } - if (message == NULL) + if (message == nullptr) { - VerifyOrExit((message = NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetLength(aMessage.GetOffset())); message->SetTimeout(kIp6ReassemblyTimeout); @@ -825,7 +825,7 @@ otError Ip6::HandleFragment(Message &aMessage, Netif *aNetif, MessageInfo &aMess exit: if (error != OT_ERROR_DROP && error != OT_ERROR_NONE && isFragmented) { - if (message != NULL) + if (message != nullptr) { mReassemblyList.Dequeue(*message); message->Free(); @@ -863,7 +863,7 @@ void Ip6::HandleUpdateTimer(void) { UpdateReassemblyList(); - if (mReassemblyList.GetHead() != NULL) + if (mReassemblyList.GetHead() != nullptr) { mTimer.Start(kStateUpdatePeriod); } @@ -903,7 +903,7 @@ void Ip6::SendIcmpError(Message &aMessage, IcmpHeader::Type aIcmpType, IcmpHeade messageInfo.SetPeerAddr(header.GetSource()); messageInfo.SetSockAddr(header.GetDestination()); messageInfo.SetHopLimit(header.GetHopLimit()); - messageInfo.SetLinkInfo(NULL); + messageInfo.SetLinkInfo(nullptr); error = mIcmp.SendError(aIcmpType, aIcmpCode, messageInfo, aMessage); @@ -1026,10 +1026,10 @@ otError Ip6::ProcessReceiveCallback(const Message & aMessage, bool aFromNcpHost) { otError error = OT_ERROR_NONE; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; VerifyOrExit(!aFromNcpHost, error = OT_ERROR_NO_ROUTE); - VerifyOrExit(mReceiveIp6DatagramCallback != NULL, error = OT_ERROR_NO_ROUTE); + VerifyOrExit(mReceiveIp6DatagramCallback != nullptr, error = OT_ERROR_NO_ROUTE); // Do not forward reassembled IPv6 packets. VerifyOrExit(aMessage.GetLength() <= kMinimalMtu, error = OT_ERROR_DROP); @@ -1103,7 +1103,7 @@ otError Ip6::ProcessReceiveCallback(const Message & aMessage, } // make a copy of the datagram to pass to host - VerifyOrExit((messageCopy = aMessage.Clone()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = aMessage.Clone()) != nullptr, error = OT_ERROR_NO_BUFS); IgnoreError(RemoveMplOption(*messageCopy)); mReceiveIp6DatagramCallback(messageCopy, mReceiveIp6DatagramCallbackContext); @@ -1138,14 +1138,14 @@ otError Ip6::SendRaw(Message &aMessage) messageInfo.SetPeerAddr(header.GetSource()); messageInfo.SetSockAddr(header.GetDestination()); messageInfo.SetHopLimit(header.GetHopLimit()); - messageInfo.SetLinkInfo(NULL); + messageInfo.SetLinkInfo(nullptr); if (header.GetDestination().IsMulticast()) { SuccessOrExit(error = InsertMplOption(aMessage, header, messageInfo)); } - error = HandleDatagram(aMessage, NULL, NULL, true); + error = HandleDatagram(aMessage, nullptr, nullptr, true); freed = true; exit: @@ -1180,7 +1180,7 @@ otError Ip6::HandleDatagram(Message &aMessage, Netif *aNetif, const void *aLinkM // determine destination of packet if (header.GetDestination().IsMulticast()) { - if (aNetif != NULL) + if (aNetif != nullptr) { if (aNetif->IsMulticastSubscribed(header.GetDestination())) { @@ -1214,7 +1214,7 @@ otError Ip6::HandleDatagram(Message &aMessage, Netif *aNetif, const void *aLinkM { forward = true; } - else if (aNetif == NULL) + else if (aNetif == nullptr) { forward = true; } @@ -1278,7 +1278,7 @@ otError Ip6::HandleDatagram(Message &aMessage, Netif *aNetif, const void *aLinkM ExitNow(); } - if (aNetif != NULL) + if (aNetif != nullptr) { VerifyOrExit(mForwardingEnabled, forward = false); header.SetHopLimit(header.GetHopLimit() - 1); @@ -1346,7 +1346,7 @@ bool Ip6::ShouldForwardToThread(const MessageInfo &aMessageInfo) const // on-link global address ExitNow(rval = true); } - else if (Get().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(), NULL) == + else if (Get().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(), nullptr) == OT_ERROR_NONE) { // route @@ -1365,7 +1365,7 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) { Address * destination = &aMessageInfo.GetPeerAddr(); uint8_t destinationScope = destination->GetScope(); - const NetifUnicastAddress *rvalAddr = NULL; + const NetifUnicastAddress *rvalAddr = nullptr; uint8_t rvalPrefixMatched = 0; for (const NetifUnicastAddress *addr = Get().GetUnicastAddresses(); addr; addr = addr->GetNext()) @@ -1392,7 +1392,7 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) overrideScope = destinationScope; } - if (rvalAddr == NULL) + if (rvalAddr == nullptr) { // Rule 0: Prefer any address rvalAddr = addr; diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index e8bf8bf13..fd0697409 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -120,7 +120,7 @@ public: * @param[in] aReserved The number of header bytes to reserve following the IPv6 header. * @param[in] aSettings The message settings. * - * @returns A pointer to the message or NULL if insufficient message buffers are available. + * @returns A pointer to the message or nullptr if insufficient message buffers are available. * */ Message *NewMessage(uint16_t aReserved, const Message::Settings &aSettings = Message::Settings::GetDefault()); @@ -132,7 +132,8 @@ public: * @param[in] aDataLength The size of the IPV6 datagram buffer pointed by @p aData. * @param[in] aSettings The message settings. * - * @returns A pointer to the message or NULL if malformed IPv6 header or insufficient message buffers are available. + * @returns A pointer to the message or nullptr if malformed IPv6 header or insufficient message buffers are + * available. * */ Message *NewMessage(const uint8_t *aData, uint16_t aDataLength, const Message::Settings &aSettings); @@ -145,7 +146,8 @@ public: * @param[in] aData A pointer to the IPv6 datagram buffer. * @param[in] aDataLength The size of the IPV6 datagram buffer pointed by @p aData. * - * @returns A pointer to the message or NULL if malformed IPv6 header or insufficient message buffers are available. + * @returns A pointer to the message or nullptr if malformed IPv6 header or insufficient message buffers are + * available. * */ Message *NewMessage(const uint8_t *aData, uint16_t aDataLength); @@ -266,7 +268,7 @@ public: * the Thread control traffic filter setting. * * @param[in] aCallback A pointer to a function that is called when an IPv6 datagram is received - * or NULL to disable the callback. + * or nullptr to disable the callback. * @param[in] aCallbackContext A pointer to application-specific context. * * @sa IsReceiveIp6FilterEnabled @@ -320,7 +322,7 @@ public: * * @param[in] aMessageInfo A reference to the message information. * - * @returns A pointer to the selected IPv6 source address or NULL if no source address was found. + * @returns A pointer to the selected IPv6 source address or nullptr if no source address was found. * */ const NetifUnicastAddress *SelectSourceAddress(MessageInfo &aMessageInfo); diff --git a/src/core/net/ip6_address.cpp b/src/core/net/ip6_address.cpp index 1f4d87bc5..9744ccfb8 100644 --- a/src/core/net/ip6_address.cpp +++ b/src/core/net/ip6_address.cpp @@ -344,8 +344,8 @@ otError Address::FromString(const char *aBuf) otError error = OT_ERROR_NONE; uint8_t * dst = reinterpret_cast(mFields.m8); uint8_t * endp = reinterpret_cast(mFields.m8 + 15); - uint8_t * colonp = NULL; - const char *colonc = NULL; + uint8_t * colonp = nullptr; + const char *colonc = nullptr; uint16_t val = 0; uint8_t count = 0; bool first = true; @@ -379,7 +379,7 @@ otError Address::FromString(const char *aBuf) } else if (ch == ':') { - VerifyOrExit(colonp == NULL || first, error = OT_ERROR_PARSE); + VerifyOrExit(colonp == nullptr || first, error = OT_ERROR_PARSE); colonp = dst; } diff --git a/src/core/net/ip6_address.hpp b/src/core/net/ip6_address.hpp index a1f37f780..802a72ae7 100644 --- a/src/core/net/ip6_address.hpp +++ b/src/core/net/ip6_address.hpp @@ -591,7 +591,7 @@ public: /** * This method converts an IPv6 address string to binary. * - * @param[in] aBuf A pointer to the NULL-terminated string. + * @param[in] aBuf A pointer to the null-terminated string. * * @retval OT_ERROR_NONE Successfully parsed the IPv6 address string. * @retval OT_ERROR_INVALID_ARGS Failed to parse the IPv6 address string. diff --git a/src/core/net/ip6_mpl.cpp b/src/core/net/ip6_mpl.cpp index 73d5b34c4..5ab0f417b 100644 --- a/src/core/net/ip6_mpl.cpp +++ b/src/core/net/ip6_mpl.cpp @@ -45,7 +45,7 @@ namespace Ip6 { Mpl::Mpl(Instance &aInstance) : InstanceLocator(aInstance) - , mMatchingAddress(NULL) + , mMatchingAddress(nullptr) , mSeedSetTimer(aInstance, Mpl::HandleSeedSetTimer, this) , mSeedId(0) , mSequence(0) @@ -137,7 +137,7 @@ exit: otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) { otError error = OT_ERROR_NONE; - SeedEntry *insert = NULL; + SeedEntry *insert = nullptr; SeedEntry *group = mSeedSet; SeedEntry *evict = mSeedSet; uint8_t curCount = 0; @@ -149,7 +149,7 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) { // unused entries exist - if (insert == NULL) + if (insert == nullptr) { // no existing group, set insert and evict entry to be the same insert = &mSeedSet[i]; @@ -164,7 +164,7 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) { // processing new group - if (aSeedId == group->mSeedId && insert == NULL) + if (aSeedId == group->mSeedId && insert == nullptr) { // insert at end of existing group insert = &mSeedSet[i]; @@ -193,7 +193,7 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) // already received, drop message ExitNow(error = OT_ERROR_DROP); } - else if (insert == NULL && diff < 0) + else if (insert == nullptr && diff < 0) { // insert in order of sequence insert = &mSeedSet[i]; @@ -207,7 +207,7 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) // no free entries available, look to evict an existing entry OT_ASSERT(curCount != 0); - if (aSeedId == group->mSeedId && insert == NULL) + if (aSeedId == group->mSeedId && insert == nullptr) { // insert at end of existing group insert = &mSeedSet[kNumSeedEntries]; @@ -224,7 +224,7 @@ otError Mpl::UpdateSeedSet(uint16_t aSeedId, uint8_t aSequence) // require evict group size to have >= 2 entries VerifyOrExit(maxCount > 1, error = OT_ERROR_DROP); - if (insert == NULL) + if (insert == nullptr) { // no existing entries for aSeedId insert = evict; @@ -298,7 +298,7 @@ void Mpl::HandleSeedSetTimer(void) void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound) { otError error = OT_ERROR_NONE; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; Metadata metadata; uint8_t hopLimit = 0; @@ -310,7 +310,7 @@ void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSeque #endif VerifyOrExit(GetTimerExpirations() > 0, OT_NOOP); - VerifyOrExit((messageCopy = aMessage.Clone()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = aMessage.Clone()) != nullptr, error = OT_ERROR_NO_BUFS); if (!aIsOutbound) { @@ -332,7 +332,7 @@ void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSeque exit: - if (error != OT_ERROR_NONE && messageCopy != NULL) + if (error != OT_ERROR_NONE && messageCopy != nullptr) { messageCopy->Free(); } @@ -351,7 +351,7 @@ void Mpl::HandleRetransmissionTimer(void) Message * message; Message * nextMessage; - for (message = mBufferedMessageSet.GetHead(); message != NULL; message = nextMessage) + for (message = mBufferedMessageSet.GetHead(); message != nullptr; message = nextMessage) { nextMessage = message->GetNext(); @@ -373,7 +373,7 @@ void Mpl::HandleRetransmissionTimer(void) { Message *messageCopy = message->Clone(message->GetLength() - sizeof(Metadata)); - if (messageCopy != NULL) + if (messageCopy != nullptr) { if (metadata.mTransmissionCount > 1) { diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index 0fdafdbb8..901284a4f 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -47,7 +47,7 @@ namespace Ip6 { * Certain fixed multicast addresses are defined as a set of chained (linked-list) constant `otNetifMulticastAddress` * entries: * - * LinkLocalAllRouters -> RealmLocalAllRouters -> LinkLocalAll -> RealmLocalAll -> RealmLocalAllMplForwarders -> NULL + * LinkLocalAllRouters -> RealmLocalAllRouters -> LinkLocalAll -> RealmLocalAll -> RealmLocalAllMplForwarders -> nullptr * * All or a portion of the chain is appended to the end of `mMulticastAddresses` linked-list. If the interface is * subscribed to all-routers multicast addresses (using `SubscribeAllRoutersMulticast()`) then all the five entries @@ -58,7 +58,7 @@ namespace Ip6 { // "ff03::fc" const otNetifMulticastAddress Netif::kRealmLocalAllMplForwardersMulticastAddress = { {{{0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc}}}, - NULL}; + nullptr}; // "ff03::01" const otNetifMulticastAddress Netif::kRealmLocalAllNodesMulticastAddress = { @@ -85,8 +85,8 @@ Netif::Netif(Instance &aInstance) , mUnicastAddresses() , mMulticastAddresses() , mMulticastPromiscuous(false) - , mAddressCallback(NULL) - , mAddressCallbackContext(NULL) + , mAddressCallback(nullptr) + , mAddressCallbackContext(nullptr) { for (NetifUnicastAddress *entry = &mExtUnicastAddresses[0]; entry < OT_ARRAY_END(mExtUnicastAddresses); entry++) { @@ -131,7 +131,7 @@ void Netif::SubscribeAllNodesMulticast(void) tail = mMulticastAddresses.GetTail(); - if (tail == NULL) + if (tail == nullptr) { mMulticastAddresses.SetHead(&linkLocalAllNodesAddress); } @@ -142,7 +142,7 @@ void Netif::SubscribeAllNodesMulticast(void) Get().Signal(kEventIp6MulticastSubscribed); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); for (const NetifMulticastAddress *entry = &linkLocalAllNodesAddress; entry; entry = entry->GetNext()) { @@ -178,18 +178,18 @@ void Netif::UnsubscribeAllNodesMulticast(void) OT_ASSERT(prev != static_cast( const_cast(&kRealmLocalAllRoutersMulticastAddress))); - if (prev == NULL) + if (prev == nullptr) { mMulticastAddresses.Clear(); } else { - prev->SetNext(NULL); + prev->SetNext(nullptr); } Get().Signal(kEventIp6MulticastUnsubscribed); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); for (const NetifMulticastAddress *entry = &linkLocalAllNodesAddress; entry; entry = entry->GetNext()) { @@ -203,7 +203,7 @@ exit: void Netif::SubscribeAllRoutersMulticast(void) { otError error = OT_ERROR_NONE; - NetifMulticastAddress *prev = NULL; + NetifMulticastAddress *prev = nullptr; NetifMulticastAddress &linkLocalAllRoutersAddress = static_cast( const_cast(kLinkLocalAllRoutersMulticastAddress)); NetifMulticastAddress &linkLocalAllNodesAddress = @@ -235,7 +235,7 @@ void Netif::SubscribeAllRoutersMulticast(void) VerifyOrExit(prev != &realmLocalAllRoutersAddress, OT_NOOP); - if (prev == NULL) + if (prev == nullptr) { mMulticastAddresses.SetHead(&linkLocalAllRoutersAddress); } @@ -246,7 +246,7 @@ void Netif::SubscribeAllRoutersMulticast(void) Get().Signal(kEventIp6MulticastSubscribed); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); for (const NetifMulticastAddress *entry = &linkLocalAllRoutersAddress; entry != &linkLocalAllNodesAddress; entry = entry->GetNext()) @@ -278,7 +278,7 @@ void Netif::UnsubscribeAllRoutersMulticast(void) SuccessOrExit(mMulticastAddresses.Find(linkLocalAllRoutersAddress, prev)); - if (prev == NULL) + if (prev == nullptr) { mMulticastAddresses.SetHead(&linkLocalAllNodesAddress); } @@ -289,7 +289,7 @@ void Netif::UnsubscribeAllRoutersMulticast(void) Get().Signal(kEventIp6MulticastUnsubscribed); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); for (const NetifMulticastAddress *entry = &linkLocalAllRoutersAddress; entry != &linkLocalAllNodesAddress; entry = entry->GetNext()) @@ -307,7 +307,7 @@ void Netif::SubscribeMulticast(NetifMulticastAddress &aAddress) Get().Signal(kEventIp6MulticastSubscribed); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); mAddressCallback(&aAddress.mAddress, kMulticastPrefixLength, /* IsAdded */ true, mAddressCallbackContext); exit: @@ -320,7 +320,7 @@ void Netif::UnsubscribeMulticast(const NetifMulticastAddress &aAddress) Get().Signal(kEventIp6MulticastUnsubscribed); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); mAddressCallback(&aAddress.mAddress, kMulticastPrefixLength, /* IsAdded */ false, mAddressCallbackContext); exit: @@ -389,7 +389,7 @@ otError Netif::UnsubscribeExternalMulticast(const Address &aAddress) { otError error = OT_ERROR_NONE; NetifMulticastAddress *entry; - NetifMulticastAddress *last = NULL; + NetifMulticastAddress *last = nullptr; for (entry = mMulticastAddresses.GetHead(); entry; entry = entry->GetNext()) { @@ -405,7 +405,7 @@ otError Netif::UnsubscribeExternalMulticast(const Address &aAddress) last = entry; } - VerifyOrExit(entry != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NOT_FOUND); entry->MarkAsNotInUse(); @@ -439,7 +439,7 @@ void Netif::AddUnicastAddress(NetifUnicastAddress &aAddress) Get().Signal(aAddress.mRloc ? kEventThreadRlocAdded : kEventIp6AddressAdded); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); mAddressCallback(&aAddress.mAddress, aAddress.mPrefixLength, /* IsAdded */ true, mAddressCallbackContext); exit: @@ -452,7 +452,7 @@ void Netif::RemoveUnicastAddress(const NetifUnicastAddress &aAddress) Get().Signal(aAddress.mRloc ? kEventThreadRlocRemoved : kEventIp6AddressRemoved); - VerifyOrExit(mAddressCallback != NULL, OT_NOOP); + VerifyOrExit(mAddressCallback != nullptr, OT_NOOP); mAddressCallback(&aAddress.mAddress, aAddress.mPrefixLength, /* IsAdded */ false, mAddressCallbackContext); exit: @@ -502,7 +502,7 @@ otError Netif::RemoveExternalUnicastAddress(const Address &aAddress) { otError error = OT_ERROR_NONE; NetifUnicastAddress *entry; - NetifUnicastAddress *last = NULL; + NetifUnicastAddress *last = nullptr; for (entry = mUnicastAddresses.GetHead(); entry; entry = entry->GetNext()) { @@ -518,7 +518,7 @@ otError Netif::RemoveExternalUnicastAddress(const Address &aAddress) last = entry; } - VerifyOrExit(entry != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NOT_FOUND); entry->MarkAsNotInUse(); diff --git a/src/core/net/sntp_client.cpp b/src/core/net/sntp_client.cpp index 4307cd421..d7f7a417b 100644 --- a/src/core/net/sntp_client.cpp +++ b/src/core/net/sntp_client.cpp @@ -67,8 +67,8 @@ Header::Header(void) QueryMetadata::QueryMetadata(void) : mTransmitTimestamp(0) - , mResponseHandler(NULL) - , mResponseContext(NULL) + , mResponseHandler(nullptr) + , mResponseContext(nullptr) , mTransmissionTime(0) , mDestinationPort(0) , mRetransmissionCount(0) @@ -115,7 +115,7 @@ otError Client::Stop(void) QueryMetadata queryMetadata; // Remove all pending queries. - while (message != NULL) + while (message != nullptr) { messageToRemove = message; message = message->GetNext(); @@ -131,17 +131,17 @@ otError Client::Query(const otSntpQuery *aQuery, otSntpResponseHandler aHandler, { otError error; QueryMetadata queryMetadata(aHandler, aContext); - Message * message = NULL; - Message * messageCopy = NULL; + Message * message = nullptr; + Message * messageCopy = nullptr; Header header; const Ip6::MessageInfo *messageInfo; - VerifyOrExit(aQuery->mMessageInfo != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aQuery->mMessageInfo != nullptr, error = OT_ERROR_INVALID_ARGS); // Originate timestamp is used only as a unique token. header.SetTransmitTimestampSeconds(TimerMilli::GetNow().GetValue() / 1000 + kTimeAt1970); - VerifyOrExit((message = NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMessage(header)) != nullptr, error = OT_ERROR_NO_BUFS); messageInfo = static_cast(aQuery->mMessageInfo); @@ -152,7 +152,7 @@ otError Client::Query(const otSntpQuery *aQuery, otSntpResponseHandler aHandler, queryMetadata.mDestinationAddress = messageInfo->GetPeerAddr(); queryMetadata.mRetransmissionCount = 0; - VerifyOrExit((messageCopy = CopyAndEnqueueMessage(*message, queryMetadata)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = CopyAndEnqueueMessage(*message, queryMetadata)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = SendMessage(*message, *messageInfo)); exit: @@ -175,9 +175,9 @@ exit: Message *Client::NewMessage(const Header &aHeader) { - Message *message = NULL; + Message *message = nullptr; - VerifyOrExit((message = mSocket.NewMessage(sizeof(aHeader))) != NULL, OT_NOOP); + VerifyOrExit((message = mSocket.NewMessage(sizeof(aHeader))) != nullptr, OT_NOOP); IgnoreError(message->Prepend(&aHeader, sizeof(aHeader))); message->SetOffset(0); @@ -188,10 +188,10 @@ exit: Message *Client::CopyAndEnqueueMessage(const Message &aMessage, const QueryMetadata &aQueryMetadata) { otError error = OT_ERROR_NONE; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; // Create a message copy for further retransmissions. - VerifyOrExit((messageCopy = aMessage.Clone()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((messageCopy = aMessage.Clone()) != nullptr, error = OT_ERROR_NO_BUFS); // Append the copy with retransmission data and add it to the queue. SuccessOrExit(error = aQueryMetadata.AppendTo(*messageCopy)); @@ -201,10 +201,10 @@ Message *Client::CopyAndEnqueueMessage(const Message &aMessage, const QueryMetad exit: - if (error != OT_ERROR_NONE && messageCopy != NULL) + if (error != OT_ERROR_NONE && messageCopy != nullptr) { messageCopy->Free(); - messageCopy = NULL; + messageCopy = nullptr; } return messageCopy; @@ -214,7 +214,7 @@ void Client::DequeueMessage(Message &aMessage) { mPendingQueries.Dequeue(aMessage); - if (mRetransmissionTimer.IsRunning() && (mPendingQueries.GetHead() == NULL)) + if (mRetransmissionTimer.IsRunning() && (mPendingQueries.GetHead() == nullptr)) { // No more requests pending, stop the timer. mRetransmissionTimer.Stop(); @@ -232,10 +232,10 @@ otError Client::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMessageI void Client::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error; - Message *messageCopy = NULL; + Message *messageCopy = nullptr; // Create a message copy for lower layers. - VerifyOrExit((messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(QueryMetadata))) != NULL, + VerifyOrExit((messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(QueryMetadata))) != nullptr, error = OT_ERROR_NO_BUFS); // Send the copy. @@ -247,7 +247,7 @@ exit: { otLogWarnIp6("Failed to send SNTP request: %s", otThreadErrorToString(error)); - if (messageCopy != NULL) + if (messageCopy != nullptr) { messageCopy->Free(); } @@ -259,7 +259,7 @@ Message *Client::FindRelatedQuery(const Header &aResponseHeader, QueryMetadata & Header header; Message *message = mPendingQueries.GetHead(); - while (message != NULL) + while (message != nullptr) { // Read originate timestamp. aQueryMetadata.ReadFrom(*message); @@ -283,7 +283,7 @@ void Client::FinalizeSntpTransaction(Message & aQuery, { DequeueMessage(aQuery); - if (aQueryMetadata.mResponseHandler != NULL) + if (aQueryMetadata.mResponseHandler != nullptr) { aQueryMetadata.mResponseHandler(aQueryMetadata.mResponseContext, aTime, aResult); } @@ -303,7 +303,7 @@ void Client::HandleRetransmissionTimer(void) Message * nextMessage; Ip6::MessageInfo messageInfo; - for (message = mPendingQueries.GetHead(); message != NULL; message = nextMessage) + for (message = mPendingQueries.GetHead(); message != nullptr; message = nextMessage) { nextMessage = message->GetNext(); @@ -356,13 +356,13 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag otError error = OT_ERROR_NONE; Header responseHeader; QueryMetadata queryMetadata; - Message * message = NULL; + Message * message = nullptr; uint64_t unixTime = 0; VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(responseHeader), &responseHeader) == sizeof(responseHeader), OT_NOOP); - VerifyOrExit((message = FindRelatedQuery(responseHeader, queryMetadata)) != NULL, OT_NOOP); + VerifyOrExit((message = FindRelatedQuery(responseHeader, queryMetadata)) != nullptr, OT_NOOP); // Check if response came from the server. VerifyOrExit(responseHeader.GetMode() == Header::kModeServer, error = OT_ERROR_FAILED); @@ -404,7 +404,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag exit: - if (message != NULL && error != OT_ERROR_NONE) + if (message != nullptr && error != OT_ERROR_NONE) { FinalizeSntpTransaction(*message, queryMetadata, 0, error); } diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index a616b183a..0e9e49827 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -63,7 +63,7 @@ static bool IsMle(Instance &aInstance, uint16_t aPort) UdpSocket::UdpSocket(Udp &aUdp) : InstanceLocator(aUdp.GetInstance()) { - mHandle = NULL; + mHandle = nullptr; } Message *UdpSocket::NewMessage(uint16_t aReserved, const Message::Settings &aSettings) @@ -208,8 +208,8 @@ Udp::Udp(Instance &aInstance) , mReceivers() , mSockets() #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE - , mUdpForwarderContext(NULL) - , mUdpForwarder(NULL) + , mUdpForwarderContext(nullptr) + , mUdpForwarder(nullptr) #endif { } @@ -224,7 +224,7 @@ otError Udp::RemoveReceiver(UdpReceiver &aReceiver) otError error; SuccessOrExit(error = mReceivers.Remove(aReceiver)); - aReceiver.SetNext(NULL); + aReceiver.SetNext(nullptr); exit: return error; @@ -238,7 +238,7 @@ void Udp::AddSocket(UdpSocket &aSocket) void Udp::RemoveSocket(UdpSocket &aSocket) { SuccessOrExit(mSockets.Remove(aSocket)); - aSocket.SetNext(NULL); + aSocket.SetNext(nullptr); exit: return; @@ -272,7 +272,7 @@ otError Udp::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, uint8_t #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE if (aMessageInfo.IsHostInterface()) { - VerifyOrExit(mUdpForwarder != NULL, error = OT_ERROR_NO_ROUTE); + VerifyOrExit(mUdpForwarder != nullptr, error = OT_ERROR_NO_ROUTE); mUdpForwarder(&aMessage, aMessageInfo.mPeerPort, &aMessageInfo.GetPeerAddr(), aMessageInfo.mSockPort, mUdpForwarderContext); // message is consumed by the callback diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index 610332d57..b56a7ea8d 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -75,7 +75,7 @@ public: */ UdpReceiver(otUdpHandler aHandler, void *aContext) { - mNext = NULL; + mNext = nullptr; mHandler = aHandler; mContext = aContext; } @@ -110,7 +110,7 @@ public: * @param[in] aReserved The number of header bytes to reserve after the UDP header. * @param[in] aSettings The message settings (default is used if not provided). * - * @returns A pointer to the message or NULL if no buffers are available. + * @returns A pointer to the message or nullptr if no buffers are available. * */ Message *NewMessage(uint16_t aReserved, const Message::Settings &aSettings = Message::Settings::GetDefault()); @@ -272,7 +272,7 @@ public: * @param[in] aReserved The number of header bytes to reserve after the UDP header. * @param[in] aSettings The message settings. * - * @returns A pointer to the message or NULL if no buffers are available. + * @returns A pointer to the message or nullptr if no buffers are available. * */ Message *NewMessage(uint16_t aReserved, const Message::Settings &aSettings = Message::Settings::GetDefault()); diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index 428fb8320..d20a57c2e 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -107,7 +107,7 @@ public: /** * This callback method handles a "Receive Done" event from radio platform. * - * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed. * @param[in] aError OT_ERROR_NONE when successfully received a frame, * OT_ERROR_ABORT when reception was aborted and a frame was not received, * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. @@ -127,7 +127,7 @@ public: * This callback method handles a "Transmit Done" event from radio platform. * * @param[in] aFrame The frame that was transmitted. - * @param[in] aAckFrame A pointer to the ACK frame, NULL if no ACK was received. + * @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received. * @param[in] aError OT_ERROR_NONE when the frame was transmitted, * OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received, * OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on the @@ -152,7 +152,7 @@ public: /** * This callback method handles a "Receive Done" event from radio platform when diagnostics mode is enabled. * - * @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed. + * @param[in] aFrame A pointer to the received frame or nullptr if the receive operation failed. * @param[in] aError OT_ERROR_NONE when successfully received a frame, * OT_ERROR_ABORT when reception was aborted and a frame was not received, * OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space. diff --git a/src/core/radio/radio_callbacks.cpp b/src/core/radio/radio_callbacks.cpp index c03706109..11d713c23 100644 --- a/src/core/radio/radio_callbacks.cpp +++ b/src/core/radio/radio_callbacks.cpp @@ -73,7 +73,7 @@ void Radio::Callbacks::HandleDiagsTransmitDone(Mac::TxFrame &aFrame, otError aEr { #if OPENTHREAD_RADIO // Pass it to notify OpenThread `Diags` module on host side. - HandleTransmitDone(aFrame, NULL, aError); + HandleTransmitDone(aFrame, nullptr, aError); #else OT_UNUSED_VARIABLE(aFrame); Get().TransmitDone(aError); diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index 3df440734..4681cc99e 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -87,7 +87,7 @@ void AddressResolver::Clear(void) CacheEntryList *list = lists[index]; CacheEntry * entry; - while ((entry = list->Pop()) != NULL) + while ((entry = list->Pop()) != nullptr) { if (list == &mQueryList) { @@ -108,9 +108,9 @@ otError AddressResolver::GetNextCacheEntry(EntryInfo &aInfo, Iterator &aIterator list = reinterpret_cast(aIterator.mData[kIteratorListIndex]); entry = reinterpret_cast(aIterator.mData[kIteratorEntryIndex]); - while (entry == NULL) + while (entry == nullptr) { - if (list == NULL) + if (list == nullptr) { list = &mCachedList; } @@ -191,7 +191,7 @@ void AddressResolver::Remove(uint16_t aRloc16) AddressResolver::CacheEntry *AddressResolver::GetEntryAfter(CacheEntry *aPrev, CacheEntryList &aList) { - return (aPrev == NULL) ? aList.GetHead() : aPrev->GetNext(); + return (aPrev == nullptr) ? aList.GetHead() : aPrev->GetNext(); } void AddressResolver::Remove(Mac::ShortAddress aRloc16, bool aMatchRouterId) @@ -201,10 +201,10 @@ void AddressResolver::Remove(Mac::ShortAddress aRloc16, bool aMatchRouterId) for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++) { CacheEntryList *list = lists[index]; - CacheEntry * prev = NULL; + CacheEntry * prev = nullptr; CacheEntry * entry; - while ((entry = GetEntryAfter(prev, *list)) != NULL) + while ((entry = GetEntryAfter(prev, *list)) != nullptr) { if ((aMatchRouterId && Mle::Mle::RouterIdMatch(entry->GetRloc16(), aRloc16)) || (!aMatchRouterId && (entry->GetRloc16() == aRloc16))) @@ -229,7 +229,7 @@ AddressResolver::CacheEntry *AddressResolver::FindCacheEntryInList(CacheEntryLis { CacheEntry *entry; - for (CacheEntry *prev = NULL; (entry = GetEntryAfter(prev, aList)) != NULL; prev = entry) + for (CacheEntry *prev = nullptr; (entry = GetEntryAfter(prev, aList)) != nullptr; prev = entry) { if (entry->GetTarget() == aEid) { @@ -245,14 +245,14 @@ AddressResolver::CacheEntry *AddressResolver::FindCacheEntry(const Ip6::Address CacheEntryList *& aList, CacheEntry *& aPrevEntry) { - CacheEntry * entry = NULL; + CacheEntry * entry = nullptr; CacheEntryList *lists[] = {&mCachedList, &mSnoopedList, &mQueryList, &mQueryRetryList}; for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++) { aList = lists[index]; entry = FindCacheEntryInList(*aList, aEid, aPrevEntry); - VerifyOrExit(entry == NULL, OT_NOOP); + VerifyOrExit(entry == nullptr, OT_NOOP); } exit: @@ -271,7 +271,7 @@ void AddressResolver::Remove(const Ip6::Address &aEid, Reason aReason) CacheEntryList *list; entry = FindCacheEntry(aEid, list, prev); - VerifyOrExit(entry != NULL, OT_NOOP); + VerifyOrExit(entry != nullptr, OT_NOOP); RemoveCacheEntry(*entry, *list, prev, aReason); mUnusedList.Push(*entry); @@ -282,8 +282,8 @@ exit: AddressResolver::CacheEntry *AddressResolver::NewCacheEntry(bool aSnoopedEntry) { - CacheEntry * newEntry = NULL; - CacheEntry * prevEntry = NULL; + CacheEntry * newEntry = nullptr; + CacheEntry * prevEntry = nullptr; CacheEntryList *lists[] = {&mSnoopedList, &mQueryRetryList, &mQueryList, &mCachedList}; // The following order is used when trying to allocate a new cache @@ -298,7 +298,7 @@ AddressResolver::CacheEntry *AddressResolver::NewCacheEntry(bool aSnoopedEntry) // evicted till timeout). newEntry = mUnusedList.Pop(); - VerifyOrExit(newEntry == NULL, OT_NOOP); + VerifyOrExit(newEntry == nullptr, OT_NOOP); for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++) { @@ -307,7 +307,7 @@ AddressResolver::CacheEntry *AddressResolver::NewCacheEntry(bool aSnoopedEntry) CacheEntry * entry; uint16_t numNonEvictable = 0; - for (prev = NULL; (entry = GetEntryAfter(prev, *list)) != NULL; prev = entry) + for (prev = nullptr; (entry = GetEntryAfter(prev, *list)) != nullptr; prev = entry) { if ((list != &mCachedList) && !entry->CanEvict()) { @@ -319,7 +319,7 @@ AddressResolver::CacheEntry *AddressResolver::NewCacheEntry(bool aSnoopedEntry) prevEntry = prev; } - if (newEntry != NULL) + if (newEntry != nullptr) { RemoveCacheEntry(*newEntry, *list, prevEntry, kReasonEvictingForNewEntry); ExitNow(); @@ -370,7 +370,7 @@ otError AddressResolver::UpdateCacheEntry(const Ip6::Address &aEid, Mac::ShortAd CacheEntry * prev; entry = FindCacheEntry(aEid, list, prev); - VerifyOrExit(entry != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NOT_FOUND); if ((list == &mCachedList) || (list == &mSnoopedList)) { @@ -404,9 +404,9 @@ void AddressResolver::AddSnoopedCacheEntry(const Ip6::Address &aEid, Mac::ShortA CacheEntry *entry; entry = NewCacheEntry(/* aSnoopedEntry */ true); - VerifyOrExit(entry != NULL, OT_NOOP); + VerifyOrExit(entry != nullptr, OT_NOOP); - for (CacheEntry *snooped = mSnoopedList.GetHead(); snooped != NULL; snooped = snooped->GetNext()) + for (CacheEntry *snooped = mSnoopedList.GetHead(); snooped != nullptr; snooped = snooped->GetNext()) { if (!snooped->CanEvict()) { @@ -451,7 +451,7 @@ void AddressResolver::RestartAddressQueries(void) tail = mQueryList.GetTail(); - if (tail == NULL) + if (tail == nullptr) { mQueryList.SetHead(mQueryRetryList.GetHead()); } @@ -462,7 +462,7 @@ void AddressResolver::RestartAddressQueries(void) mQueryRetryList.Clear(); - for (CacheEntry *entry = mQueryList.GetHead(); entry != NULL; entry = entry->GetNext()) + for (CacheEntry *entry = mQueryList.GetHead(); entry != nullptr; entry = entry->GetNext()) { IgnoreError(SendAddressQuery(entry->GetTarget())); @@ -476,12 +476,12 @@ otError AddressResolver::Resolve(const Ip6::Address &aEid, uint16_t &aRloc16) { otError error = OT_ERROR_NONE; CacheEntry * entry; - CacheEntry * prev = NULL; + CacheEntry * prev = nullptr; CacheEntryList *list; entry = FindCacheEntry(aEid, list, prev); - if (entry == NULL) + if (entry == nullptr) { // If the entry is not present in any of the lists, try to // allocate a new entry and perform address query. We do not @@ -489,13 +489,13 @@ otError AddressResolver::Resolve(const Ip6::Address &aEid, uint16_t &aRloc16) // timeout. entry = NewCacheEntry(/* aSnoopedEntry */ false); - VerifyOrExit(entry != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NO_BUFS); entry->SetTarget(aEid); entry->SetRloc16(Mac::kShortAddrInvalid); entry->SetRetryDelay(kAddressQueryInitialRetryDelay); entry->SetCanEvict(false); - list = NULL; + list = nullptr; } if ((list == &mCachedList) || (list == &mSnoopedList)) @@ -535,7 +535,7 @@ otError AddressResolver::Resolve(const Ip6::Address &aEid, uint16_t &aRloc16) error = SendAddressQuery(aEid); VerifyOrExit(error == OT_ERROR_NONE, mUnusedList.Push(*entry)); - if (list == NULL) + if (list == nullptr) { LogCacheEntryChange(kEntryAdded, kReasonQueryRequest, *entry); } @@ -553,7 +553,7 @@ otError AddressResolver::SendAddressQuery(const Ip6::Address &aEid) Coap::Message * message; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = Get().NewPriorityMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_ADDRESS_QUERY)); @@ -577,7 +577,7 @@ exit: mTimer.Start(kStateUpdatePeriod); } - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -622,7 +622,7 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I target.ToString().AsCString(), rloc16); entry = FindCacheEntry(target, list, prev); - VerifyOrExit(entry != NULL, OT_NOOP); + VerifyOrExit(entry != nullptr, OT_NOOP); if (list == &mCachedList) { @@ -633,7 +633,7 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I // by more than one device. Try to resolve the duplicate // address by sending an Address Error message. - VerifyOrExit(entry->HasMeshLocalIid(meshLocalIid), SendAddressError(target, meshLocalIid, NULL)); + VerifyOrExit(entry->HasMeshLocalIid(meshLocalIid), SendAddressError(target, meshLocalIid, nullptr)); VerifyOrExit(lastTransactionTime < entry->GetLastTransactionTime(), OT_NOOP); } @@ -667,9 +667,9 @@ void AddressResolver::SendAddressError(const Ip6::Address &aTarget, Coap::Message * message; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); - message->Init(aDestination == NULL ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); + message->Init(aDestination == nullptr ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_ADDRESS_ERROR)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -677,7 +677,7 @@ void AddressResolver::SendAddressError(const Ip6::Address &aTarget, SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kMeshLocalEid, aMeshLocalIid, Ip6::Address::kInterfaceIdentifierSize)); - if (aDestination == NULL) + if (aDestination == nullptr) { messageInfo.GetPeerAddr().SetToRealmLocalAllRoutersMulticast(); } @@ -699,7 +699,7 @@ exit: { otLogInfoArp("Failed to send address error: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -802,7 +802,7 @@ void AddressResolver::HandleAddressQuery(Coap::Message &aMessage, const Ip6::Mes if (Get().IsUnicastAddress(target)) { - SendAddressQueryResponse(target, Get().GetMeshLocal64().GetIid(), NULL, + SendAddressQueryResponse(target, Get().GetMeshLocal64().GetIid(), nullptr, aMessageInfo.GetPeerAddr()); ExitNow(); } @@ -837,7 +837,7 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address &aTarget, Coap::Message * message; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = Get().NewPriorityMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_ADDRESS_NOTIFY)); @@ -848,7 +848,7 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address &aTarget, Ip6::Address::kInterfaceIdentifierSize)); SuccessOrExit(error = Tlv::AppendUint16Tlv(*message, ThreadTlv::kRloc16, Get().GetRloc16())); - if (aLastTransactionTime != NULL) + if (aLastTransactionTime != nullptr) { SuccessOrExit(error = Tlv::AppendUint32Tlv(*message, ThreadTlv::kLastTransactionTime, *aLastTransactionTime)); } @@ -863,7 +863,7 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address &aTarget, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -880,7 +880,7 @@ void AddressResolver::HandleTimer(void) CacheEntry *prev; CacheEntry *entry; - for (entry = mSnoopedList.GetHead(); entry != NULL; entry = entry->GetNext()) + for (entry = mSnoopedList.GetHead(); entry != nullptr; entry = entry->GetNext()) { if (entry->IsTimeoutZero()) { @@ -896,7 +896,7 @@ void AddressResolver::HandleTimer(void) } } - for (entry = mQueryRetryList.GetHead(); entry != NULL; entry = entry->GetNext()) + for (entry = mQueryRetryList.GetHead(); entry != nullptr; entry = entry->GetNext()) { if (entry->IsTimeoutZero()) { @@ -907,9 +907,9 @@ void AddressResolver::HandleTimer(void) entry->DecrementTimeout(); } - prev = NULL; + prev = nullptr; - while ((entry = GetEntryAfter(prev, mQueryList)) != NULL) + while ((entry = GetEntryAfter(prev, mQueryList)) != nullptr) { OT_ASSERT(!entry->IsTimeoutZero()); @@ -1040,7 +1040,7 @@ void AddressResolver::LogCacheEntryChange(EntryChange aChange, } otLogNoteArp("Cache entry %s: %s, 0x%04x%s%s - %s", change, aEntry.GetTarget().ToString().AsCString(), - aEntry.GetRloc16(), (aList == NULL) ? "" : ", list:", ListToString(aList), reason); + aEntry.GetRloc16(), (aList == nullptr) ? "" : ", list:", ListToString(aList), reason); } const char *AddressResolver::ListToString(const CacheEntryList *aList) const @@ -1077,17 +1077,17 @@ void AddressResolver::CacheEntry::Init(Instance &aInstance) AddressResolver::CacheEntry *AddressResolver::CacheEntry::GetNext(void) { - return (mNextIndex == kNoNextIndex) ? NULL : &Get().mCacheEntries[mNextIndex]; + return (mNextIndex == kNoNextIndex) ? nullptr : &Get().mCacheEntries[mNextIndex]; } const AddressResolver::CacheEntry *AddressResolver::CacheEntry::GetNext(void) const { - return (mNextIndex == kNoNextIndex) ? NULL : &Get().mCacheEntries[mNextIndex]; + return (mNextIndex == kNoNextIndex) ? nullptr : &Get().mCacheEntries[mNextIndex]; } void AddressResolver::CacheEntry::SetNext(CacheEntry *aEntry) { - VerifyOrExit(aEntry != NULL, mNextIndex = kNoNextIndex); + VerifyOrExit(aEntry != nullptr, mNextIndex = kNoNextIndex); mNextIndex = static_cast(aEntry - Get().mCacheEntries); exit: diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index dcf6608a7..9e103e153 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -306,7 +306,7 @@ private: void LogCacheEntryChange(EntryChange aChange, Reason aReason, const CacheEntry &aEntry, - CacheEntryList * aList = NULL); + CacheEntryList * aList = nullptr); const char *ListToString(const CacheEntryList *aList) const; diff --git a/src/core/thread/child_table.cpp b/src/core/thread/child_table.cpp index 0f3243be7..b54b20ba3 100644 --- a/src/core/thread/child_table.cpp +++ b/src/core/thread/child_table.cpp @@ -44,8 +44,8 @@ namespace ot { ChildTable::Iterator::Iterator(Instance &aInstance, Child::StateFilter aFilter) : InstanceLocator(aInstance) , mFilter(aFilter) - , mStart(NULL) - , mChild(NULL) + , mStart(nullptr) + , mChild(nullptr) { Reset(); } @@ -54,14 +54,14 @@ ChildTable::Iterator::Iterator(Instance &aInstance, Child::StateFilter aFilter, : InstanceLocator(aInstance) , mFilter(aFilter) , mStart(aStartingChild) - , mChild(NULL) + , mChild(nullptr) { Reset(); } void ChildTable::Iterator::Reset(void) { - if (mStart == NULL) + if (mStart == nullptr) { mStart = &Get().mChildren[0]; } @@ -80,7 +80,7 @@ void ChildTable::Iterator::Advance(void) Child * listStart = &childTable.mChildren[0]; Child * listEnd = &childTable.mChildren[childTable.mMaxChildrenAllowed]; - VerifyOrExit(mChild != NULL, OT_NOOP); + VerifyOrExit(mChild != nullptr, OT_NOOP); do { @@ -91,7 +91,7 @@ void ChildTable::Iterator::Advance(void) mChild = listStart; } - VerifyOrExit(mChild != mStart, mChild = NULL); + VerifyOrExit(mChild != mStart, mChild = nullptr); } while (!mChild->MatchesFilter(mFilter)); exit: @@ -119,7 +119,7 @@ void ChildTable::Clear(void) Child *ChildTable::GetChildAtIndex(uint16_t aChildIndex) { - Child *child = NULL; + Child *child = nullptr; VerifyOrExit(aChildIndex < mMaxChildrenAllowed, OT_NOOP); child = &mChildren[aChildIndex]; @@ -141,7 +141,7 @@ Child *ChildTable::GetNewChild(void) } } - child = NULL; + child = nullptr; exit: return child; @@ -159,7 +159,7 @@ Child *ChildTable::FindChild(uint16_t aRloc16, Child::StateFilter aFilter) } } - child = NULL; + child = nullptr; exit: return child; @@ -177,7 +177,7 @@ Child *ChildTable::FindChild(const Mac::ExtAddress &aAddress, Child::StateFilter } } - child = NULL; + child = nullptr; exit: return child; @@ -185,7 +185,7 @@ exit: Child *ChildTable::FindChild(const Mac::Address &aAddress, Child::StateFilter aFilter) { - Child *child = NULL; + Child *child = nullptr; switch (aAddress.GetType()) { diff --git a/src/core/thread/child_table.hpp b/src/core/thread/child_table.hpp index 1d2b9b54a..ae5c3d046 100644 --- a/src/core/thread/child_table.hpp +++ b/src/core/thread/child_table.hpp @@ -73,11 +73,12 @@ public: * given child and will go through all entries in the child table (matching the filter) till it gets back to * the starting `Child` entry. * - * If the given starting `Child` pointer is `NULL`, then the iterator starts from beginning of the child table. + * If the given starting `Child` pointer is `nullptr`, then the iterator starts from beginning of the child + * table. * * @param[in] aInstance A reference to the OpenThread instance. * @param[in] aFilter A child state filter. - * @param[in] aStartingChild A pointer to a child. If non-NULL, the iterator starts from the given entry. + * @param[in] aStartingChild A pointer to a child. If non-nullptr, the iterator starts from the given entry. * */ Iterator(Instance &aInstance, Child::StateFilter aFilter, Child *aStartingChild); @@ -96,14 +97,14 @@ public: * @retval FALSE The current entry is valid. * */ - bool IsDone(void) const { return (mChild == NULL); } + bool IsDone(void) const { return (mChild == nullptr); } /** * This method advances the iterator. * * The iterator is moved to point to the next `Child` entry matching the given state filter in the constructor. * If there are no more `Child` entries matching the given filter, the iterator becomes empty (i.e., - * `GetChild()` returns `NULL` and `IsDone()` returns `true`). + * `GetChild()` returns `nullptr` and `IsDone()` returns `true`). * */ void Advance(void); @@ -113,7 +114,7 @@ public: * * The iterator is moved to point to the next `Child` entry matching the given state filter in the constructor. * If there are no more `Child` entries matching the given filter, the iterator becomes empty (i.e., - * `GetChild()` returns `NULL` and `IsDone()` returns `true`). + * `GetChild()` returns `nullptr` and `IsDone()` returns `true`). * */ void operator++(void) { Advance(); } @@ -123,7 +124,7 @@ public: * * The iterator is moved to point to the next `Child` entry matching the given state filter in the constructor. * If there are no more `Child` entries matching the given filter, the iterator becomes empty (i.e., - * `GetChild()` returns `NULL` and `IsDone()` returns `true`). + * `GetChild()` returns `nullptr` and `IsDone()` returns `true`). * */ void operator++(int) { Advance(); } @@ -131,7 +132,7 @@ public: /** * This method gets the `Child` entry to which the iterator is currently pointing. * - * @returns A pointer to the `Child` entry, or `NULL` if the iterator is done and/or empty. + * @returns A pointer to the `Child` entry, or `nullptr` if the iterator is done and/or empty. * */ Child *GetChild(void) { return mChild; } @@ -167,12 +168,12 @@ public: uint16_t GetChildIndex(const Child &aChild) const { return static_cast(&aChild - mChildren); } /** - * This method returns a pointer to a `Child` entry at a given index, or `NULL` if the index is out of bounds, + * This method returns a pointer to a `Child` entry at a given index, or `nullptr` if the index is out of bounds, * i.e., index is larger or equal to maximum number of children allowed (@sa GetMaxChildrenAllowed()). * * @param[in] aChildIndex A child index. * - * @returns A pointer to the `Child` corresponding to the given index, or `NULL` if the index is out of bounds. + * @returns A pointer to the `Child` corresponding to the given index, or `nullptr` if the index is out of bounds. * */ Child *GetChildAtIndex(uint16_t aChildIndex); @@ -182,7 +183,7 @@ public: * * @note The returned child entry will be cleared (`memset` to zero). * - * @returns A pointer to a new `Child` entry, or `NULL` if all `Child` entries are in use. + * @returns A pointer to a new `Child` entry, or `nullptr` if all `Child` entries are in use. * */ Child *GetNewChild(void); @@ -193,7 +194,7 @@ public: * @param[in] aRloc16 A RLOC16 address. * @param[in] aFilter A child state filter. * - * @returns A pointer to the `Child` entry if one is found, or `NULL` otherwise. + * @returns A pointer to the `Child` entry if one is found, or `nullptr` otherwise. * */ Child *FindChild(uint16_t aRloc16, Child::StateFilter aFilter); @@ -205,7 +206,7 @@ public: * @param[in] aAddress A reference to an extended address. * @param[in] aFilter A child state filter. * - * @returns A pointer to the `Child` entry if one is found, or `NULL` otherwise. + * @returns A pointer to the `Child` entry if one is found, or `nullptr` otherwise. * */ Child *FindChild(const Mac::ExtAddress &aAddress, Child::StateFilter aFilter); @@ -216,7 +217,7 @@ public: * @param[in] aAddress A reference to a MAC address. * @param[in] aFilter A child state filter. * - * @returns A pointer to the `Child` entry if one is found, or `NULL` otherwise. + * @returns A pointer to the `Child` entry if one is found, or `nullptr` otherwise. * */ Child *FindChild(const Mac::Address &aAddress, Child::StateFilter aFilter); diff --git a/src/core/thread/discover_scanner.cpp b/src/core/thread/discover_scanner.cpp index 827f9d8a1..1282aa68e 100644 --- a/src/core/thread/discover_scanner.cpp +++ b/src/core/thread/discover_scanner.cpp @@ -46,8 +46,8 @@ namespace Mle { DiscoverScanner::DiscoverScanner(Instance &aInstance) : InstanceLocator(aInstance) - , mHandler(NULL) - , mHandlerContext(NULL) + , mHandler(nullptr) + , mHandlerContext(nullptr) , mTimer(aInstance, DiscoverScanner::HandleTimer, this) , mFilterIndexes() , mScanChannels() @@ -67,7 +67,7 @@ otError DiscoverScanner::Discover(const Mac::ChannelMask &aScanChannels, void * aContext) { otError error = OT_ERROR_NONE; - Message * message = NULL; + Message * message = nullptr; Ip6::Address destination; MeshCoP::DiscoveryRequestTlv discoveryRequest; @@ -77,7 +77,7 @@ otError DiscoverScanner::Discover(const Mac::ChannelMask &aScanChannels, if (mEnableFiltering) { - if (aFilterIndexes == NULL) + if (aFilterIndexes == nullptr) { Mac::ExtAddress extAddress; @@ -101,7 +101,7 @@ otError DiscoverScanner::Discover(const Mac::ChannelMask &aScanChannels, mScanChannels.Intersect(aScanChannels); } - VerifyOrExit((message = Get().NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(Message::kSubTypeMleDiscoverRequest); message->SetPanId(aPanId); SuccessOrExit(error = Get().AppendHeader(*message, Header::kCommandDiscoveryRequest)); @@ -136,7 +136,7 @@ otError DiscoverScanner::Discover(const Mac::ChannelMask &aScanChannels, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -216,7 +216,7 @@ void DiscoverScanner::HandleDiscoverComplete(void) if (mHandler) { - mHandler(NULL, mHandlerContext); + mHandler(nullptr, mHandlerContext); } break; diff --git a/src/core/thread/discover_scanner.hpp b/src/core/thread/discover_scanner.hpp index 0a578e9da..562978a23 100644 --- a/src/core/thread/discover_scanner.hpp +++ b/src/core/thread/discover_scanner.hpp @@ -77,7 +77,7 @@ public: * completes. * * The handler function format is `void (*oHandler)(ScanResult *aResult, void *aContext);`. End of scan is - * indicated by `aResult` pointer being set to NULL. + * indicated by `aResult` pointer being set to nullptr. * */ typedef otHandleActiveScanResult Handler; @@ -109,7 +109,7 @@ public: * @param[in] aEnableFiltering Enable filtering MLE Discovery Responses with steering data not containing a * given filter indexes. * @param[in] aFilterIndexes A pointer to `FilterIndexes` to use for filtering (when enabled). - * If set to NULL, filter indexes are derived from hash of factory-assigned EUI64. + * If set to nullptr, filter indexes are derived from hash of factory-assigned EUI64. * @param[in] aHandler A pointer to a function that is called on receiving an MLE Discovery Response. * @param[in] aContext A pointer to arbitrary context information. * diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index c13243822..6be910bed 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -76,7 +76,7 @@ void DuaManager::UpdateDomainUnicastAddress(BackboneRouter::Leader::DomainPrefix prefix = Get().GetDomainPrefix(); - OT_ASSERT(prefix != NULL); + OT_ASSERT(prefix != nullptr); mDomainUnicastAddress.mPrefixLength = prefix->mLength; mDomainUnicastAddress.GetAddress().Clear(); @@ -103,7 +103,7 @@ otError DuaManager::GenerateDomainUnicastAddressIid(void) otError error; uint8_t dadCounter = mDadCounter; - if ((error = Get().GenerateIid(mDomainUnicastAddress, NULL, 0, &dadCounter)) == OT_ERROR_NONE) + if ((error = Get().GenerateIid(mDomainUnicastAddress, nullptr, 0, &dadCounter)) == OT_ERROR_NONE) { if (dadCounter != mDadCounter) { diff --git a/src/core/thread/energy_scan_server.cpp b/src/core/thread/energy_scan_server.cpp index 19d21dee4..06fba9797 100644 --- a/src/core/thread/energy_scan_server.cpp +++ b/src/core/thread/energy_scan_server.cpp @@ -176,7 +176,7 @@ void EnergyScanServer::SendReport(void) Ip6::MessageInfo messageInfo; Coap::Message * message; - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_ENERGY_REPORT)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -203,7 +203,7 @@ exit: { otLogInfoMeshCoP("Failed to send scan results: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -220,7 +220,7 @@ void EnergyScanServer::HandleNotifierEvents(Notifier::Receiver &aReceiver, Event void EnergyScanServer::HandleNotifierEvents(Events aEvents) { if (aEvents.Contains(kEventThreadNetdataChanged) && !mActive && - Get().GetCommissioningData() == NULL) + Get().GetCommissioningData() == nullptr) { mActive = false; mTimer.Stop(); diff --git a/src/core/thread/indirect_sender.cpp b/src/core/thread/indirect_sender.cpp index 0592c042a..df3ff5035 100644 --- a/src/core/thread/indirect_sender.cpp +++ b/src/core/thread/indirect_sender.cpp @@ -74,7 +74,7 @@ void IndirectSender::Stop(void) for (ChildTable::Iterator iter(GetInstance(), Child::kInStateAnyExceptInvalid); !iter.IsDone(); iter++) { - iter.GetChild()->SetIndirectMessage(NULL); + iter.GetChild()->SetIndirectMessage(nullptr); mSourceMatchController.ResetMessageCount(*iter.GetChild()); } @@ -135,7 +135,7 @@ void IndirectSender::ClearAllMessagesForSleepyChild(Child &aChild) { if (Get().mSendMessage == message) { - Get().mSendMessage = NULL; + Get().mSendMessage = nullptr; } Get().mSendQueue.Dequeue(*message); @@ -143,7 +143,7 @@ void IndirectSender::ClearAllMessagesForSleepyChild(Child &aChild) } } - aChild.SetIndirectMessage(NULL); + aChild.SetIndirectMessage(nullptr); mSourceMatchController.ResetMessageCount(aChild); mDataPollHandler.RequestFrameChange(DataPollHandler::kPurgeFrame, aChild); @@ -185,7 +185,7 @@ void IndirectSender::HandleChildModeChange(Child &aChild, Mle::DeviceMode aOldMo } } - aChild.SetIndirectMessage(NULL); + aChild.SetIndirectMessage(nullptr); mSourceMatchController.ResetMessageCount(aChild); mDataPollHandler.RequestFrameChange(DataPollHandler::kPurgeFrame, aChild); @@ -240,12 +240,12 @@ void IndirectSender::RequestMessageUpdate(Child &aChild) // case where we have a pending "replace frame" request and while // waiting for the callback, the current message is removed. - if ((curMessage != NULL) && !curMessage->GetChildMask(Get().GetChildIndex(aChild))) + if ((curMessage != nullptr) && !curMessage->GetChildMask(Get().GetChildIndex(aChild))) { - // Set the indirect message for this child to NULL to ensure + // Set the indirect message for this child to nullptr to ensure // it is not processed on `HandleSentFrameToChild()` callback. - aChild.SetIndirectMessage(NULL); + aChild.SetIndirectMessage(nullptr); // Request a "frame purge" using `RequestFrameChange()` and // wait for `HandleFrameChangeDone()` callback for completion @@ -265,16 +265,16 @@ void IndirectSender::RequestMessageUpdate(Child &aChild) VerifyOrExit(curMessage != newMessage, OT_NOOP); - if (curMessage == NULL) + if (curMessage == nullptr) { - // Current message is NULL, but new message is not. + // Current message is nullptr, but new message is not. // We have a new indirect message. UpdateIndirectMessage(aChild); ExitNow(); } - // Current message and new message differ and are both non-NULL. + // Current message and new message differ and are both non-nullptr. // We need to request the frame to be replaced. The current // indirect message can be replaced only if it is the first // fragment. If a next fragment frame for message is already @@ -307,7 +307,7 @@ void IndirectSender::UpdateIndirectMessage(Child &aChild) aChild.SetIndirectFragmentOffset(0); aChild.SetIndirectTxSuccess(true); - if (message != NULL) + if (message != nullptr) { Mac::Address childAddress; @@ -325,7 +325,7 @@ otError IndirectSender::PrepareFrameForChild(Mac::TxFrame &aFrame, FrameContext VerifyOrExit(mEnabled, error = OT_ERROR_ABORT); - if (message == NULL) + if (message == nullptr) { PrepareEmptyFrame(aFrame, aChild, /* aAckRequest */ true); ExitNow(); @@ -457,7 +457,7 @@ void IndirectSender::HandleSentFrameToChild(const Mac::TxFrame &aFrame, // send any remaining fragments in the message to the child, if all tx // attempts of current frame already failed. - if (message != NULL) + if (message != nullptr) { nextOffset = message->GetLength(); } @@ -469,14 +469,14 @@ void IndirectSender::HandleSentFrameToChild(const Mac::TxFrame &aFrame, OT_UNREACHABLE_CODE(break); } - if ((message != NULL) && (nextOffset < message->GetLength())) + if ((message != nullptr) && (nextOffset < message->GetLength())) { aChild.SetIndirectFragmentOffset(nextOffset); mDataPollHandler.HandleNewFrame(aChild); ExitNow(); } - if (message != NULL) + if (message != nullptr) { // The indirect tx of this message to the child is done. @@ -484,7 +484,7 @@ void IndirectSender::HandleSentFrameToChild(const Mac::TxFrame &aFrame, uint16_t childIndex = Get().GetChildIndex(aChild); Mac::Address macDest; - aChild.SetIndirectMessage(NULL); + aChild.SetIndirectMessage(nullptr); aChild.GetLinkInfo().AddMessageTxStatus(aChild.GetIndirectTxSuccess()); // Enable short source address matching after the first indirect diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index df01ebde4..41ebe074c 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -59,7 +59,7 @@ MeshForwarder::MeshForwarder(Instance &aInstance) : InstanceLocator(aInstance) , mUpdateTimer(aInstance, MeshForwarder::HandleUpdateTimer, this) , mMessageNextOffset(0) - , mSendMessage(NULL) + , mSendMessage(nullptr) , mMeshSource() , mMeshDest() , mAddMeshHeader(false) @@ -104,13 +104,13 @@ void MeshForwarder::Stop(void) mUpdateTimer.Stop(); Get().Stop(); - while ((message = mSendQueue.GetHead()) != NULL) + while ((message = mSendQueue.GetHead()) != nullptr) { mSendQueue.Dequeue(*message); message->Free(); } - while ((message = mReassemblyList.GetHead()) != NULL) + while ((message = mReassemblyList.GetHead()) != nullptr) { mReassemblyList.Dequeue(*message); message->Free(); @@ -122,7 +122,7 @@ void MeshForwarder::Stop(void) #endif mEnabled = false; - mSendMessage = NULL; + mSendMessage = nullptr; Get().SetRxOnWhenIdle(false); exit: @@ -133,7 +133,7 @@ void MeshForwarder::RemoveMessage(Message &aMessage) { PriorityQueue *queue = aMessage.GetPriorityQueue(); - OT_ASSERT(queue != NULL); + OT_ASSERT(queue != nullptr); if (queue == &mSendQueue) { @@ -146,12 +146,12 @@ void MeshForwarder::RemoveMessage(Message &aMessage) if (mSendMessage == &aMessage) { - mSendMessage = NULL; + mSendMessage = nullptr; } } queue->Dequeue(aMessage); - LogMessage(kMessageEvict, aMessage, NULL, OT_ERROR_NO_BUFS); + LogMessage(kMessageEvict, aMessage, nullptr, OT_ERROR_NO_BUFS); aMessage.Free(); } @@ -174,7 +174,7 @@ void MeshForwarder::ScheduleTransmissionTask(void) VerifyOrExit(!mSendBusy && !mTxPaused, OT_NOOP); mSendMessage = GetDirectTransmission(); - VerifyOrExit(mSendMessage != NULL, OT_NOOP); + VerifyOrExit(mSendMessage != nullptr, OT_NOOP); if (mSendMessage->GetOffset() == 0) { @@ -242,7 +242,7 @@ Message *MeshForwarder::GetDirectTransmission(void) default: mSendQueue.Dequeue(*curMessage); - LogMessage(kMessageDrop, *curMessage, NULL, error); + LogMessage(kMessageDrop, *curMessage, nullptr, error); curMessage->Free(); continue; } @@ -401,7 +401,7 @@ otError MeshForwarder::HandleFrameRequest(Mac::TxFrame &aFrame) otError error = OT_ERROR_NONE; VerifyOrExit(mEnabled, error = OT_ERROR_ABORT); - VerifyOrExit(mSendMessage != NULL, error = OT_ERROR_ABORT); + VerifyOrExit(mSendMessage != nullptr, error = OT_ERROR_ABORT); mSendBusy = true; @@ -736,12 +736,12 @@ start: Neighbor *MeshForwarder::UpdateNeighborOnSentFrame(Mac::TxFrame &aFrame, otError aError, const Mac::Address &aMacDest) { - Neighbor *neighbor = NULL; + Neighbor *neighbor = nullptr; VerifyOrExit(mEnabled, OT_NOOP); neighbor = Get().GetNeighbor(aMacDest); - VerifyOrExit(neighbor != NULL, OT_NOOP); + VerifyOrExit(neighbor != nullptr, OT_NOOP); VerifyOrExit(aFrame.GetAckRequest(), OT_NOOP); @@ -766,7 +766,7 @@ exit: void MeshForwarder::HandleSentFrame(Mac::TxFrame &aFrame, otError aError) { - Neighbor * neighbor = NULL; + Neighbor * neighbor = nullptr; Mac::Address macDest; OT_ASSERT((aError == OT_ERROR_NONE) || (aError == OT_ERROR_CHANNEL_ACCESS_FAILURE) || (aError == OT_ERROR_ABORT) || @@ -782,7 +782,7 @@ void MeshForwarder::HandleSentFrame(Mac::TxFrame &aFrame, otError aError) neighbor = UpdateNeighborOnSentFrame(aFrame, aError, macDest); } - VerifyOrExit(mSendMessage != NULL, OT_NOOP); + VerifyOrExit(mSendMessage != nullptr, OT_NOOP); OT_ASSERT(mSendMessage->GetDirectTransmission()); if (aError != OT_ERROR_NONE) @@ -813,7 +813,7 @@ void MeshForwarder::HandleSentFrame(Mac::TxFrame &aFrame, otError aError) mSendMessage->ClearDirectTransmission(); mSendMessage->SetOffset(0); - if (neighbor != NULL) + if (neighbor != nullptr) { neighbor->GetLinkInfo().AddMessageTxStatus(mSendMessage->GetTxSuccess()); } @@ -869,7 +869,7 @@ void MeshForwarder::HandleSentFrame(Mac::TxFrame &aFrame, otError aError) mSendQueue.Dequeue(*mSendMessage); mSendMessage->Free(); - mSendMessage = NULL; + mSendMessage = nullptr; mMessageNextOffset = 0; } @@ -904,7 +904,7 @@ void MeshForwarder::HandleReceivedFrame(Mac::RxFrame &aFrame) linkInfo.mLqi = aFrame.GetLqi(); linkInfo.mLinkSecurity = aFrame.GetSecurityEnabled(); #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE - if (aFrame.GetTimeIe() != NULL) + if (aFrame.GetTimeIe() != nullptr) { linkInfo.mNetworkTimeOffset = aFrame.ComputeNetworkTimeOffset(); linkInfo.mTimeSyncSeq = aFrame.ReadTimeSyncSeq(); @@ -967,7 +967,7 @@ void MeshForwarder::HandleFragment(const uint8_t * aFrame, otError error = OT_ERROR_NONE; Lowpan::FragmentHeader fragmentHeader; uint16_t fragmentHeaderLength; - Message * message = NULL; + Message * message = nullptr; // Check the fragment header SuccessOrExit(error = fragmentHeader.ParseFrom(aFrame, aFrameLength, fragmentHeaderLength)); @@ -1038,12 +1038,12 @@ void MeshForwarder::HandleFragment(const uint8_t * aFrame, // message with a new tag. In either case, we can safely clear any // remaining fragments stored in the reassembly list. - if (!GetRxOnWhenIdle() && (message == NULL) && aLinkInfo.mLinkSecurity) + if (!GetRxOnWhenIdle() && (message == nullptr) && aLinkInfo.mLinkSecurity) { ClearReassemblyList(); } - VerifyOrExit(message != NULL, error = OT_ERROR_DROP); + VerifyOrExit(message != nullptr, error = OT_ERROR_DROP); message->Write(message->GetOffset(), aFrameLength, aFrame); message->MoveOffset(aFrameLength); @@ -1065,7 +1065,7 @@ exit: { LogFragmentFrameDrop(error, aFrameLength, aMacSource, aMacDest, fragmentHeader, aLinkInfo.mLinkSecurity); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -1082,7 +1082,7 @@ void MeshForwarder::ClearReassemblyList(void) next = message->GetNext(); mReassemblyList.Dequeue(*message); - LogMessage(kMessageReassemblyDrop, *message, NULL, OT_ERROR_NO_FRAME_RECEIVED); + LogMessage(kMessageReassemblyDrop, *message, nullptr, OT_ERROR_NO_FRAME_RECEIVED); if (message->GetType() == Message::kTypeIp6) { @@ -1114,7 +1114,7 @@ void MeshForwarder::HandleUpdateTimer(void) bool MeshForwarder::UpdateReassemblyList(void) { - Message *next = NULL; + Message *next = nullptr; for (Message *message = mReassemblyList.GetHead(); message; message = next) { @@ -1128,7 +1128,7 @@ bool MeshForwarder::UpdateReassemblyList(void) { mReassemblyList.Dequeue(*message); - LogMessage(kMessageReassemblyDrop, *message, NULL, OT_ERROR_REASSEMBLY_TIMEOUT); + LogMessage(kMessageReassemblyDrop, *message, nullptr, OT_ERROR_REASSEMBLY_TIMEOUT); if (message->GetType() == Message::kTypeIp6) { mIpCounters.mRxFailure++; @@ -1138,7 +1138,7 @@ bool MeshForwarder::UpdateReassemblyList(void) } } - return mReassemblyList.GetHead() != NULL; + return mReassemblyList.GetHead() != nullptr; } otError MeshForwarder::FrameToMessage(const uint8_t * aFrame, @@ -1180,7 +1180,7 @@ void MeshForwarder::HandleLowpanHC(const uint8_t * aFrame, const otThreadLinkInfo &aLinkInfo) { otError error = OT_ERROR_NONE; - Message *message = NULL; + Message *message = nullptr; #if OPENTHREAD_FTD UpdateRoutes(aFrame, aFrameLength, aMacSource, aMacDest); @@ -1213,7 +1213,7 @@ exit: { LogLowpanHcFrameDrop(error, aFrameLength, aMacSource, aMacDest, aLinkInfo.mLinkSecurity); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -1452,8 +1452,8 @@ void MeshForwarder::LogIp6Message(MessageAction aAction, otLogMac(aLogLevel, "%s IPv6 %s msg, len:%d, chksum:%04x%s%s, sec:%s%s%s, prio:%s%s%s", MessageActionToString(aAction, aError), Ip6::Ip6::IpProtoToString(ip6Header.GetNextHeader()), aMessage.GetLength(), checksum, - (aMacAddress == NULL) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"), - (aMacAddress == NULL) ? "" : aMacAddress->ToString().AsCString(), + (aMacAddress == nullptr) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"), + (aMacAddress == nullptr) ? "" : aMacAddress->ToString().AsCString(), aMessage.IsLinkSecurityEnabled() ? "yes" : "no", (aError == OT_ERROR_NONE) ? "" : ", error:", (aError == OT_ERROR_NONE) ? "" : otThreadErrorToString(aError), MessagePriorityToString(aMessage), shouldLogRss ? ", rss:" : "", shouldLogRss ? aMessage.GetRssAverager().ToString().AsCString() : ""); diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 24e3765ff..6482eb968 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -107,7 +107,7 @@ otError MeshForwarder::SendMessage(Message &aMessage) } } } - else if ((neighbor = mle.GetNeighbor(ip6Header.GetDestination())) != NULL && !neighbor->IsRxOnWhenIdle() && + else if ((neighbor = mle.GetNeighbor(ip6Header.GetDestination())) != nullptr && !neighbor->IsRxOnWhenIdle() && !aMessage.GetDirectTransmission()) { // destined for a sleepy child @@ -126,7 +126,7 @@ otError MeshForwarder::SendMessage(Message &aMessage) case Message::kTypeSupervision: { Child *child = Get().GetDestination(aMessage); - OT_ASSERT((child != NULL) && !child->IsRxOnWhenIdle()); + OT_ASSERT((child != nullptr) && !child->IsRxOnWhenIdle()); mIndirectSender.AddMessageForSleepyChild(aMessage, *child); break; } @@ -169,7 +169,7 @@ void MeshForwarder::HandleResolved(const Ip6::Address &aEid, otError aError) } else { - LogMessage(kMessageDrop, *cur, NULL, aError); + LogMessage(kMessageDrop, *cur, nullptr, aError); cur->Free(); } } @@ -185,7 +185,7 @@ otError MeshForwarder::EvictMessage(Message::Priority aPriority) { otError error = OT_ERROR_NOT_FOUND; PriorityQueue *queues[] = {&mResolvingQueue, &mSendQueue}; - Message * evict = NULL; + Message * evict = nullptr; // search for a lower priority message to evict (choose lowest priority message among all queues) for (uint8_t index = 0; index < OT_ARRAY_LENGTH(queues); index++) @@ -212,7 +212,7 @@ otError MeshForwarder::EvictMessage(Message::Priority aPriority) } } - if (evict != NULL) + if (evict != nullptr) { ExitNow(error = OT_ERROR_NONE); } @@ -305,7 +305,7 @@ void MeshForwarder::RemoveMessages(Child &aChild, Message::SubType aSubType) { if (mSendMessage == message) { - mSendMessage = NULL; + mSendMessage = nullptr; } mSendQueue.Dequeue(*message); @@ -337,11 +337,11 @@ void MeshForwarder::RemoveDataResponseMessages(void) if (mSendMessage == message) { - mSendMessage = NULL; + mSendMessage = nullptr; } mSendQueue.Dequeue(*message); - LogMessage(kMessageDrop, *message, NULL, OT_ERROR_NONE); + LogMessage(kMessageDrop, *message, nullptr, OT_ERROR_NONE); message->Free(); } } @@ -388,7 +388,7 @@ otError MeshForwarder::UpdateMeshRoute(Message &aMessage) neighbor = Get().GetNeighbor(meshHeader.GetDestination()); } - if (neighbor == NULL) + if (neighbor == nullptr) { ExitNow(error = OT_ERROR_DROP); } @@ -471,7 +471,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header, Message &aMessa ExitNow(error = OT_ERROR_DROP); } } - else if ((neighbor = mle.GetNeighbor(ip6Header.GetDestination())) != NULL) + else if ((neighbor = mle.GetNeighbor(ip6Header.GetDestination())) != nullptr) { mMeshDest = neighbor->GetRloc16(); } @@ -481,7 +481,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header, Message &aMessa } else { - IgnoreError(Get().RouteLookup(ip6Header.GetSource(), ip6Header.GetDestination(), NULL, + IgnoreError(Get().RouteLookup(ip6Header.GetSource(), ip6Header.GetDestination(), nullptr, &mMeshDest)); } @@ -528,7 +528,7 @@ void MeshForwarder::SendIcmpErrorIfDstUnreach(const Message & aMessage, VerifyOrExit(aMacSource.IsShort() && aMacDest.IsShort(), OT_NOOP); child = Get().FindChild(aMacSource.GetShort(), Child::kInStateAnyExceptInvalid); - VerifyOrExit((child == NULL) || child->IsFullThreadDevice(), OT_NOOP); + VerifyOrExit((child == nullptr) || child->IsFullThreadDevice(), OT_NOOP); aMessage.Read(0, sizeof(ip6header), &ip6header); VerifyOrExit(!ip6header.GetDestination().IsMulticast() && @@ -553,7 +553,7 @@ otError MeshForwarder::CheckReachability(const uint8_t * aFrame, { otError error = OT_ERROR_NONE; Ip6::Header ip6Header; - Message * message = NULL; + Message * message = nullptr; Lowpan::FragmentHeader fragmentHeader; uint16_t fragmentHeaderLength; uint16_t datagramSize = 0; @@ -587,7 +587,7 @@ exit: SendDestinationUnreachable(aMeshSource.GetShort(), *message); } - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -612,7 +612,7 @@ void MeshForwarder::HandleMesh(uint8_t * aFrame, const otThreadLinkInfo &aLinkInfo) { otError error = OT_ERROR_NONE; - Message * message = NULL; + Message * message = nullptr; Mac::Address meshDest; Mac::Address meshSource; Lowpan::MeshHeader meshHeader; @@ -660,7 +660,7 @@ void MeshForwarder::HandleMesh(uint8_t * aFrame, GetForwardFramePriority(aFrame, aFrameLength, meshSource, meshDest, priority); message = Get().New(Message::kType6lowpan, priority); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetLength(meshHeader.GetHeaderLength() + aFrameLength)); offset += meshHeader.WriteTo(*message, offset); @@ -681,7 +681,7 @@ exit: otLogInfoMac("Dropping rx mesh frame, error:%s, len:%d, src:%s, sec:%s", otThreadErrorToString(error), aFrameLength, aMacSource.ToString().AsCString(), aLinkInfo.mLinkSecurity ? "yes" : "no"); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -722,7 +722,7 @@ void MeshForwarder::UpdateRoutes(const uint8_t * aFrame, } neighbor = Get().GetNeighbor(ip6Header.GetSource()); - VerifyOrExit(neighbor != NULL && !neighbor->IsFullThreadDevice(), OT_NOOP); + VerifyOrExit(neighbor != nullptr && !neighbor->IsFullThreadDevice(), OT_NOOP); if (!Mle::Mle::RouterIdMatch(aMeshSource.GetShort(), Get().GetShortAddress())) { @@ -762,7 +762,7 @@ void MeshForwarder::UpdateFragmentPriority(Lowpan::FragmentHeader &aFragmentHead if (aFragmentHeader.GetDatagramOffset() == 0) { - VerifyOrExit((entry = GetUnusedFragmentPriorityEntry()) != NULL, OT_NOOP); + VerifyOrExit((entry = GetUnusedFragmentPriorityEntry()) != nullptr, OT_NOOP); entry->SetDatagramTag(aFragmentHeader.GetDatagramTag()); entry->SetSrcRloc16(aSrcRloc16); @@ -776,7 +776,7 @@ void MeshForwarder::UpdateFragmentPriority(Lowpan::FragmentHeader &aFragmentHead } else { - VerifyOrExit((entry = FindFragmentPriorityEntry(aFragmentHeader.GetDatagramTag(), aSrcRloc16)) != NULL, + VerifyOrExit((entry = FindFragmentPriorityEntry(aFragmentHeader.GetDatagramTag(), aSrcRloc16)) != nullptr, OT_NOOP); entry->SetLifetime(kReassemblyTimeout); @@ -803,7 +803,7 @@ FragmentPriorityEntry *MeshForwarder::FindFragmentPriorityEntry(uint16_t aTag, u } } - entry = NULL; + entry = nullptr; exit: return entry; @@ -821,7 +821,7 @@ FragmentPriorityEntry *MeshForwarder::GetUnusedFragmentPriorityEntry(void) } } - entry = NULL; + entry = nullptr; exit: return entry; @@ -835,7 +835,7 @@ otError MeshForwarder::GetFragmentPriority(Lowpan::FragmentHeader &aFragmentHead FragmentPriorityEntry *entry; entry = FindFragmentPriorityEntry(aFragmentHeader.GetDatagramTag(), aSrcRloc16); - VerifyOrExit(entry != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(entry != nullptr, error = OT_ERROR_NOT_FOUND); aPriority = entry->GetPriority(); exit: @@ -890,7 +890,7 @@ otError MeshForwarder::GetDestinationRlocByServiceAloc(uint16_t aServiceAloc, ui uint8_t serviceId = Mle::Mle::ServiceIdFromAloc(aServiceAloc); const NetworkData::ServiceTlv *serviceTlv = Get().FindServiceById(serviceId); - if (serviceTlv != NULL) + if (serviceTlv != nullptr) { const NetworkData::NetworkDataTlv *cur = serviceTlv->GetSubTlvs(); const NetworkData::NetworkDataTlv *end = serviceTlv->GetNext(); @@ -919,7 +919,7 @@ otError MeshForwarder::GetDestinationRlocByServiceAloc(uint16_t aServiceAloc, ui // Cost if the server is direct neighbor. neighbor = Get().GetNeighbor(server16); - if (neighbor != NULL && neighbor->IsStateValid()) + if (neighbor != nullptr && neighbor->IsStateValid()) { uint8_t cost; @@ -1014,8 +1014,8 @@ otError MeshForwarder::LogMeshFragmentHeader(MessageAction aAction, otLogMac( aLogLevel, "%s mesh frame, len:%d%s%s, msrc:%s, mdst:%s, hops:%d, frag:%s, sec:%s%s%s%s%s", MessageActionToString(aAction, aError), aMessage.GetLength(), - (aMacAddress == NULL) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"), - (aMacAddress == NULL) ? "" : aMacAddress->ToString().AsCString(), aMeshSource.ToString().AsCString(), + (aMacAddress == nullptr) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"), + (aMacAddress == nullptr) ? "" : aMacAddress->ToString().AsCString(), aMeshSource.ToString().AsCString(), aMeshDest.ToString().AsCString(), meshHeader.GetHopsLeft() + ((aAction == kMessageReceive) ? 1 : 0), hasFragmentHeader ? "yes" : "no", aMessage.IsLinkSecurityEnabled() ? "yes" : "no", (aError == OT_ERROR_NONE) ? "" : ", error:", (aError == OT_ERROR_NONE) ? "" : otThreadErrorToString(aError), diff --git a/src/core/thread/mesh_forwarder_mtd.cpp b/src/core/thread/mesh_forwarder_mtd.cpp index 40444b5ac..d637a54b2 100644 --- a/src/core/thread/mesh_forwarder_mtd.cpp +++ b/src/core/thread/mesh_forwarder_mtd.cpp @@ -54,7 +54,7 @@ otError MeshForwarder::EvictMessage(Message::Priority aPriority) otError error = OT_ERROR_NOT_FOUND; Message *message; - VerifyOrExit((message = mSendQueue.GetTail()) != NULL, OT_NOOP); + VerifyOrExit((message = mSendQueue.GetTail()) != nullptr, OT_NOOP); if (message->GetPriority() < static_cast(aPriority)) { diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 3779be7f6..b43c248fd 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -105,8 +105,8 @@ Mle::Mle(Instance &aInstance) , mAlternateChannel(0) , mAlternatePanId(Mac::kPanIdBroadcast) , mAlternateTimestamp(0) - , mParentResponseCb(NULL) - , mParentResponseCbContext(NULL) + , mParentResponseCb(nullptr) + , mParentResponseCbContext(nullptr) { MeshLocalPrefix meshLocalPrefix; @@ -1012,7 +1012,7 @@ Message *Mle::NewMleMessage(void) Message::Settings settings(Message::kNoLinkSecurity, Message::kPriorityNet); message = mSocket.NewMessage(0, settings); - VerifyOrExit(message != NULL, OT_NOOP); + VerifyOrExit(message != nullptr, OT_NOOP); message->SetSubType(Message::kSubTypeMleGeneral); @@ -1848,7 +1848,7 @@ void Mle::HandleDelayedResponseTimer(void) Message * message; Message * nextMessage; - for (message = mDelayedResponses.GetHead(); message != NULL; message = nextMessage) + for (message = mDelayedResponses.GetHead(); message != nullptr; message = nextMessage) { nextMessage = message->GetNext(); @@ -1898,7 +1898,7 @@ void Mle::RemoveDelayedDataResponseMessage(void) Message * message = mDelayedResponses.GetHead(); DelayedResponseMetadata metadata; - while (message != NULL) + while (message != nullptr) { metadata.ReadFrom(*message); @@ -1936,7 +1936,7 @@ otError Mle::SendParentRequest(ParentRequestType aType) break; } - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandParentRequest)); SuccessOrExit(error = AppendMode(*message, mDeviceMode)); SuccessOrExit(error = AppendChallenge(*message, mParentRequestChallenge)); @@ -1962,7 +1962,7 @@ otError Mle::SendParentRequest(ParentRequestType aType) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -1984,7 +1984,7 @@ otError Mle::SendChildIdRequest(void) otError error = OT_ERROR_NONE; uint8_t tlvs[] = {Tlv::kAddress16, Tlv::kNetworkData, Tlv::kRoute}; uint8_t tlvsLen = sizeof(tlvs); - Message * message = NULL; + Message * message = nullptr; Ip6::Address destination; if (mParent.GetExtAddress() == mParentCandidate.GetExtAddress()) @@ -2005,7 +2005,7 @@ otError Mle::SendChildIdRequest(void) } } - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(Message::kSubTypeMleChildIdRequest); SuccessOrExit(error = AppendHeader(*message, Header::kCommandChildIdRequest)); SuccessOrExit(error = AppendResponse(*message, mParentCandidateChallenge)); @@ -2049,7 +2049,7 @@ otError Mle::SendChildIdRequest(void) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -2065,7 +2065,7 @@ otError Mle::SendDataRequest(const Ip6::Address &aDestination, otError error = OT_ERROR_NONE; Message *message; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandDataRequest)); SuccessOrExit(error = AppendTlvRequest(*message, aTlvs, aTlvsLength)); SuccessOrExit(error = AppendActiveTimestamp(*message)); @@ -2089,7 +2089,7 @@ otError Mle::SendDataRequest(const Ip6::Address &aDestination, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -2219,7 +2219,7 @@ otError Mle::SendChildUpdateRequest(void) { otError error = OT_ERROR_NONE; Ip6::Address destination; - Message * message = NULL; + Message * message = nullptr; if (!mParent.IsStateValidOrRestoring()) { @@ -2231,7 +2231,7 @@ otError Mle::SendChildUpdateRequest(void) mChildUpdateRequestState = kChildUpdateRequestActive; ScheduleMessageTransmissionTimer(); - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(Message::kSubTypeMleChildUpdateRequest); SuccessOrExit(error = AppendHeader(*message, Header::kCommandChildUpdateRequest)); SuccessOrExit(error = AppendMode(*message, mDeviceMode)); @@ -2278,7 +2278,7 @@ otError Mle::SendChildUpdateRequest(void) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -2293,7 +2293,7 @@ otError Mle::SendChildUpdateResponse(const uint8_t *aTlvs, uint8_t aNumTlvs, con Message * message; bool checkAddress = false; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandChildUpdateResponse)); SuccessOrExit(error = AppendSourceAddress(*message)); SuccessOrExit(error = AppendLeaderData(*message)); @@ -2350,7 +2350,7 @@ otError Mle::SendChildUpdateResponse(const uint8_t *aTlvs, uint8_t aNumTlvs, con exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -2372,10 +2372,10 @@ void Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Addres otError error = OT_ERROR_NONE; ChannelTlv channel; ActiveTimestampTlv activeTimestamp; - Message * message = NULL; + Message * message = nullptr; VerifyOrExit(Get().GetSupportedChannelMask().ContainsChannel(aChannel), error = OT_ERROR_INVALID_ARGS); - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetLinkSecurityEnabled(true); message->SetSubType(Message::kSubTypeMleAnnounce); message->SetChannel(aChannel); @@ -2407,7 +2407,7 @@ void Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Addres exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -2535,7 +2535,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn otLogDebgMle("Receive UDP message"); - VerifyOrExit(aMessageInfo.GetLinkInfo() != NULL, OT_NOOP); + VerifyOrExit(aMessageInfo.GetLinkInfo() != nullptr, OT_NOOP); VerifyOrExit(aMessageInfo.GetHopLimit() == kMleHopLimit, error = OT_ERROR_PARSE); length = aMessage.Read(aMessage.GetOffset(), sizeof(header), &header); @@ -2645,11 +2645,11 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn break; default: - neighbor = NULL; + neighbor = nullptr; break; } - if (neighbor != NULL && neighbor->IsStateValid()) + if (neighbor != nullptr && neighbor->IsStateValid()) { if (keySequence == neighbor->GetKeySequence()) { @@ -2941,7 +2941,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a // if received timestamp does not match the local value and message does not contain the dataset, // send MLE Data Request - if (!IsLeader() && ((timestamp == NULL) || (timestamp->Compare(activeTimestamp) != 0)) && + if (!IsLeader() && ((timestamp == nullptr) || (timestamp->Compare(activeTimestamp) != 0)) && (Tlv::FindTlvOffset(aMessage, Tlv::kActiveDataset, activeDatasetOffset) != OT_ERROR_NONE)) { ExitNow(dataRequest = true); @@ -2962,7 +2962,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a // if received timestamp does not match the local value and message does not contain the dataset, // send MLE Data Request - if (!IsLeader() && ((timestamp == NULL) || (timestamp->Compare(pendingTimestamp) != 0)) && + if (!IsLeader() && ((timestamp == nullptr) || (timestamp->Compare(pendingTimestamp) != 0)) && (Tlv::FindTlvOffset(aMessage, Tlv::kPendingDataset, pendingDatasetOffset) != OT_ERROR_NONE)) { ExitNow(dataRequest = true); @@ -3700,7 +3700,7 @@ void Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo &aMessa localTimestamp = Get().GetTimestamp(); - if (localTimestamp == NULL || localTimestamp->Compare(timestamp) > 0) + if (localTimestamp == nullptr || localTimestamp->Compare(timestamp) > 0) { // No action is required if device is detached, and current // channel and pan-id match the values from the received MLE @@ -3771,7 +3771,7 @@ void Mle::ProcessAnnounce(void) Neighbor *Mle::GetNeighbor(uint16_t aAddress) { - Neighbor *rval = NULL; + Neighbor *rval = nullptr; if (mParent.IsStateValidOrRestoring() && (mParent.GetRloc16() == aAddress)) { @@ -3787,7 +3787,7 @@ Neighbor *Mle::GetNeighbor(uint16_t aAddress) Neighbor *Mle::GetNeighbor(const Mac::ExtAddress &aAddress) { - Neighbor *rval = NULL; + Neighbor *rval = nullptr; if (mParent.IsStateValidOrRestoring() && (mParent.GetExtAddress() == aAddress)) { @@ -3803,7 +3803,7 @@ Neighbor *Mle::GetNeighbor(const Mac::ExtAddress &aAddress) Neighbor *Mle::GetNeighbor(const Mac::Address &aAddress) { - Neighbor *neighbor = NULL; + Neighbor *neighbor = nullptr; switch (aAddress.GetType()) { @@ -3863,7 +3863,7 @@ otError Mle::CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header) void Mle::InformPreviousParent(void) { otError error = OT_ERROR_NONE; - Message * message = NULL; + Message * message = nullptr; Ip6::MessageInfo messageInfo; VerifyOrExit((mPreviousParentRloc != Mac::kShortAddrInvalid) && (mPreviousParentRloc != mParent.GetRloc16()), @@ -3871,7 +3871,7 @@ void Mle::InformPreviousParent(void) mCounters.mParentChanges++; - VerifyOrExit((message = Get().NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage(0)) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetLength(0)); messageInfo.SetSockAddr(GetMeshLocal64()); @@ -3888,7 +3888,7 @@ exit: { otLogWarnMle("Failed to inform previous parent: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 850498a9b..5557fc684 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1016,7 +1016,7 @@ protected: /** * This method allocates a new message buffer for preparing an MLE message. * - * @returns A pointer to the message or NULL if insufficient message buffers are available. + * @returns A pointer to the message or nullptr if insufficient message buffers are available. * */ Message *NewMleMessage(void); @@ -1412,7 +1412,7 @@ protected: Neighbor *GetNeighbor(const Ip6::Address &aAddress) { OT_UNUSED_VARIABLE(aAddress); - return NULL; + return nullptr; } /** diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 2f43bd31d..ff1ddef44 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -58,13 +58,13 @@ namespace Mle { MleRouter::MleRouter(Instance &aInstance) : Mle(aInstance) - , mAdvertiseTimer(aInstance, MleRouter::HandleAdvertiseTimer, NULL, this) + , mAdvertiseTimer(aInstance, MleRouter::HandleAdvertiseTimer, nullptr, this) , mStateUpdateTimer(aInstance, MleRouter::HandleStateUpdateTimer, this) , mAddressSolicit(OT_URI_PATH_ADDRESS_SOLICIT, &MleRouter::HandleAddressSolicit, this) , mAddressRelease(OT_URI_PATH_ADDRESS_RELEASE, &MleRouter::HandleAddressRelease, this) , mChildTable(aInstance) , mRouterTable(aInstance) - , mNeighborTableChangedCallback(NULL) + , mNeighborTableChangedCallback(nullptr) , mChallengeTimeout(0) , mNextChildId(kMaxChildId) , mNetworkIdTimeout(kNetworkIdTimeout) @@ -162,7 +162,7 @@ otError MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) switch (mRole) { case kRoleDetached: - SuccessOrExit(error = SendLinkRequest(NULL)); + SuccessOrExit(error = SendLinkRequest(nullptr)); mStateUpdateTimer.Start(kStateUpdatePeriod); break; @@ -201,7 +201,7 @@ otError MleRouter::BecomeLeader(void) SetLeaderData(partitionId, mLeaderWeight, leaderId); router = mRouterTable.Allocate(leaderId); - OT_ASSERT(router != NULL); + OT_ASSERT(router != nullptr); SetRouterId(leaderId); router->SetExtAddress(Get().GetExtAddress()); @@ -423,7 +423,7 @@ void MleRouter::SendAdvertisement(void) { otError error = OT_ERROR_NONE; Ip6::Address destination; - Message * message = NULL; + Message * message = nullptr; // Suppress MLE Advertisements when trying to attach to a better partition. // @@ -438,7 +438,7 @@ void MleRouter::SendAdvertisement(void) // children to detach. VerifyOrExit(!mAddressSolicitPending, OT_NOOP); - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandAdvertisement)); SuccessOrExit(error = AppendSourceAddress(*message)); SuccessOrExit(error = AppendLeaderData(*message)); @@ -470,7 +470,7 @@ exit: { otLogWarnMle("Failed to send Advertisement: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -488,7 +488,7 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor) destination.Clear(); - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandLinkRequest)); SuccessOrExit(error = AppendVersion(*message)); @@ -509,7 +509,7 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor) case kRoleRouter: case kRoleLeader: - if (aNeighbor == NULL || !aNeighbor->IsStateValid()) + if (aNeighbor == nullptr || !aNeighbor->IsStateValid()) { SuccessOrExit(error = AppendTlvRequest(*message, routerTlvs, sizeof(routerTlvs))); } @@ -527,7 +527,7 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor) SuccessOrExit(error = AppendTimeRequest(*message)); #endif - if (aNeighbor == NULL) + if (aNeighbor == nullptr) { mChallenge.GenerateRandom(); mChallengeTimeout = (((2 * kMaxResponseDelay) + kStateUpdatePeriod - 1) / kStateUpdatePeriod); @@ -559,7 +559,7 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -570,7 +570,7 @@ exit: void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, Neighbor *aNeighbor) { otError error = OT_ERROR_NONE; - Neighbor * neighbor = NULL; + Neighbor * neighbor = nullptr; Challenge challenge; uint16_t version; LeaderData leaderData; @@ -616,7 +616,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); neighbor = mRouterTable.GetRouter(RouterIdFromRloc16(sourceAddress)); - VerifyOrExit(neighbor != NULL, error = OT_ERROR_PARSE); + VerifyOrExit(neighbor != nullptr, error = OT_ERROR_PARSE); VerifyOrExit(!neighbor->IsStateLinkRequest(), error = OT_ERROR_ALREADY); if (!neighbor->IsStateValid()) @@ -662,7 +662,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf } #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE - if (neighbor != NULL) + if (neighbor != nullptr) { if (Tlv::FindTlv(aMessage, Tlv::kTimeRequest, sizeof(timeRequest), timeRequest) == OT_ERROR_NONE) { @@ -697,10 +697,10 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, Header::Command command; uint8_t linkMargin; - command = (aNeighbor == NULL || aNeighbor->IsStateValid()) ? Header::kCommandLinkAccept - : Header::kCommandLinkAcceptAndRequest; + command = (aNeighbor == nullptr || aNeighbor->IsStateValid()) ? Header::kCommandLinkAccept + : Header::kCommandLinkAcceptAndRequest; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, command)); SuccessOrExit(error = AppendVersion(*message)); SuccessOrExit(error = AppendSourceAddress(*message)); @@ -713,7 +713,7 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, SuccessOrExit(error = AppendLinkMargin(*message, linkMargin)); - if (aNeighbor != NULL && IsActiveRouter(aNeighbor->GetRloc16())) + if (aNeighbor != nullptr && IsActiveRouter(aNeighbor->GetRloc16())) { SuccessOrExit(error = AppendLeaderData(*message)); } @@ -727,7 +727,7 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, break; case Tlv::kAddress16: - VerifyOrExit(aNeighbor != NULL, error = OT_ERROR_DROP); + VerifyOrExit(aNeighbor != nullptr, error = OT_ERROR_DROP); SuccessOrExit(error = AppendAddress16(*message, aNeighbor->GetRloc16())); break; @@ -739,7 +739,7 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, } } - if (aNeighbor != NULL && !aNeighbor->IsStateValid()) + if (aNeighbor != nullptr && !aNeighbor->IsStateValid()) { aNeighbor->GenerateChallenge(); @@ -750,7 +750,7 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, } #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE - if (aNeighbor != NULL && aNeighbor->IsTimeSyncEnabled()) + if (aNeighbor != nullptr && aNeighbor->IsTimeSyncEnabled()) { message->SetTimeSync(true); } @@ -772,7 +772,7 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -846,7 +846,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, routerId = RouterIdFromRloc16(sourceAddress); router = mRouterTable.GetRouter(routerId); - neighborState = (router != NULL) ? router->GetState() : Neighbor::kStateInvalid; + neighborState = (router != nullptr) ? router->GetState() : Neighbor::kStateInvalid; // Response SuccessOrExit(error = ReadResponse(aMessage, response)); @@ -929,7 +929,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, mRouterTable.Clear(); SuccessOrExit(error = ProcessRouteTlv(route)); router = mRouterTable.GetRouter(routerId); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); if (mLeaderData.GetLeaderRouterId() == RouterIdFromRloc16(GetRloc16())) { @@ -949,12 +949,12 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, break; case kRoleChild: - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); break; case kRoleRouter: case kRoleLeader: - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); // Leader Data SuccessOrExit(error = ReadLeaderData(aMessage, leaderData)); @@ -1061,8 +1061,8 @@ uint8_t MleRouter::GetLinkCost(uint8_t aRouterId) router = mRouterTable.GetRouter(aRouterId); - // NULL aRouterId indicates non-existing next hop, hence return kMaxRouteCost for it. - VerifyOrExit(router != NULL, OT_NOOP); + // nullptr aRouterId indicates non-existing next hop, hence return kMaxRouteCost for it. + VerifyOrExit(router != nullptr, OT_NOOP); rval = mRouterTable.GetLinkCost(*router); @@ -1273,7 +1273,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, { router = mRouterTable.GetRouter(routerId); - if (router != NULL && router->IsStateValid()) + if (router != nullptr && router->IsStateValid()) { processRouteTlv = true; } @@ -1292,7 +1292,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, SuccessOrExit(error = ProcessRouteTlv(route)); if (Get().Contains(*aNeighbor)) { - aNeighbor = NULL; // aNeighbor is no longer valid after `ProcessRouteTlv` + aNeighbor = nullptr; // aNeighbor is no longer valid after `ProcessRouteTlv` } } } @@ -1328,7 +1328,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, leader = mRouterTable.GetLeader(); - if (leader != NULL) + if (leader != nullptr) { for (uint8_t id = 0, routeCount = 0; id <= kMaxRouterId; id++) { @@ -1363,7 +1363,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, { // MLE Advertisement not from parent, but from some other neighboring router router = mRouterTable.GetRouter(routerId); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); if (IsFullThreadDevice() && !router->IsStateValid() && !router->IsStateLinkRequest() && (mRouterTable.GetActiveLinkCount() < OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS)) @@ -1385,7 +1385,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, case kRoleRouter: router = mRouterTable.GetRouter(routerId); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); // check current active router number routerCount = 0; @@ -1409,7 +1409,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, case kRoleLeader: router = mRouterTable.GetRouter(routerId); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); // Send unicast link request if no link to router and no unicast/multicast link request in progress if (!router->IsStateValid() && !router->IsStateLinkRequest() && (mChallengeTimeout == 0) && @@ -1448,7 +1448,7 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) bool changed = false; neighbor = mRouterTable.GetRouter(aRouterId); - VerifyOrExit(neighbor != NULL, OT_NOOP); + VerifyOrExit(neighbor != nullptr, OT_NOOP); // update link quality out to neighbor changed = UpdateLinkQualityOut(aRoute, *neighbor, resetAdvInterval); @@ -1468,7 +1468,7 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) router = mRouterTable.GetRouter(routerId); - if (router == NULL || router->GetRloc16() == GetRloc16() || router == neighbor) + if (router == nullptr || router->GetRloc16() == GetRloc16() || router == neighbor) { routeCount++; continue; @@ -1484,13 +1484,13 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) cost = kMaxRouteCost; } - if (nextHop == NULL || nextHop == neighbor) + if (nextHop == nullptr || nextHop == neighbor) { // route has no next hop or next hop is neighbor (sender) if (cost + mRouterTable.GetLinkCost(*neighbor) < kMaxRouteCost) { - if (nextHop == NULL && mRouterTable.GetLinkCost(*router) >= kMaxRouteCost) + if (nextHop == nullptr && mRouterTable.GetLinkCost(*router) >= kMaxRouteCost) { resetAdvInterval = true; } @@ -1584,7 +1584,7 @@ bool MleRouter::UpdateLinkQualityOut(const RouteTlv &aRoute, Router &aNeighbor, nextHop = mRouterTable.GetRouter(aNeighbor.GetNextHop()); // reset MLE advertisement timer if neighbor route cost changed to or from infinite - if (nextHop == NULL && (oldLinkCost >= kMaxRouteCost) != (mRouterTable.GetLinkCost(aNeighbor) >= kMaxRouteCost)) + if (nextHop == nullptr && (oldLinkCost >= kMaxRouteCost) != (mRouterTable.GetLinkCost(aNeighbor) >= kMaxRouteCost)) { aResetAdvInterval = true; } @@ -1628,7 +1628,7 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI // 3. Its current routing path cost to the Leader is infinite. leader = mRouterTable.GetLeader(); - OT_ASSERT(leader != NULL); + OT_ASSERT(leader != nullptr); VerifyOrExit(IsLeader() || GetLinkCost(GetLeaderId()) < kMaxRouteCost || (IsChild() && leader->GetCost() + 1 < kMaxRouteCost) || @@ -1665,9 +1665,9 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid); - if (child == NULL) + if (child == nullptr) { - VerifyOrExit((child = mChildTable.GetNewChild()) != NULL, OT_NOOP); + VerifyOrExit((child = mChildTable.GetNewChild()) != nullptr, OT_NOOP); // MAC Address child->SetExtAddress(macAddr); @@ -1917,7 +1917,7 @@ void MleRouter::HandleStateUpdateTimer(void) if (IsLeader()) { - if (mRouterTable.GetRouter(router.GetNextHop()) == NULL && + if (mRouterTable.GetRouter(router.GetNextHop()) == nullptr && mRouterTable.GetLinkCost(router) >= kMaxRouteCost && age >= Time::SecToMsec(kMaxLeaderToRouterTimeout)) { otLogInfoMle("Router ID timeout expired (no route)"); @@ -1948,7 +1948,7 @@ void MleRouter::SendParentResponse(Child *aChild, const Challenge &aChallenge, b Message * message; uint16_t delay; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetDirectTransmission(); SuccessOrExit(error = AppendHeader(*message, Header::kCommandParentResponse)); @@ -1990,7 +1990,7 @@ void MleRouter::SendParentResponse(Child *aChild, const Challenge &aChallenge, b exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -2179,7 +2179,7 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage, aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid); - VerifyOrExit(child != NULL, error = OT_ERROR_ALREADY); + VerifyOrExit(child != nullptr, error = OT_ERROR_ALREADY); // Version SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version)); @@ -2245,7 +2245,7 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage, // Remove from router table router = mRouterTable.GetRouter(macAddr); - if (router != NULL) + if (router != nullptr) { // The `router` here can be invalid RemoveNeighbor(*router); @@ -2369,13 +2369,13 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage, // Not proceed if the Child Update Request is from the peer which is not the device's child or // which was the device's child but becomes invalid. - if (child == NULL || child->IsStateInvalid()) + if (child == nullptr || child->IsStateInvalid()) { // For invalid non-sleepy child, Send Child Update Response with status TLV (error) if (mode.IsRxOnWhenIdle()) { tlvs[tlvslength++] = Tlv::kStatus; - SendChildUpdateResponse(NULL, aMessageInfo, tlvs, tlvslength, challenge); + SendChildUpdateResponse(nullptr, aMessageInfo, tlvs, tlvslength, challenge); } ExitNow(); @@ -2509,7 +2509,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage, Child * child; uint16_t addressRegistrationOffset = 0; - if ((aNeighbor == NULL) || IsActiveRouter(aNeighbor->GetRloc16())) + if ((aNeighbor == nullptr) || IsActiveRouter(aNeighbor->GetRloc16())) { LogMleMessage("Receive Child Update Response from unknown child", aMessageInfo.GetPeerAddr()); ExitNow(error = OT_ERROR_NOT_FOUND); @@ -2760,7 +2760,7 @@ void MleRouter::SetSteeringData(const Mac::ExtAddress *aExtAddress) nullExtAddr.Clear(); allowAnyExtAddr.Fill(0xff); - if ((aExtAddress == NULL) || (*aExtAddress == nullExtAddr)) + if ((aExtAddress == nullptr) || (*aExtAddress == nullExtAddr)) { mSteeringData.Clear(); } @@ -2860,7 +2860,7 @@ otError MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, uint1 MeshCoP::NetworkNameTlv networkName; uint16_t delay; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(Message::kSubTypeMleDiscoverResponse); message->SetPanId(aPanId); SuccessOrExit(error = AppendHeader(*message, Header::kCommandDiscoveryResponse)); @@ -2913,7 +2913,7 @@ otError MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, uint1 steeringData = Get().GetCommissioningDataSubTlv(MeshCoP::Tlv::kSteeringData); - if (steeringData != NULL) + if (steeringData != nullptr) { SuccessOrExit(error = steeringData->AppendTo(*message)); } @@ -2938,7 +2938,7 @@ exit: { otLogWarnMle("Failed to process Discovery Response: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -2953,7 +2953,7 @@ otError MleRouter::SendChildIdResponse(Child &aChild) Ip6::Address destination; Message * message; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandChildIdResponse)); SuccessOrExit(error = AppendSourceAddress(*message)); SuccessOrExit(error = AppendLeaderData(*message)); @@ -2976,7 +2976,7 @@ otError MleRouter::SendChildIdResponse(Child &aChild) rloc16 = Get().GetShortAddress() | mNextChildId; - } while (mChildTable.FindChild(rloc16, Child::kInStateAnyExceptInvalid) != NULL); + } while (mChildTable.FindChild(rloc16, Child::kInStateAnyExceptInvalid) != nullptr); // allocate Child ID aChild.SetRloc16(rloc16); @@ -3035,7 +3035,7 @@ otError MleRouter::SendChildIdResponse(Child &aChild) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -3072,7 +3072,7 @@ otError MleRouter::SendChildUpdateRequest(Child &aChild) } } - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(Message::kSubTypeMleChildUpdateRequest); SuccessOrExit(error = AppendHeader(*message, Header::kCommandChildUpdateRequest)); SuccessOrExit(error = AppendSourceAddress(*message)); @@ -3101,7 +3101,7 @@ otError MleRouter::SendChildUpdateRequest(Child &aChild) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -3118,7 +3118,7 @@ void MleRouter::SendChildUpdateResponse(Child * aChild, otError error = OT_ERROR_NONE; Message *message; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandChildUpdateResponse)); for (int i = 0; i < aTlvsLength; i++) @@ -3171,7 +3171,7 @@ void MleRouter::SendChildUpdateResponse(Child * aChild, SuccessOrExit(error = SendMessage(*message, aMessageInfo.GetPeerAddr())); - if (aChild == NULL) + if (aChild == nullptr) { LogMleMessage("Send Child Update Response to child", aMessageInfo.GetPeerAddr()); } @@ -3182,7 +3182,7 @@ void MleRouter::SendChildUpdateResponse(Child * aChild, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -3194,7 +3194,7 @@ void MleRouter::SendDataResponse(const Ip6::Address &aDestination, uint16_t aDelay) { otError error = OT_ERROR_NONE; - Message * message = NULL; + Message * message = nullptr; Neighbor *neighbor; bool stableOnly; @@ -3204,7 +3204,7 @@ void MleRouter::SendDataResponse(const Ip6::Address &aDestination, ExitNow(); } - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); message->SetSubType(Message::kSubTypeMleDataResponse); SuccessOrExit(error = AppendHeader(*message, Header::kCommandDataResponse)); SuccessOrExit(error = AppendSourceAddress(*message)); @@ -3218,7 +3218,7 @@ void MleRouter::SendDataResponse(const Ip6::Address &aDestination, { case Tlv::kNetworkData: neighbor = GetNeighbor(aDestination); - stableOnly = neighbor != NULL ? !neighbor->IsFullNetworkData() : false; + stableOnly = neighbor != nullptr ? !neighbor->IsFullNetworkData() : false; SuccessOrExit(error = AppendNetworkData(*message, stableOnly)); break; @@ -3255,7 +3255,7 @@ exit: { otLogWarnMle("Failed to send Data Response: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -3272,7 +3272,7 @@ bool MleRouter::IsMinimalChild(uint16_t aRloc16) neighbor = GetNeighbor(aRloc16); - rval = (neighbor != NULL) && (!neighbor->IsFullThreadDevice()); + rval = (neighbor != nullptr) && (!neighbor->IsFullThreadDevice()); } return rval; @@ -3352,7 +3352,7 @@ exit: Neighbor *MleRouter::GetNeighbor(uint16_t aAddress) { - Neighbor *rval = NULL; + Neighbor *rval = nullptr; if (aAddress == Mac::kShortAddrBroadcast || aAddress == Mac::kShortAddrInvalid) { @@ -3372,7 +3372,7 @@ Neighbor *MleRouter::GetNeighbor(uint16_t aAddress) case kRoleRouter: case kRoleLeader: rval = mChildTable.FindChild(aAddress, Child::kInStateValidOrRestoring); - VerifyOrExit(rval == NULL, OT_NOOP); + VerifyOrExit(rval == nullptr, OT_NOOP); rval = mRouterTable.GetNeighbor(aAddress); break; @@ -3384,7 +3384,7 @@ exit: Neighbor *MleRouter::GetNeighbor(const Mac::ExtAddress &aAddress) { - Neighbor *rval = NULL; + Neighbor *rval = nullptr; switch (mRole) { @@ -3399,11 +3399,11 @@ Neighbor *MleRouter::GetNeighbor(const Mac::ExtAddress &aAddress) case kRoleRouter: case kRoleLeader: rval = mChildTable.FindChild(aAddress, Child::kInStateValidOrRestoring); - VerifyOrExit(rval == NULL, OT_NOOP); + VerifyOrExit(rval == nullptr, OT_NOOP); rval = mRouterTable.GetNeighbor(aAddress); - if (rval != NULL) + if (rval != nullptr) { ExitNow(); } @@ -3422,7 +3422,7 @@ exit: Neighbor *MleRouter::GetNeighbor(const Mac::Address &aAddress) { - Neighbor *rval = NULL; + Neighbor *rval = nullptr; switch (aAddress.GetType()) { @@ -3446,7 +3446,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress) Mac::Address macAddr; Lowpan::Context context; Child * child; - Neighbor * rval = NULL; + Neighbor * rval = nullptr; if (aAddress.IsLinkLocal()) { @@ -3476,7 +3476,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress) } } - VerifyOrExit(context.mContextId == kMeshLocalPrefixContextId, rval = NULL); + VerifyOrExit(context.mContextId == kMeshLocalPrefixContextId, rval = nullptr); if (aAddress.IsIidLocator()) { @@ -3489,9 +3489,9 @@ exit: Neighbor *MleRouter::GetRxOnlyNeighborRouter(const Mac::Address &aAddress) { - Neighbor *rval = NULL; + Neighbor *rval = nullptr; - VerifyOrExit(IsChild(), rval = NULL); + VerifyOrExit(IsChild(), rval = nullptr); switch (aAddress.GetType()) { @@ -3532,7 +3532,7 @@ uint16_t MleRouter::GetNextHop(uint16_t aDestination) } router = mRouterTable.GetRouter(destinationId); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); linkCost = GetLinkCost(destinationId); routeCost = GetRouteCost(aDestination); @@ -3540,7 +3540,7 @@ uint16_t MleRouter::GetNextHop(uint16_t aDestination) if ((routeCost + GetLinkCost(router->GetNextHop())) < linkCost) { nextHop = mRouterTable.GetRouter(router->GetNextHop()); - VerifyOrExit(nextHop != NULL && !nextHop->IsStateInvalid(), OT_NOOP); + VerifyOrExit(nextHop != nullptr && !nextHop->IsStateInvalid(), OT_NOOP); rval = Rloc16FromRouterId(router->GetNextHop()); } @@ -3560,7 +3560,7 @@ uint8_t MleRouter::GetCost(uint16_t aRloc16) Router *router = mRouterTable.GetRouter(routerId); uint8_t routeCost; - VerifyOrExit(router != NULL && mRouterTable.GetRouter(router->GetNextHop()) != NULL, OT_NOOP); + VerifyOrExit(router != nullptr && mRouterTable.GetRouter(router->GetNextHop()) != nullptr, OT_NOOP); routeCost = GetRouteCost(aRloc16) + GetLinkCost(router->GetNextHop()); @@ -3579,7 +3579,7 @@ uint8_t MleRouter::GetRouteCost(uint16_t aRloc16) const const Router *router; router = mRouterTable.GetRouter(RouterIdFromRloc16(aRloc16)); - VerifyOrExit(router != NULL && mRouterTable.GetRouter(router->GetNextHop()) != NULL, OT_NOOP); + VerifyOrExit(router != nullptr && mRouterTable.GetRouter(router->GetNextHop()) != nullptr, OT_NOOP); rval = router->GetCost(); @@ -3618,7 +3618,7 @@ otError MleRouter::GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo) rloc16 = Get().GetShortAddress() | aChildId; child = mChildTable.FindChild(rloc16, Child::kInStateAnyExceptInvalid); - VerifyOrExit(child != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(child != nullptr, error = OT_ERROR_NOT_FOUND); error = GetChildInfo(*child, aChildInfo); @@ -3629,10 +3629,10 @@ exit: otError MleRouter::GetChildInfoByIndex(uint16_t aChildIndex, otChildInfo &aChildInfo) { otError error = OT_ERROR_NONE; - Child * child = NULL; + Child * child = nullptr; child = mChildTable.GetChildAtIndex(aChildIndex); - VerifyOrExit(child != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(child != nullptr, error = OT_ERROR_NOT_FOUND); error = GetChildInfo(*child, aChildInfo); @@ -3645,10 +3645,10 @@ otError MleRouter::GetChildNextIp6Address(uint16_t aChildIndex Ip6::Address & aAddress) { otError error = OT_ERROR_NONE; - Child * child = NULL; + Child * child = nullptr; child = mChildTable.GetChildAtIndex(aChildIndex); - VerifyOrExit(child != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(child != nullptr, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(child->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_ARGS); error = child->GetNextIp6Address(aIterator, aAddress); @@ -3670,9 +3670,9 @@ void MleRouter::RestoreChildren(void) child = mChildTable.FindChild(childInfo.GetExtAddress(), Child::kInStateAnyExceptInvalid); - if (child == NULL) + if (child == nullptr) { - VerifyOrExit((child = mChildTable.GetNewChild()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((child = mChildTable.GetNewChild()) != nullptr, error = OT_ERROR_NO_BUFS); } else { @@ -3802,7 +3802,7 @@ void MleRouter::GetNeighborInfo(Neighbor &aNeighbor, otNeighborInfo &aNeighInfo) otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeighborInfo &aNeighInfo) { otError error = OT_ERROR_NONE; - Neighbor *neighbor = NULL; + Neighbor *neighbor = nullptr; int16_t index; memset(&aNeighInfo, 0, sizeof(aNeighInfo)); @@ -3815,7 +3815,7 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig { Child *child = mChildTable.GetChildAtIndex(static_cast(index)); - if (child == NULL) + if (child == nullptr) { break; } @@ -3839,7 +3839,7 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig { Router *router = mRouterTable.GetRouter(static_cast(index)); - if (router != NULL && router->IsStateValid()) + if (router != nullptr && router->IsStateValid()) { neighbor = router; aNeighInfo.mIsChild = false; @@ -3854,7 +3854,7 @@ otError MleRouter::GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeig exit: - if (neighbor != NULL) + if (neighbor != nullptr) { GetNeighborInfo(*neighbor, aNeighInfo); } @@ -3873,7 +3873,7 @@ void MleRouter::ResolveRoutingLoops(uint16_t aSourceMac, uint16_t aDestRloc16) // loop exists router = mRouterTable.GetRouter(RouterIdFromRloc16(aDestRloc16)); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); // invalidate next hop router->SetNextHop(kInvalidRouterId); @@ -3901,7 +3901,7 @@ otError MleRouter::CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header // IPv6 destination is this device ExitNow(); } - else if (GetNeighbor(aIp6Header.GetDestination()) != NULL) + else if (GetNeighbor(aIp6Header.GetDestination()) != nullptr) { // IPv6 destination is an RFD child ExitNow(); @@ -3931,11 +3931,11 @@ otError MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus) { otError error = OT_ERROR_NONE; Ip6::MessageInfo messageInfo; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; VerifyOrExit(!mAddressSolicitPending, OT_NOOP); - VerifyOrExit((message = Get().NewPriorityMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_ADDRESS_SOLICIT)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -3967,7 +3967,7 @@ otError MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -3981,7 +3981,7 @@ void MleRouter::SendAddressRelease(void) Ip6::MessageInfo messageInfo; Coap::Message * message; - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_ADDRESS_RELEASE)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -4004,7 +4004,7 @@ exit: { otLogWarnMle("Failed to send Address Release: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } @@ -4035,7 +4035,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage, mAddressSolicitPending = false; - VerifyOrExit(aResult == OT_ERROR_NONE && aMessage != NULL && aMessage != NULL, OT_NOOP); + VerifyOrExit(aResult == OT_ERROR_NONE && aMessage != nullptr && aMessage != nullptr, OT_NOOP); VerifyOrExit(aMessage->GetCode() == OT_COAP_CODE_CHANGED, OT_NOOP); @@ -4074,13 +4074,13 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage, mRouterTable.UpdateRouterIdSet(routerMaskTlv.GetIdSequence(), routerMaskTlv.GetAssignedRouterIdMask()); router = mRouterTable.GetRouter(routerId); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); router->SetExtAddress(Get().GetExtAddress()); router->SetCost(0); router = mRouterTable.GetRouter(mParent.GetRouterId()); - VerifyOrExit(router != NULL, OT_NOOP); + VerifyOrExit(router != nullptr, OT_NOOP); // Keep link to the parent in order to respond to Parent Requests before new link is established. *router = mParent; @@ -4089,7 +4089,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage, router->SetCost(0); leader = mRouterTable.GetLeader(); - OT_ASSERT(leader != NULL); + OT_ASSERT(leader != nullptr); if (leader != router) { @@ -4099,7 +4099,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage, } // send link request - IgnoreError(SendLinkRequest(NULL)); + IgnoreError(SendLinkRequest(nullptr)); // send child id responses for (ChildTable::Iterator iter(GetInstance(), Child::kInStateChildIdRequest); !iter.IsDone(); iter++) @@ -4131,7 +4131,7 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message Mac::ExtAddress extAddress; uint16_t rloc16; uint8_t status; - Router * router = NULL; + Router * router = nullptr; #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE uint16_t xtalAccuracy; #endif @@ -4153,7 +4153,7 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message // see if allocation already exists router = mRouterTable.GetRouter(extAddress); - if (router != NULL) + if (router != nullptr) { ExitNow(); } @@ -4186,7 +4186,7 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message } // allocate new router id - if (router == NULL) + if (router == nullptr) { router = mRouterTable.Allocate(); } @@ -4195,7 +4195,7 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message otLogInfoMle("router id requested and provided!"); } - if (router != NULL) + if (router != nullptr) { router->SetExtAddress(extAddress); } @@ -4220,16 +4220,16 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Message & aRequest, ThreadRouterMaskTlv routerMaskTlv; Coap::Message * message; - VerifyOrExit((message = Get().NewPriorityMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); SuccessOrExit(error = Tlv::AppendUint8Tlv(*message, ThreadTlv::kStatus, - aRouter == NULL ? ThreadStatusTlv::kNoAddressAvailable - : ThreadStatusTlv::kSuccess)); + aRouter == nullptr ? ThreadStatusTlv::kNoAddressAvailable + : ThreadStatusTlv::kSuccess)); - if (aRouter != NULL) + if (aRouter != nullptr) { SuccessOrExit(error = Tlv::AppendUint16Tlv(*message, ThreadTlv::kRloc16, aRouter->GetRloc16())); @@ -4246,7 +4246,7 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Message & aRequest, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -4276,7 +4276,7 @@ void MleRouter::HandleAddressRelease(Coap::Message &aMessage, const Ip6::Message routerId = RouterIdFromRloc16(rloc16); router = mRouterTable.GetRouter(routerId); - VerifyOrExit((router != NULL) && (router->GetExtAddress() == extAddress), OT_NOOP); + VerifyOrExit((router != nullptr) && (router->GetExtAddress() == extAddress), OT_NOOP); IgnoreError(mRouterTable.Release(routerId)); @@ -4321,7 +4321,7 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv) aTlv.SetLinkQuality3(0); leader = mRouterTable.GetLeader(); - cost = (leader != NULL) ? leader->GetCost() : static_cast(kMaxRouteCost); + cost = (leader != nullptr) ? leader->GetCost() : static_cast(kMaxRouteCost); switch (mRole) { @@ -4350,7 +4350,7 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv) break; case kRoleRouter: - if (leader != NULL) + if (leader != nullptr) { cost += GetLinkCost(leader->GetNextHop()); @@ -4495,7 +4495,7 @@ void MleRouter::FillRouteTlv(RouteTlv &aTlv) linkCost = mRouterTable.GetLinkCost(router); nextHop = mRouterTable.GetRouter(router.GetNextHop()); - if (nextHop == NULL) + if (nextHop == nullptr) { routeCost = linkCost; } @@ -4726,7 +4726,7 @@ exit: void MleRouter::Signal(otNeighborTableEvent aEvent, Neighbor &aNeighbor) { - if (mNeighborTableChangedCallback != NULL) + if (mNeighborTableChangedCallback != nullptr) { otNeighborTableEntryInfo info; otError error; @@ -4816,9 +4816,9 @@ otError MleRouter::SendTimeSync(void) { otError error = OT_ERROR_NONE; Ip6::Address destination; - Message * message = NULL; + Message * message = nullptr; - VerifyOrExit((message = NewMleMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = NewMleMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = AppendHeader(*message, Header::kCommandTimeSync)); message->SetTimeSync(true); @@ -4830,7 +4830,7 @@ otError MleRouter::SendTimeSync(void) exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } diff --git a/src/core/thread/mle_router.hpp b/src/core/thread/mle_router.hpp index 90b9fca98..12379f386 100644 --- a/src/core/thread/mle_router.hpp +++ b/src/core/thread/mle_router.hpp @@ -377,7 +377,7 @@ public: * * @param[in] aAddress The address of the Neighbor. * - * @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise. + * @returns A pointer to the Neighbor corresponding to @p aAddress, nullptr otherwise. * */ Neighbor *GetNeighbor(uint16_t aAddress); @@ -387,7 +387,7 @@ public: * * @param[in] aAddress The address of the Neighbor. * - * @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise. + * @returns A pointer to the Neighbor corresponding to @p aAddress, nullptr otherwise. * */ Neighbor *GetNeighbor(const Mac::ExtAddress &aAddress); @@ -397,7 +397,7 @@ public: * * @param[in] aAddress The address of the Neighbor. * - * @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise. + * @returns A pointer to the Neighbor corresponding to @p aAddress, nullptr otherwise. * */ Neighbor *GetNeighbor(const Mac::Address &aAddress); @@ -407,7 +407,7 @@ public: * * @param[in] aAddress The address of the Neighbor. * - * @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise. + * @returns A pointer to the Neighbor corresponding to @p aAddress, nullptr otherwise. * */ Neighbor *GetNeighbor(const Ip6::Address &aAddress); @@ -418,7 +418,7 @@ public: * * @param[in] aAddress The address of the Neighbor. * - * @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise. + * @returns A pointer to the Neighbor corresponding to @p aAddress, nullptr otherwise. * */ Neighbor *GetRxOnlyNeighborRouter(const Mac::Address &aAddress); @@ -605,8 +605,8 @@ public: /** * This method register the "neighbor table changed" callback function. * - * The provided callback (if non-NULL) will be invoked when a child/router entry is being added/remove to/from the - * neighbor table. Subsequent calls to this method will overwrite the previous callback. + * The provided callback (if non-nullptr) will be invoked when a child/router entry is being added/remove to/from + * the neighbor table. Subsequent calls to this method will overwrite the previous callback. * * @param[in] aCallback A pointer to callback handler function. * diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index fed7d06c2..2cbc95dbd 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -67,7 +67,7 @@ const NetworkDataTlv *NetworkData::FindTlv(const NetworkDataTlv *aStart, for (tlv = aStart; tlv < aEnd; tlv = tlv->GetNext()) { - VerifyOrExit((tlv + 1) <= aEnd && tlv->GetNext() <= aEnd, tlv = NULL); + VerifyOrExit((tlv + 1) <= aEnd && tlv->GetNext() <= aEnd, tlv = nullptr); if (tlv->GetType() == aType) { @@ -75,7 +75,7 @@ const NetworkDataTlv *NetworkData::FindTlv(const NetworkDataTlv *aStart, } } - tlv = NULL; + tlv = nullptr; exit: return tlv; @@ -90,7 +90,7 @@ const NetworkDataTlv *NetworkData::FindTlv(const NetworkDataTlv *aStart, for (tlv = aStart; tlv < aEnd; tlv = tlv->GetNext()) { - VerifyOrExit((tlv + 1) <= aEnd && tlv->GetNext() <= aEnd, tlv = NULL); + VerifyOrExit((tlv + 1) <= aEnd && tlv->GetNext() <= aEnd, tlv = nullptr); if ((tlv->GetType() == aType) && (tlv->IsStable() == aStable)) { @@ -98,7 +98,7 @@ const NetworkDataTlv *NetworkData::FindTlv(const NetworkDataTlv *aStart, } } - tlv = NULL; + tlv = nullptr; exit: return tlv; @@ -108,7 +108,7 @@ otError NetworkData::GetNetworkData(bool aStable, uint8_t *aData, uint8_t &aData { otError error = OT_ERROR_NONE; - OT_ASSERT(aData != NULL); + OT_ASSERT(aData != nullptr); VerifyOrExit(aDataLength >= mLength, error = OT_ERROR_NO_BUFS); memcpy(aData, mTlvs, mLength); @@ -133,8 +133,8 @@ otError NetworkData::GetNextOnMeshPrefix(Iterator &aIterator, uint16_t aRloc16, Config config; config.mOnMeshPrefix = &aConfig; - config.mExternalRoute = NULL; - config.mService = NULL; + config.mExternalRoute = nullptr; + config.mService = nullptr; return Iterate(aIterator, aRloc16, config); } @@ -148,9 +148,9 @@ otError NetworkData::GetNextExternalRoute(Iterator &aIterator, uint16_t aRloc16, { Config config; - config.mOnMeshPrefix = NULL; + config.mOnMeshPrefix = nullptr; config.mExternalRoute = &aConfig; - config.mService = NULL; + config.mService = nullptr; return Iterate(aIterator, aRloc16, config); } @@ -164,8 +164,8 @@ otError NetworkData::GetNextService(Iterator &aIterator, uint16_t aRloc16, Servi { Config config; - config.mOnMeshPrefix = NULL; - config.mExternalRoute = NULL; + config.mOnMeshPrefix = nullptr; + config.mExternalRoute = nullptr; config.mService = &aConfig; return Iterate(aIterator, aRloc16, config); @@ -176,11 +176,11 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon // Iterate to the next entry in Network Data matching `aRloc16` // (can be set to `Mac::kShortAddrBroadcast` to allow any RLOC). // The `aIterator` is used to track and save the current position. - // On input, the non-NULL pointer members in `aConfig` specify the + // On input, the non-nullptr pointer members in `aConfig` specify the // Network Data entry types (`mOnMeshPrefix`, `mExternalRoute`, // `mService`) to iterate over. On successful exit, the `aConfig` - // is updated such that only one member pointer is not NULL - // indicating the type of entry and the non-NULL config is updated + // is updated such that only one member pointer is not nullptr + // indicating the type of entry and the non-nullptr config is updated // with the entry info. otError error = OT_ERROR_NOT_FOUND; @@ -188,18 +188,18 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon for (const NetworkDataTlv *cur; (cur = iterator.GetTlv(mTlvs)) < GetTlvsEnd(); iterator.AdvanceTlv(mTlvs)) { - const NetworkDataTlv *subTlvs = NULL; + const NetworkDataTlv *subTlvs = nullptr; switch (cur->GetType()) { case NetworkDataTlv::kTypePrefix: - if ((aConfig.mOnMeshPrefix != NULL) || (aConfig.mExternalRoute != NULL)) + if ((aConfig.mOnMeshPrefix != nullptr) || (aConfig.mExternalRoute != nullptr)) { subTlvs = static_cast(cur)->GetSubTlvs(); } break; case NetworkDataTlv::kTypeService: - if (aConfig.mService != NULL) + if (aConfig.mService != nullptr) { subTlvs = static_cast(cur)->GetSubTlvs(); } @@ -208,7 +208,7 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon break; } - if (subTlvs == NULL) + if (subTlvs == nullptr) { continue; } @@ -226,7 +226,7 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon { const BorderRouterTlv *borderRouter = static_cast(subCur); - if (aConfig.mOnMeshPrefix == NULL) + if (aConfig.mOnMeshPrefix == nullptr) { continue; } @@ -237,8 +237,8 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon { const BorderRouterEntry *borderRouterEntry = borderRouter->GetEntry(index); - aConfig.mExternalRoute = NULL; - aConfig.mService = NULL; + aConfig.mExternalRoute = nullptr; + aConfig.mService = nullptr; memset(aConfig.mOnMeshPrefix, 0, sizeof(OnMeshPrefixConfig)); memcpy(&aConfig.mOnMeshPrefix->mPrefix.mPrefix, prefix->GetPrefix(), @@ -267,7 +267,7 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon { const HasRouteTlv *hasRoute = static_cast(subCur); - if (aConfig.mExternalRoute == NULL) + if (aConfig.mExternalRoute == nullptr) { continue; } @@ -278,8 +278,8 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon { const HasRouteEntry *hasRouteEntry = hasRoute->GetEntry(index); - aConfig.mOnMeshPrefix = NULL; - aConfig.mService = NULL; + aConfig.mOnMeshPrefix = nullptr; + aConfig.mService = nullptr; memset(aConfig.mExternalRoute, 0, sizeof(ExternalRouteConfig)); memcpy(&aConfig.mExternalRoute->mPrefix.mPrefix, prefix->GetPrefix(), @@ -317,8 +317,8 @@ otError NetworkData::Iterate(Iterator &aIterator, uint16_t aRloc16, Config &aCon if ((aRloc16 == Mac::kShortAddrBroadcast) || (server->GetServer16() == aRloc16)) { - aConfig.mOnMeshPrefix = NULL; - aConfig.mExternalRoute = NULL; + aConfig.mOnMeshPrefix = nullptr; + aConfig.mExternalRoute = nullptr; memset(aConfig.mService, 0, sizeof(ServiceConfig)); aConfig.mService->mServiceId = service->GetServiceId(); @@ -548,7 +548,7 @@ void NetworkData::RemoveTemporaryData(uint8_t *aData, uint8_t &aDataLength, Pref for (BorderRouterEntry *entry = borderRouter->GetFirstEntry(); entry <= borderRouter->GetLastEntry(); entry = entry->GetNext()) { - if ((entry->IsDhcp() || entry->IsConfigure()) && (context != NULL)) + if ((entry->IsDhcp() || entry->IsConfigure()) && (context != nullptr)) { entry->SetRloc(0xfc00 | context->GetContextId()); } @@ -669,7 +669,7 @@ const PrefixTlv *NetworkData::FindPrefix(const uint8_t *aPrefix, { prefixTlv = FindTlv(start, end); - VerifyOrExit(prefixTlv != NULL, OT_NOOP); + VerifyOrExit(prefixTlv != nullptr, OT_NOOP); if (prefixTlv->GetPrefixLength() == aPrefixLength && PrefixMatch(prefixTlv->GetPrefix(), aPrefix, aPrefixLength) >= aPrefixLength) @@ -680,7 +680,7 @@ const PrefixTlv *NetworkData::FindPrefix(const uint8_t *aPrefix, start = prefixTlv->GetNext(); } - prefixTlv = NULL; + prefixTlv = nullptr; exit: return prefixTlv; @@ -719,7 +719,7 @@ const ServiceTlv *NetworkData::FindService(uint32_t aEnterpriseNumber, { serviceTlv = FindTlv(start, end); - VerifyOrExit(serviceTlv != NULL, OT_NOOP); + VerifyOrExit(serviceTlv != nullptr, OT_NOOP); if ((serviceTlv->GetEnterpriseNumber() == aEnterpriseNumber) && (serviceTlv->GetServiceDataLength() == aServiceDataLength) && @@ -731,7 +731,7 @@ const ServiceTlv *NetworkData::FindService(uint32_t aEnterpriseNumber, start = serviceTlv->GetNext(); } - serviceTlv = NULL; + serviceTlv = nullptr; exit: return serviceTlv; @@ -741,7 +741,7 @@ NetworkDataTlv *NetworkData::AppendTlv(uint16_t aTlvSize) { NetworkDataTlv *tlv; - VerifyOrExit(CanInsert(aTlvSize), tlv = NULL); + VerifyOrExit(CanInsert(aTlvSize), tlv = nullptr); tlv = GetTlvsEnd(); mLength += static_cast(aTlvSize); @@ -788,10 +788,10 @@ void NetworkData::RemoveTlv(NetworkDataTlv *aTlv) otError NetworkData::SendServerDataNotification(uint16_t aRloc16, Coap::ResponseHandler aHandler, void *aContext) { otError error = OT_ERROR_NONE; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_SERVER_DATA)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -819,7 +819,7 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16, Coap::Response exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -841,15 +841,15 @@ otError NetworkData::GetNextServer(Iterator &aIterator, uint16_t &aRloc16) const SuccessOrExit(error = Iterate(aIterator, Mac::kShortAddrBroadcast, config)); - if (config.mOnMeshPrefix != NULL) + if (config.mOnMeshPrefix != nullptr) { aRloc16 = config.mOnMeshPrefix->mRloc16; } - else if (config.mExternalRoute != NULL) + else if (config.mExternalRoute != nullptr) { aRloc16 = config.mExternalRoute->mRloc16; } - else if (config.mService != NULL) + else if (config.mService != nullptr) { aRloc16 = config.mService->mServerConfig.mRloc16; } diff --git a/src/core/thread/network_data.hpp b/src/core/thread/network_data.hpp index 3b688f2c0..179c23bd4 100644 --- a/src/core/thread/network_data.hpp +++ b/src/core/thread/network_data.hpp @@ -354,7 +354,7 @@ protected: * * @param[in] aPrefix A reference to the Prefix TLV. * - * @returns A pointer to the Border Router TLV if one is found or NULL if no Border Router TLV exists. + * @returns A pointer to the Border Router TLV if one is found or nullptr if no Border Router TLV exists. * */ static BorderRouterTlv *FindBorderRouter(PrefixTlv &aPrefix) @@ -367,7 +367,7 @@ protected: * * @param[in] aPrefix A reference to the Prefix TLV. * - * @returns A pointer to the Border Router TLV if one is found or NULL if no Border Router TLV exists. + * @returns A pointer to the Border Router TLV if one is found or nullptr if no Border Router TLV exists. * */ static const BorderRouterTlv *FindBorderRouter(const PrefixTlv &aPrefix); @@ -378,7 +378,7 @@ protected: * @param[in] aPrefix A reference to the Prefix TLV. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable.. * - * @returns A pointer to the Border Router TLV if one is found or NULL if no Border Router TLV exists. + * @returns A pointer to the Border Router TLV if one is found or nullptr if no Border Router TLV exists. * */ static BorderRouterTlv *FindBorderRouter(PrefixTlv &aPrefix, bool aStable) @@ -392,7 +392,7 @@ protected: * @param[in] aPrefix A reference to the Prefix TLV. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable.. * - * @returns A pointer to the Border Router TLV if one is found or NULL if no Border Router TLV exists. + * @returns A pointer to the Border Router TLV if one is found or nullptr if no Border Router TLV exists. * */ static const BorderRouterTlv *FindBorderRouter(const PrefixTlv &aPrefix, bool aStable); @@ -402,7 +402,7 @@ protected: * * @param[in] aPrefix A reference to the Prefix TLV. * - * @returns A pointer to the Has Route TLV if one is found or NULL if no Has Route TLV exists. + * @returns A pointer to the Has Route TLV if one is found or nullptr if no Has Route TLV exists. * */ static HasRouteTlv *FindHasRoute(PrefixTlv &aPrefix) @@ -415,7 +415,7 @@ protected: * * @param[in] aPrefix A reference to the Prefix TLV. * - * @returns A pointer to the Has Route TLV if one is found or NULL if no Has Route TLV exists. + * @returns A pointer to the Has Route TLV if one is found or nullptr if no Has Route TLV exists. * */ static const HasRouteTlv *FindHasRoute(const PrefixTlv &aPrefix); @@ -426,7 +426,7 @@ protected: * @param[in] aPrefix A reference to the Prefix TLV. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable. * - * @returns A pointer to the Has Route TLV if one is found or NULL if no Has Route TLV exists. + * @returns A pointer to the Has Route TLV if one is found or nullptr if no Has Route TLV exists. * */ static HasRouteTlv *FindHasRoute(PrefixTlv &aPrefix, bool aStable) @@ -440,7 +440,7 @@ protected: * @param[in] aPrefix A reference to the Prefix TLV. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable. * - * @returns A pointer to the Has Route TLV if one is found or NULL if no Has Route TLV exists. + * @returns A pointer to the Has Route TLV if one is found or nullptr if no Has Route TLV exists. * */ static const HasRouteTlv *FindHasRoute(const PrefixTlv &aPrefix, bool aStable); @@ -450,7 +450,7 @@ protected: * * @param[in] aPrefix A reference to the Prefix TLV. * - * @returns A pointer to the Context TLV is one is found or NULL if no Context TLV exists. + * @returns A pointer to the Context TLV is one is found or nullptr if no Context TLV exists. * */ static ContextTlv *FindContext(PrefixTlv &aPrefix) @@ -463,7 +463,7 @@ protected: * * @param[in] aPrefix A reference to the Prefix TLV. * - * @returns A pointer to the Context TLV is one is found or NULL if no Context TLV exists. + * @returns A pointer to the Context TLV is one is found or nullptr if no Context TLV exists. * */ static const ContextTlv *FindContext(const PrefixTlv &aPrefix); @@ -474,7 +474,7 @@ protected: * @param[in] aPrefix A pointer to an IPv6 prefix. * @param[in] aPrefixLength The prefix length pointed to by @p aPrefix. * - * @returns A pointer to the Prefix TLV is one is found or NULL if no matching Prefix TLV exists. + * @returns A pointer to the Prefix TLV is one is found or nullptr if no matching Prefix TLV exists. * */ PrefixTlv *FindPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength) @@ -488,7 +488,7 @@ protected: * @param[in] aPrefix A pointer to an IPv6 prefix. * @param[in] aPrefixLength The prefix length pointed to by @p aPrefix. * - * @returns A pointer to the Prefix TLV is one is found or NULL if no matching Prefix TLV exists. + * @returns A pointer to the Prefix TLV is one is found or nullptr if no matching Prefix TLV exists. * */ const PrefixTlv *FindPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength) const; @@ -501,7 +501,7 @@ protected: * @param[in] aTlvs A pointer to a specified tlvs buffer. * @param[in] aTlvsLength The specified tlvs buffer length pointed to by @p aTlvs. * - * @returns A pointer to the Prefix TLV is one is found or NULL if no matching Prefix TLV exists. + * @returns A pointer to the Prefix TLV is one is found or nullptr if no matching Prefix TLV exists. * */ static PrefixTlv *FindPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, uint8_t *aTlvs, uint8_t aTlvsLength) @@ -518,7 +518,7 @@ protected: * @param[in] aTlvs A pointer to a specified tlvs buffer. * @param[in] aTlvsLength The specified tlvs buffer length pointed to by @p aTlvs. * - * @returns A pointer to the Prefix TLV is one is found or NULL if no matching Prefix TLV exists. + * @returns A pointer to the Prefix TLV is one is found or nullptr if no matching Prefix TLV exists. * */ static const PrefixTlv *FindPrefix(const uint8_t *aPrefix, @@ -533,7 +533,7 @@ protected: * @param[in] aServiceData A pointer to a Service Data. * @param[in] aServiceDataLength The Service Data length pointed to by @p aServiceData. * - * @returns A pointer to the Service TLV is one is found or NULL if no matching Service TLV exists. + * @returns A pointer to the Service TLV is one is found or nullptr if no matching Service TLV exists. * */ ServiceTlv *FindService(uint32_t aEnterpriseNumber, const uint8_t *aServiceData, uint8_t aServiceDataLength) @@ -549,7 +549,7 @@ protected: * @param[in] aServiceData A pointer to a Service Data. * @param[in] aServiceDataLength The Service Data length pointed to by @p aServiceData. * - * @returns A pointer to the Service TLV is one is found or NULL if no matching Service TLV exists. + * @returns A pointer to the Service TLV is one is found or nullptr if no matching Service TLV exists. * */ const ServiceTlv *FindService(uint32_t aEnterpriseNumber, @@ -565,7 +565,7 @@ protected: * @param[in] aTlvs A pointer to a specified tlvs buffer. * @param[in] aTlvsLength The specified tlvs buffer length pointed to by @p aTlvs. * - * @returns A pointer to the Service TLV is one is found or NULL if no matching Service TLV exists. + * @returns A pointer to the Service TLV is one is found or nullptr if no matching Service TLV exists. * */ static ServiceTlv *FindService(uint32_t aEnterpriseNumber, @@ -587,7 +587,7 @@ protected: * @param[in] aTlvs A pointer to a specified tlvs buffer. * @param[in] aTlvsLength The specified tlvs buffer length pointed to by @p aTlvs. * - * @returns A pointer to the Service TLV is one is found or NULL if no matching Service TLV exists. + * @returns A pointer to the Service TLV is one is found or nullptr if no matching Service TLV exists. * */ static const ServiceTlv *FindService(uint32_t aEnterpriseNumber, @@ -616,7 +616,7 @@ protected: * * @param[in] aTlvSize The size of TLV (total number of bytes including Type, Length, and Value fields) * - * @returns A pointer to the TLV if there is space to grow Network Data, or NULL if no space to grow the Network + * @returns A pointer to the TLV if there is space to grow Network Data, or nullptr if no space to grow the Network * Data with requested @p aTlvSize number of bytes. * */ @@ -690,7 +690,7 @@ protected: * @param[in] aEnd A pointer to the end of the sequence of TLVs. * @param[in] aType The TLV type to find. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ static NetworkDataTlv *FindTlv(NetworkDataTlv *aStart, NetworkDataTlv *aEnd, NetworkDataTlv::Type aType) @@ -706,7 +706,7 @@ protected: * @param[in] aEnd A pointer to the end of the sequence of TLVs. * @param[in] aType The TLV type to find. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ static const NetworkDataTlv *FindTlv(const NetworkDataTlv *aStart, @@ -720,7 +720,7 @@ protected: * @param[in] aStart A pointer to the start of the sequence of TLVs to search within. * @param[in] aEnd A pointer to the end of the sequence of TLVs. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ template static TlvType *FindTlv(NetworkDataTlv *aStart, NetworkDataTlv *aEnd) @@ -735,7 +735,7 @@ protected: * @param[in] aStart A pointer to the start of the sequence of TLVs to search within. * @param[in] aEnd A pointer to the end of the sequence of TLVs. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ template static const TlvType *FindTlv(const NetworkDataTlv *aStart, const NetworkDataTlv *aEnd) @@ -752,7 +752,7 @@ protected: * @param[in] aType The TLV type to find. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ static NetworkDataTlv *FindTlv(NetworkDataTlv * aStart, @@ -773,7 +773,7 @@ protected: * @param[in] aType The TLV type to find. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ static const NetworkDataTlv *FindTlv(const NetworkDataTlv *aStart, @@ -789,7 +789,7 @@ protected: * @param [in] aEnd A pointer to the end of the sequence of TLVs. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ template static TlvType *FindTlv(NetworkDataTlv *aStart, NetworkDataTlv *aEnd, bool aStable) @@ -806,7 +806,7 @@ protected: * @param [in] aEnd A pointer to the end of the sequence of TLVs. * @param[in] aStable TRUE to find a stable TLV, FALSE to find a TLV not marked as stable. * - * @returns A pointer to the TLV if found, or NULL if not found. + * @returns A pointer to the TLV if found, or nullptr if not found. * */ template diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 683578ee0..5a0e60635 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -98,22 +98,22 @@ otError LeaderBase::GetBackboneRouterPrimary(BackboneRouter::BackboneRouterConfi { otError error = OT_ERROR_NOT_FOUND; uint8_t serviceData = ServiceTlv::kServiceDataBackboneRouter; - const ServerTlv * rvalServerTlv = NULL; - const BackboneRouterServerData *rvalServerData = NULL; + const ServerTlv * rvalServerTlv = nullptr; + const BackboneRouterServerData *rvalServerData = nullptr; const ServiceTlv * serviceTlv; const ServerTlv * serverTlv; serviceTlv = Get().FindService(ServiceTlv::kThreadEnterpriseNumber, &serviceData, sizeof(serviceData)); - VerifyOrExit(serviceTlv != NULL, aConfig.mServer16 = Mac::kShortAddrInvalid); + VerifyOrExit(serviceTlv != nullptr, aConfig.mServer16 = Mac::kShortAddrInvalid); - for (const NetworkDataTlv *start = serviceTlv->GetSubTlvs(); - (serverTlv = FindTlv(start, serviceTlv->GetNext())) != NULL; start = serverTlv->GetNext()) + for (const NetworkDataTlv *start = serviceTlv->GetSubTlvs(); + (serverTlv = FindTlv(start, serviceTlv->GetNext())) != nullptr; start = serverTlv->GetNext()) { const BackboneRouterServerData *serverData = reinterpret_cast(serverTlv->GetServerData()); - if (rvalServerTlv == NULL || + if (rvalServerTlv == nullptr || (serverTlv->GetServer16() == Mle::Mle::Rloc16FromRouterId(Get().GetLeaderId())) || serverData->GetSequenceNumber() > rvalServerData->GetSequenceNumber() || (serverData->GetSequenceNumber() == rvalServerData->GetSequenceNumber() && @@ -124,7 +124,7 @@ otError LeaderBase::GetBackboneRouterPrimary(BackboneRouter::BackboneRouterConfi } } - VerifyOrExit(rvalServerTlv != NULL, OT_NOOP); + VerifyOrExit(rvalServerTlv != nullptr, OT_NOOP); aConfig.mServer16 = rvalServerTlv->GetServer16(); aConfig.mSequenceNumber = rvalServerData->GetSequenceNumber(); @@ -142,8 +142,8 @@ const PrefixTlv *LeaderBase::FindNextMatchingPrefix(const Ip6::Address &aAddress { const PrefixTlv *prefix; - for (const NetworkDataTlv *start = (aPrevTlv == NULL) ? GetTlvsStart() : aPrevTlv->GetNext(); - (prefix = FindTlv(start, GetTlvsEnd())) != NULL; start = prefix->GetNext()) + for (const NetworkDataTlv *start = (aPrevTlv == nullptr) ? GetTlvsStart() : aPrevTlv->GetNext(); + (prefix = FindTlv(start, GetTlvsEnd())) != nullptr; start = prefix->GetNext()) { if (PrefixMatch(prefix->GetPrefix(), aAddress.mFields.m8, prefix->GetPrefixLength()) >= 0) { @@ -157,7 +157,7 @@ exit: otError LeaderBase::GetContext(const Ip6::Address &aAddress, Lowpan::Context &aContext) const { - const PrefixTlv * prefix = NULL; + const PrefixTlv * prefix = nullptr; const ContextTlv *contextTlv; aContext.mPrefixLength = 0; @@ -170,11 +170,11 @@ otError LeaderBase::GetContext(const Ip6::Address &aAddress, Lowpan::Context &aC aContext.mCompressFlag = true; } - while ((prefix = FindNextMatchingPrefix(aAddress, prefix)) != NULL) + while ((prefix = FindNextMatchingPrefix(aAddress, prefix)) != nullptr) { contextTlv = FindContext(*prefix); - if (contextTlv == NULL) + if (contextTlv == nullptr) { continue; } @@ -205,12 +205,12 @@ otError LeaderBase::GetContext(uint8_t aContextId, Lowpan::Context &aContext) co ExitNow(error = OT_ERROR_NONE); } - for (const NetworkDataTlv *start = GetTlvsStart(); (prefix = FindTlv(start, GetTlvsEnd())) != NULL; + for (const NetworkDataTlv *start = GetTlvsStart(); (prefix = FindTlv(start, GetTlvsEnd())) != nullptr; start = prefix->GetNext()) { const ContextTlv *contextTlv = FindContext(*prefix); - if ((contextTlv == NULL) || (contextTlv->GetContextId() != aContextId)) + if ((contextTlv == nullptr) || (contextTlv->GetContextId() != aContextId)) { continue; } @@ -253,14 +253,14 @@ exit: bool LeaderBase::IsOnMesh(const Ip6::Address &aAddress) const { - const PrefixTlv *prefix = NULL; + const PrefixTlv *prefix = nullptr; bool rval = false; VerifyOrExit(!Get().IsMeshLocalAddress(aAddress), rval = true); - while ((prefix = FindNextMatchingPrefix(aAddress, prefix)) != NULL) + while ((prefix = FindNextMatchingPrefix(aAddress, prefix)) != nullptr) { - if (FindBorderRouter(*prefix) == NULL) + if (FindBorderRouter(*prefix) == nullptr) { continue; } @@ -278,9 +278,9 @@ otError LeaderBase::RouteLookup(const Ip6::Address &aSource, uint16_t * aRloc16) const { otError error = OT_ERROR_NO_ROUTE; - const PrefixTlv *prefix = NULL; + const PrefixTlv *prefix = nullptr; - while ((prefix = FindNextMatchingPrefix(aSource, prefix)) != NULL) + while ((prefix = FindNextMatchingPrefix(aSource, prefix)) != nullptr) { if (ExternalRouteLookup(prefix->GetDomainId(), aDestination, aPrefixMatch, aRloc16) == OT_ERROR_NONE) { @@ -309,10 +309,10 @@ otError LeaderBase::ExternalRouteLookup(uint8_t aDomainId, { otError error = OT_ERROR_NO_ROUTE; const PrefixTlv * prefix; - const HasRouteEntry *rvalRoute = NULL; + const HasRouteEntry *rvalRoute = nullptr; uint8_t rval_plen = 0; - for (const NetworkDataTlv *start = GetTlvsStart(); (prefix = FindTlv(start, GetTlvsEnd())) != NULL; + for (const NetworkDataTlv *start = GetTlvsStart(); (prefix = FindTlv(start, GetTlvsEnd())) != nullptr; start = prefix->GetNext()) { const HasRouteTlv *hasRoute; @@ -330,13 +330,13 @@ otError LeaderBase::ExternalRouteLookup(uint8_t aDomainId, continue; } - for (const NetworkDataTlv *subStart = prefix->GetSubTlvs(); - (hasRoute = FindTlv(subStart, prefix->GetNext())) != NULL; subStart = hasRoute->GetNext()) + for (const NetworkDataTlv *subStart = prefix->GetSubTlvs(); + (hasRoute = FindTlv(subStart, prefix->GetNext())) != nullptr; subStart = hasRoute->GetNext()) { for (const HasRouteEntry *entry = hasRoute->GetFirstEntry(); entry <= hasRoute->GetLastEntry(); entry = entry->GetNext()) { - if (rvalRoute == NULL || entry->GetPreference() > rvalRoute->GetPreference() || + if (rvalRoute == nullptr || entry->GetPreference() > rvalRoute->GetPreference() || (entry->GetPreference() == rvalRoute->GetPreference() && (entry->GetRloc() == Get().GetRloc16() || (rvalRoute->GetRloc() != Get().GetRloc16() && @@ -350,14 +350,14 @@ otError LeaderBase::ExternalRouteLookup(uint8_t aDomainId, } } - if (rvalRoute != NULL) + if (rvalRoute != nullptr) { - if (aRloc16 != NULL) + if (aRloc16 != nullptr) { *aRloc16 = rvalRoute->GetRloc(); } - if (aPrefixMatch != NULL) + if (aPrefixMatch != nullptr) { *aPrefixMatch = rval_plen; } @@ -372,10 +372,11 @@ otError LeaderBase::DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t *aRloc { otError error = OT_ERROR_NO_ROUTE; const BorderRouterTlv * borderRouter; - const BorderRouterEntry *route = NULL; + const BorderRouterEntry *route = nullptr; - for (const NetworkDataTlv *start = aPrefix.GetSubTlvs(); - (borderRouter = FindTlv(start, aPrefix.GetNext())) != NULL; start = borderRouter->GetNext()) + for (const NetworkDataTlv *start = aPrefix.GetSubTlvs(); + (borderRouter = FindTlv(start, aPrefix.GetNext())) != nullptr; + start = borderRouter->GetNext()) { for (const BorderRouterEntry *entry = borderRouter->GetFirstEntry(); entry <= borderRouter->GetLastEntry(); entry = entry->GetNext()) @@ -385,7 +386,7 @@ otError LeaderBase::DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t *aRloc continue; } - if (route == NULL || entry->GetPreference() > route->GetPreference() || + if (route == nullptr || entry->GetPreference() > route->GetPreference() || (entry->GetPreference() == route->GetPreference() && (entry->GetRloc() == Get().GetRloc16() || (route->GetRloc() != Get().GetRloc16() && @@ -396,9 +397,9 @@ otError LeaderBase::DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t *aRloc } } - if (route != NULL) + if (route != nullptr) { - if (aRloc16 != NULL) + if (aRloc16 != nullptr) { *aRloc16 = route->GetRloc(); } @@ -462,7 +463,7 @@ otError LeaderBase::SetCommissioningData(const uint8_t *aValue, uint8_t aValueLe VerifyOrExit(aValueLength <= kMaxSize - sizeof(CommissioningDataTlv), error = OT_ERROR_NO_BUFS); commissioningDataTlv = static_cast(AppendTlv(sizeof(CommissioningDataTlv) + aValueLength)); - VerifyOrExit(commissioningDataTlv != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(commissioningDataTlv != nullptr, error = OT_ERROR_NO_BUFS); commissioningDataTlv->Init(); commissioningDataTlv->SetLength(aValueLength); @@ -483,11 +484,11 @@ const CommissioningDataTlv *LeaderBase::GetCommissioningData(void) const const MeshCoP::Tlv *LeaderBase::GetCommissioningDataSubTlv(MeshCoP::Tlv::Type aType) const { - const MeshCoP::Tlv * rval = NULL; + const MeshCoP::Tlv * rval = nullptr; const NetworkDataTlv *commissioningDataTlv; commissioningDataTlv = GetCommissioningData(); - VerifyOrExit(commissioningDataTlv != NULL, OT_NOOP); + VerifyOrExit(commissioningDataTlv != nullptr, OT_NOOP); rval = MeshCoP::Tlv::FindTlv(commissioningDataTlv->GetValue(), commissioningDataTlv->GetLength(), aType); @@ -500,10 +501,10 @@ bool LeaderBase::IsJoiningEnabled(void) const const MeshCoP::Tlv *steeringData; bool rval = false; - VerifyOrExit(GetCommissioningDataSubTlv(MeshCoP::Tlv::kBorderAgentLocator) != NULL, OT_NOOP); + VerifyOrExit(GetCommissioningDataSubTlv(MeshCoP::Tlv::kBorderAgentLocator) != nullptr, OT_NOOP); steeringData = GetCommissioningDataSubTlv(MeshCoP::Tlv::kSteeringData); - VerifyOrExit(steeringData != NULL, OT_NOOP); + VerifyOrExit(steeringData != nullptr, OT_NOOP); for (int i = 0; i < steeringData->GetLength(); i++) { @@ -521,7 +522,7 @@ void LeaderBase::RemoveCommissioningData(void) { CommissioningDataTlv *tlv = GetCommissioningData(); - VerifyOrExit(tlv != NULL, OT_NOOP); + VerifyOrExit(tlv != nullptr, OT_NOOP); RemoveTlv(tlv); exit: diff --git a/src/core/thread/network_data_leader.hpp b/src/core/thread/network_data_leader.hpp index 153738b8b..7c122485d 100644 --- a/src/core/thread/network_data_leader.hpp +++ b/src/core/thread/network_data_leader.hpp @@ -184,7 +184,7 @@ public: /** * This method returns a pointer to the Commissioning Data. * - * @returns A pointer to the Commissioning Data or NULL if no Commissioning Data exists. + * @returns A pointer to the Commissioning Data or nullptr if no Commissioning Data exists. * */ CommissioningDataTlv *GetCommissioningData(void) @@ -195,7 +195,7 @@ public: /** * This method returns a pointer to the Commissioning Data. * - * @returns A pointer to the Commissioning Data or NULL if no Commissioning Data exists. + * @returns A pointer to the Commissioning Data or nullptr if no Commissioning Data exists. * */ const CommissioningDataTlv *GetCommissioningData(void) const; @@ -205,7 +205,7 @@ public: * * @param[in] aType The TLV type value. * - * @returns A pointer to the Commissioning Data Sub-TLV or NULL if no Sub-TLV exists. + * @returns A pointer to the Commissioning Data Sub-TLV or nullptr if no Sub-TLV exists. * */ MeshCoP::Tlv *GetCommissioningDataSubTlv(MeshCoP::Tlv::Type aType) @@ -218,7 +218,7 @@ public: * * @param[in] aType The TLV type value. * - * @returns A pointer to the Commissioning Data Sub-TLV or NULL if no Sub-TLV exists. + * @returns A pointer to the Commissioning Data Sub-TLV or nullptr if no Sub-TLV exists. * */ const MeshCoP::Tlv *GetCommissioningDataSubTlv(MeshCoP::Tlv::Type aType) const; diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index ccd7e4f83..364814a6b 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -242,7 +242,7 @@ void Leader::HandleCommissioningSet(Coap::Message &aMessage, const Ip6::MessageI // Find Commissioning Data TLV commDataTlv = GetCommissioningData(); - if (commDataTlv != NULL) + if (commDataTlv != nullptr) { // Iterate over MeshCoP TLVs and extract desired data for (cur = reinterpret_cast(commDataTlv->GetValue()); @@ -301,17 +301,17 @@ void Leader::SendCommissioningGetResponse(const Coap::Message & aRequest, otError error = OT_ERROR_NONE; Coap::Message * message; CommissioningDataTlv *commDataTlv; - uint8_t * data = NULL; + uint8_t * data = nullptr; uint8_t length = 0; - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); commDataTlv = GetCommissioningData(); - if (commDataTlv != NULL) + if (commDataTlv != nullptr) { data = commDataTlv->GetValue(); length = commDataTlv->GetLength(); @@ -355,7 +355,7 @@ void Leader::SendCommissioningGetResponse(const Coap::Message & aRequest, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -368,7 +368,7 @@ void Leader::SendCommissioningSetResponse(const Coap::Message & aRequest, otError error = OT_ERROR_NONE; Coap::Message *message; - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -381,7 +381,7 @@ void Leader::SendCommissioningSetResponse(const Coap::Message & aRequest, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -431,7 +431,7 @@ otError Leader::Validate(const uint8_t *aTlvs, uint8_t aTlvsLength, uint16_t aRl VerifyOrExit(prefix->IsValid(), error = OT_ERROR_PARSE); // Ensure there is no duplicate Prefix TLVs with same prefix. - VerifyOrExit(FindPrefix(prefix->GetPrefix(), prefix->GetPrefixLength(), aTlvs, offset) == NULL, + VerifyOrExit(FindPrefix(prefix->GetPrefix(), prefix->GetPrefixLength(), aTlvs, offset) == nullptr, error = OT_ERROR_PARSE); SuccessOrExit(error = ValidatePrefix(*prefix, aRloc16)); @@ -447,7 +447,7 @@ otError Leader::Validate(const uint8_t *aTlvs, uint8_t aTlvsLength, uint16_t aRl // Ensure there is no duplicate Service TLV with same // Enterprise Number and Service Data. VerifyOrExit(FindService(service->GetEnterpriseNumber(), service->GetServiceData(), - service->GetServiceDataLength(), aTlvs, offset) == NULL, + service->GetServiceDataLength(), aTlvs, offset) == nullptr, error = OT_ERROR_PARSE); SuccessOrExit(error = ValidateService(*service, aRloc16)); @@ -589,7 +589,7 @@ bool Leader::ContainsMatchingEntry(const PrefixTlv *aPrefix, bool aStable, const // Check whether `aPrefix` has a Has Route sub-TLV with stable // flag `aStable` containing a matching entry to `aEntry`. - return (aPrefix == NULL) ? false : ContainsMatchingEntry(FindHasRoute(*aPrefix, aStable), aEntry); + return (aPrefix == nullptr) ? false : ContainsMatchingEntry(FindHasRoute(*aPrefix, aStable), aEntry); } bool Leader::ContainsMatchingEntry(const HasRouteTlv *aHasRoute, const HasRouteEntry &aEntry) @@ -598,7 +598,7 @@ bool Leader::ContainsMatchingEntry(const HasRouteTlv *aHasRoute, const HasRouteE bool contains = false; - VerifyOrExit(aHasRoute != NULL, OT_NOOP); + VerifyOrExit(aHasRoute != nullptr, OT_NOOP); for (const HasRouteEntry *entry = aHasRoute->GetFirstEntry(); entry <= aHasRoute->GetLastEntry(); entry++) { @@ -618,7 +618,7 @@ bool Leader::ContainsMatchingEntry(const PrefixTlv *aPrefix, bool aStable, const // Check whether `aPrefix` has a Border Router sub-TLV with stable // flag `aStable` containing a matching entry to `aEntry`. - return (aPrefix == NULL) ? false : ContainsMatchingEntry(FindBorderRouter(*aPrefix, aStable), aEntry); + return (aPrefix == nullptr) ? false : ContainsMatchingEntry(FindBorderRouter(*aPrefix, aStable), aEntry); } bool Leader::ContainsMatchingEntry(const BorderRouterTlv *aBorderRouter, const BorderRouterEntry &aEntry) @@ -627,7 +627,7 @@ bool Leader::ContainsMatchingEntry(const BorderRouterTlv *aBorderRouter, const B bool contains = false; - VerifyOrExit(aBorderRouter != NULL, OT_NOOP); + VerifyOrExit(aBorderRouter != nullptr, OT_NOOP); for (const BorderRouterEntry *entry = aBorderRouter->GetFirstEntry(); entry <= aBorderRouter->GetLastEntry(); entry++) @@ -651,10 +651,10 @@ bool Leader::ContainsMatchingServer(const ServiceTlv *aService, const ServerTlv bool contains = false; const ServerTlv *server; - VerifyOrExit(aService != NULL, OT_NOOP); + VerifyOrExit(aService != nullptr, OT_NOOP); for (const NetworkDataTlv *start = aService->GetSubTlvs(); - (server = FindTlv(start, aService->GetNext(), aServer.IsStable())) != NULL; + (server = FindTlv(start, aService->GetNext(), aServer.IsStable())) != nullptr; start = server->GetNext()) { if (*server == aServer) @@ -756,10 +756,10 @@ otError Leader::AddPrefix(const PrefixTlv &aPrefix, ChangedFlags &aChangedFlags) otError error = OT_ERROR_NONE; PrefixTlv *dstPrefix = FindPrefix(aPrefix.GetPrefix(), aPrefix.GetPrefixLength()); - if (dstPrefix == NULL) + if (dstPrefix == nullptr) { dstPrefix = static_cast(AppendTlv(PrefixTlv::CalculateSize(aPrefix.GetPrefixLength()))); - VerifyOrExit(dstPrefix != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(dstPrefix != nullptr, error = OT_ERROR_NO_BUFS); dstPrefix->Init(aPrefix.GetDomainId(), aPrefix.GetPrefixLength(), aPrefix.GetPrefix()); } @@ -783,7 +783,7 @@ otError Leader::AddPrefix(const PrefixTlv &aPrefix, ChangedFlags &aChangedFlags) } exit: - if (dstPrefix != NULL) + if (dstPrefix != nullptr) { // `UpdatePrefix()` updates the TLV's stable flag based on // its sub-TLVs, or removes the TLV if it contains no sub-TLV. @@ -804,7 +804,7 @@ otError Leader::AddService(const ServiceTlv &aService, ChangedFlags &aChangedFla FindService(aService.GetEnterpriseNumber(), aService.GetServiceData(), aService.GetServiceDataLength()); const ServerTlv *server; - if (dstService == NULL) + if (dstService == nullptr) { uint8_t serviceId; @@ -812,19 +812,19 @@ otError Leader::AddService(const ServiceTlv &aService, ChangedFlags &aChangedFla dstService = static_cast( AppendTlv(ServiceTlv::CalculateSize(aService.GetEnterpriseNumber(), aService.GetServiceDataLength()))); - VerifyOrExit(dstService != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(dstService != nullptr, error = OT_ERROR_NO_BUFS); dstService->Init(serviceId, aService.GetEnterpriseNumber(), aService.GetServiceData(), aService.GetServiceDataLength()); } server = FindTlv(aService.GetSubTlvs(), aService.GetNext()); - OT_ASSERT(server != NULL); + OT_ASSERT(server != nullptr); SuccessOrExit(error = AddServer(*server, *dstService, aChangedFlags)); exit: - if (dstService != NULL) + if (dstService != nullptr) { // `UpdateService()` updates the TLV's stable flag based on // its sub-TLVs, or removes the TLV if it contains no sub-TLV. @@ -844,7 +844,7 @@ otError Leader::AddHasRoute(const HasRouteTlv &aHasRoute, PrefixTlv &aDstPrefix, HasRouteTlv * dstHasRoute = FindHasRoute(aDstPrefix, aHasRoute.IsStable()); const HasRouteEntry *entry = aHasRoute.GetFirstEntry(); - if (dstHasRoute == NULL) + if (dstHasRoute == nullptr) { // Ensure there is space for `HasRouteTlv` and a single entry. VerifyOrExit(CanInsert(sizeof(HasRouteTlv) + sizeof(HasRouteEntry)), error = OT_ERROR_NO_BUFS); @@ -885,7 +885,7 @@ otError Leader::AddBorderRouter(const BorderRouterTlv &aBorderRouter, uint8_t contextId = 0; const BorderRouterEntry *entry = aBorderRouter.GetFirstEntry(); - if (dstContext == NULL) + if (dstContext == nullptr) { // Allocate a Context ID first. This ensure that if we cannot // allocate, we fail and exit before potentially inserting a @@ -893,12 +893,12 @@ otError Leader::AddBorderRouter(const BorderRouterTlv &aBorderRouter, SuccessOrExit(error = AllocateContextId(contextId)); } - if (dstBorderRouter == NULL) + if (dstBorderRouter == nullptr) { // Ensure there is space for `BorderRouterTlv` with a single entry // and a `ContextTlv` (if not already present). VerifyOrExit(CanInsert(sizeof(BorderRouterTlv) + sizeof(BorderRouterEntry) + - ((dstContext == NULL) ? sizeof(ContextTlv) : 0)), + ((dstContext == nullptr) ? sizeof(ContextTlv) : 0)), error = OT_ERROR_NO_BUFS); dstBorderRouter = static_cast(aDstPrefix.GetNext()); @@ -912,7 +912,7 @@ otError Leader::AddBorderRouter(const BorderRouterTlv &aBorderRouter, } } - if (dstContext == NULL) + if (dstContext == nullptr) { // Ensure there is space for a `ContextTlv` and a single entry. VerifyOrExit(CanInsert(sizeof(BorderRouterEntry) + sizeof(ContextTlv)), error = OT_ERROR_NO_BUFS); @@ -978,7 +978,7 @@ otError Leader::AllocateServiceId(uint8_t &aServiceId) for (serviceId = Mle::kServiceMinId; serviceId <= Mle::kServiceMaxId; serviceId++) { - if (FindServiceById(serviceId) == NULL) + if (FindServiceById(serviceId) == nullptr) { aServiceId = serviceId; error = OT_ERROR_NONE; @@ -995,7 +995,7 @@ const ServiceTlv *Leader::FindServiceById(uint8_t aServiceId) const const NetworkDataTlv *start = GetTlvsStart(); const ServiceTlv * service; - while ((service = FindTlv(start, GetTlvsEnd())) != NULL) + while ((service = FindTlv(start, GetTlvsEnd())) != nullptr) { if (service->GetServiceId() == aServiceId) { @@ -1055,7 +1055,7 @@ void Leader::StopContextReuseTimer(uint8_t aContextId) void Leader::RemoveRloc(uint16_t aRloc16, MatchMode aMatchMode, ChangedFlags &aChangedFlags) { - RemoveRloc(aRloc16, aMatchMode, NULL, 0, aChangedFlags); + RemoveRloc(aRloc16, aMatchMode, nullptr, 0, aChangedFlags); } void Leader::RemoveRloc(uint16_t aRloc16, @@ -1170,7 +1170,7 @@ void Leader::RemoveRlocInPrefix(PrefixTlv & aPrefix, cur = cur->GetNext(); } - if ((context = FindContext(aPrefix)) != NULL) + if ((context = FindContext(aPrefix)) != nullptr) { if (aPrefix.GetSubTlvsLength() == sizeof(ContextTlv)) { @@ -1197,7 +1197,7 @@ void Leader::RemoveRlocInService(ServiceTlv & aService, NetworkDataTlv *start = aService.GetSubTlvs(); ServerTlv * server; - while ((server = FindTlv(start, aService.GetNext())) != NULL) + while ((server = FindTlv(start, aService.GetNext())) != nullptr) { if (RlocMatch(server->GetServer16(), aRloc16, aMatchMode) && !ContainsMatchingServer(aExcludeService, *server)) { @@ -1276,7 +1276,7 @@ void Leader::RemoveContext(uint8_t aContextId) NetworkDataTlv *start = GetTlvsStart(); PrefixTlv * prefix; - while ((prefix = FindTlv(start, GetTlvsEnd())) != NULL) + while ((prefix = FindTlv(start, GetTlvsEnd())) != nullptr) { RemoveContext(*prefix, aContextId); @@ -1295,7 +1295,7 @@ void Leader::RemoveContext(PrefixTlv &aPrefix, uint8_t aContextId) NetworkDataTlv *start = aPrefix.GetSubTlvs(); ContextTlv * context; - while ((context = FindTlv(start, aPrefix.GetNext())) != NULL) + while ((context = FindTlv(start, aPrefix.GetNext())) != nullptr) { if (context->GetContextId() == aContextId) { @@ -1314,11 +1314,12 @@ void Leader::UpdateContextsAfterReset(void) NetworkDataTlv *start; PrefixTlv * prefix; - for (start = GetTlvsStart(); (prefix = FindTlv(start, GetTlvsEnd())) != NULL; start = prefix->GetNext()) + for (start = GetTlvsStart(); (prefix = FindTlv(start, GetTlvsEnd())) != nullptr; + start = prefix->GetNext()) { ContextTlv *context = FindContext(*prefix); - if (context == NULL) + if (context == nullptr) { continue; } @@ -1379,7 +1380,7 @@ otError Leader::RemoveStaleChildEntries(Coap::ResponseHandler aHandler, void *aC while (GetNextServer(iterator, rloc16) == OT_ERROR_NONE) { if (!Mle::Mle::IsActiveRouter(rloc16) && Mle::Mle::RouterIdMatch(Get().GetRloc16(), rloc16) && - Get().FindChild(rloc16, Child::kInStateValid) == NULL) + Get().FindChild(rloc16, Child::kInStateValid) == nullptr) { // In Thread 1.1 Specification 5.15.6.1, only one RLOC16 TLV entry may appear in SRV_DATA.ntf. error = NetworkData::SendServerDataNotification(rloc16, aHandler, aContext); diff --git a/src/core/thread/network_data_leader_ftd.hpp b/src/core/thread/network_data_leader_ftd.hpp index f0f70badc..fabafaafb 100644 --- a/src/core/thread/network_data_leader_ftd.hpp +++ b/src/core/thread/network_data_leader_ftd.hpp @@ -152,7 +152,7 @@ public: * This method scans network data for given Service ID and returns pointer to the respective TLV, if present. * * @param aServiceId Service ID to look for. - * @return Pointer to the Service TLV for given Service ID, or NULL if not present. + * @return Pointer to the Service TLV for given Service ID, or nullptr if not present. * */ const ServiceTlv *FindServiceById(uint8_t aServiceId) const; diff --git a/src/core/thread/network_data_local.cpp b/src/core/thread/network_data_local.cpp index 460abce2e..a65ad8a6d 100644 --- a/src/core/thread/network_data_local.cpp +++ b/src/core/thread/network_data_local.cpp @@ -154,7 +154,7 @@ otError Local::AddPrefix(const uint8_t * aPrefix, : sizeof(HasRouteTlv) + sizeof(HasRouteEntry); prefixTlv = static_cast(AppendTlv(sizeof(PrefixTlv) + prefixLengthBytes + subTlvLength)); - VerifyOrExit(prefixTlv != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(prefixTlv != nullptr, error = OT_ERROR_NO_BUFS); prefixTlv->Init(0, aPrefixLength, aPrefix); prefixTlv->SetSubTlvsLength(subTlvLength); @@ -194,8 +194,8 @@ otError Local::RemovePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, Netwo otError error = OT_ERROR_NONE; PrefixTlv *tlv; - VerifyOrExit((tlv = FindPrefix(aPrefix, aPrefixLength)) != NULL, error = OT_ERROR_NOT_FOUND); - VerifyOrExit(FindTlv(tlv->GetSubTlvs(), tlv->GetNext(), aSubTlvType) != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit((tlv = FindPrefix(aPrefix, aPrefixLength)) != nullptr, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(FindTlv(tlv->GetSubTlvs(), tlv->GetNext(), aSubTlvType) != nullptr, error = OT_ERROR_NOT_FOUND); RemoveTlv(tlv); exit: @@ -259,7 +259,7 @@ otError Local::AddService(uint32_t aEnterpriseNumber, VerifyOrExit(serviceTlvSize <= kMaxSize, error = OT_ERROR_NO_BUFS); serviceTlv = static_cast(AppendTlv(serviceTlvSize)); - VerifyOrExit(serviceTlv != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(serviceTlv != nullptr, error = OT_ERROR_NO_BUFS); serviceTlv->Init(/* aServiceId */ 0, aEnterpriseNumber, aServiceData, aServiceDataLength); serviceTlv->SetSubTlvsLength(sizeof(ServerTlv) + aServerDataLength); @@ -288,7 +288,7 @@ otError Local::RemoveService(uint32_t aEnterpriseNumber, const uint8_t *aService otError error = OT_ERROR_NONE; ServiceTlv *tlv; - VerifyOrExit((tlv = FindService(aEnterpriseNumber, aServiceData, aServiceDataLength)) != NULL, + VerifyOrExit((tlv = FindService(aEnterpriseNumber, aServiceData, aServiceDataLength)) != nullptr, error = OT_ERROR_NOT_FOUND); RemoveTlv(tlv); diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 650a600b5..2b778ce68 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -60,8 +60,8 @@ NetworkDiagnostic::NetworkDiagnostic(Instance &aInstance) , mDiagnosticGetQuery(OT_URI_PATH_DIAGNOSTIC_GET_QUERY, &NetworkDiagnostic::HandleDiagnosticGetQuery, this) , mDiagnosticGetAnswer(OT_URI_PATH_DIAGNOSTIC_GET_ANSWER, &NetworkDiagnostic::HandleDiagnosticGetAnswer, this) , mDiagnosticReset(OT_URI_PATH_DIAGNOSTIC_RESET, &NetworkDiagnostic::HandleDiagnosticReset, this) - , mReceiveDiagnosticGetCallback(NULL) - , mReceiveDiagnosticGetCallbackContext(NULL) + , mReceiveDiagnosticGetCallback(nullptr) + , mReceiveDiagnosticGetCallbackContext(nullptr) { Get().AddResource(mDiagnosticGetRequest); Get().AddResource(mDiagnosticGetQuery); @@ -81,11 +81,11 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination, uint8_t aCount) { otError error; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; - otCoapResponseHandler handler = NULL; + otCoapResponseHandler handler = nullptr; - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); if (aDestination.IsMulticast()) { @@ -127,7 +127,7 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -472,7 +472,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(void *aContext, otMessage *aMes void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; NetworkDiagnosticTlv networkDiagnosticTlv; Ip6::MessageInfo messageInfo; @@ -495,7 +495,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const } } - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DIAGNOSTIC_GET_ANSWER)); @@ -525,13 +525,13 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const IgnoreError(message->SetLength(message->GetLength() - 1)); } - SuccessOrExit(error = Get().SendMessage(*message, messageInfo, NULL, this)); + SuccessOrExit(error = Get().SendMessage(*message, messageInfo, nullptr, this)); otLogInfoNetDiag("Sent diagnostic get answer"); exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -548,7 +548,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(void * aContext void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; NetworkDiagnosticTlv networkDiagnosticTlv; Ip6::MessageInfo messageInfo(aMessageInfo); @@ -562,7 +562,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Message &aMessage, cons VerifyOrExit(networkDiagnosticTlv.GetType() == NetworkDiagnosticTlv::kTypeList, error = OT_ERROR_PARSE); - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->SetDefaultResponseHeader(aMessage)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -581,7 +581,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Message &aMessage, cons exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } @@ -592,10 +592,10 @@ otError NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination, uint8_t aCount) { otError error; - Coap::Message * message = NULL; + Coap::Message * message = nullptr; Ip6::MessageInfo messageInfo; - VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = Get().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DIAGNOSTIC_RESET)); @@ -627,7 +627,7 @@ otError NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination, exit: - if (error != OT_ERROR_NONE && message != NULL) + if (error != OT_ERROR_NONE && message != nullptr) { message->Free(); } diff --git a/src/core/thread/network_diagnostic.hpp b/src/core/thread/network_diagnostic.hpp index aed96a45f..553ef670c 100644 --- a/src/core/thread/network_diagnostic.hpp +++ b/src/core/thread/network_diagnostic.hpp @@ -84,7 +84,7 @@ public: * This method registers a callback to provide received raw DIAG_GET.rsp or an DIAG_GET.ans payload. * * @param[in] aCallback A pointer to a function that is called when an DIAG_GET.rsp or an DIAG_GET.ans - * is received or NULL to disable the callback. + * is received or nullptr to disable the callback. * @param[in] aCallbackContext A pointer to application-specific context. * */ diff --git a/src/core/thread/panid_query_server.cpp b/src/core/thread/panid_query_server.cpp index ac4c72223..a45e5ebd6 100644 --- a/src/core/thread/panid_query_server.cpp +++ b/src/core/thread/panid_query_server.cpp @@ -95,7 +95,7 @@ void PanIdQueryServer::HandleScanResult(Mac::ActiveScanResult *aScanResult, void void PanIdQueryServer::HandleScanResult(Mac::ActiveScanResult *aScanResult) { - if (aScanResult != NULL) + if (aScanResult != nullptr) { if (aScanResult->mPanId == mPanId) { @@ -115,7 +115,7 @@ void PanIdQueryServer::SendConflict(void) Ip6::MessageInfo messageInfo; Coap::Message * message; - VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get())) != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_PANID_CONFLICT)); SuccessOrExit(error = message->SetPayloadMarker()); @@ -139,7 +139,7 @@ exit: { otLogWarnMeshCoP("Failed to send panid conflict: %s", otThreadErrorToString(error)); - if (message != NULL) + if (message != nullptr) { message->Free(); } diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index 759f73e0a..3eecdcf10 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -44,7 +44,7 @@ namespace ot { RouterTable::Iterator::Iterator(Instance &aInstance) : InstanceLocator(aInstance) - , mRouter(NULL) + , mRouter(nullptr) { Reset(); } @@ -76,7 +76,7 @@ RouterTable::RouterTable(Instance &aInstance) const Router *RouterTable::GetFirstEntry(void) const { const Router *router = &mRouters[0]; - VerifyOrExit(router->GetRloc16() != 0xffff, router = NULL); + VerifyOrExit(router->GetRloc16() != 0xffff, router = nullptr); exit: return router; @@ -84,10 +84,10 @@ exit: const Router *RouterTable::GetNextEntry(const Router *aRouter) const { - VerifyOrExit(aRouter != NULL, OT_NOOP); + VerifyOrExit(aRouter != nullptr, OT_NOOP); aRouter++; - VerifyOrExit(aRouter < &mRouters[Mle::kMaxRouters], aRouter = NULL); - VerifyOrExit(aRouter->GetRloc16() != 0xffff, aRouter = NULL); + VerifyOrExit(aRouter < &mRouters[Mle::kMaxRouters], aRouter = nullptr); + VerifyOrExit(aRouter->GetRloc16() != 0xffff, aRouter = nullptr); exit: return aRouter; @@ -206,7 +206,7 @@ void RouterTable::UpdateAllocation(void) Router *RouterTable::Allocate(void) { - Router *rval = NULL; + Router *rval = nullptr; uint8_t numAvailable = 0; uint8_t freeBit; @@ -235,7 +235,7 @@ Router *RouterTable::Allocate(void) if (freeBit == 0) { rval = Allocate(routerId); - OT_ASSERT(rval != NULL); + OT_ASSERT(rval != nullptr); ExitNow(); } @@ -248,7 +248,7 @@ exit: Router *RouterTable::Allocate(uint8_t aRouterId) { - Router *rval = NULL; + Router *rval = nullptr; VerifyOrExit(aRouterId <= Mle::kMaxRouterId && mActiveRouterCount < Mle::kMaxRouters && !IsAllocated(aRouterId) && mRouterIdReuseDelay[aRouterId] == 0, @@ -285,7 +285,7 @@ otError RouterTable::Release(uint8_t aRouterId) mRouterIdReuseDelay[aRouterId] = Mle::kRouterIdReuseDelay; - for (Router *router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (Router *router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->GetNextHop() == rloc16) { @@ -312,7 +312,7 @@ void RouterTable::RemoveRouterLink(Router &aRouter) aRouter.SetLinkQualityOut(0); aRouter.SetLastHeard(TimerMilli::GetNow()); - for (Router *cur = GetFirstEntry(); cur != NULL; cur = GetNextEntry(cur)) + for (Router *cur = GetFirstEntry(); cur != nullptr; cur = GetNextEntry(cur)) { if (cur->GetNextHop() == aRouter.GetRouterId()) { @@ -339,7 +339,7 @@ uint8_t RouterTable::GetActiveLinkCount(void) const { uint8_t activeLinks = 0; - for (const Router *router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (const Router *router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->IsStateValid()) { @@ -352,11 +352,11 @@ uint8_t RouterTable::GetActiveLinkCount(void) const Router *RouterTable::GetNeighbor(uint16_t aRloc16) { - Router *router = NULL; + Router *router = nullptr; VerifyOrExit(aRloc16 != Get().GetRloc16(), OT_NOOP); - for (router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->IsStateValid() && router->GetRloc16() == aRloc16) { @@ -370,11 +370,11 @@ exit: Router *RouterTable::GetNeighbor(const Mac::ExtAddress &aExtAddress) { - Router *router = NULL; + Router *router = nullptr; VerifyOrExit(aExtAddress != Get().GetExtAddress(), OT_NOOP); - for (router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->IsStateValid() && router->GetExtAddress() == aExtAddress) { @@ -388,7 +388,7 @@ exit: const Router *RouterTable::GetRouter(uint8_t aRouterId) const { - const Router *router = NULL; + const Router *router = nullptr; uint16_t rloc16; // Skip if invalid router id is passed. @@ -396,7 +396,7 @@ const Router *RouterTable::GetRouter(uint8_t aRouterId) const rloc16 = Mle::Mle::Rloc16FromRouterId(aRouterId); - for (router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->GetRloc16() == rloc16) { @@ -410,9 +410,9 @@ exit: Router *RouterTable::GetRouter(const Mac::ExtAddress &aExtAddress) { - Router *router = NULL; + Router *router = nullptr; - for (router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->GetExtAddress() == aExtAddress) { @@ -441,7 +441,7 @@ otError RouterTable::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo } router = GetRouter(routerId); - VerifyOrExit(router != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(router != nullptr, error = OT_ERROR_NOT_FOUND); memset(&aRouterInfo, 0, sizeof(aRouterInfo)); aRouterInfo.mRouterId = routerId; @@ -473,7 +473,7 @@ uint8_t RouterTable::GetNeighborCount(void) const { uint8_t count = 0; - for (const Router *router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) + for (const Router *router = GetFirstEntry(); router != nullptr; router = GetNextEntry(router)) { if (router->IsStateValid()) { @@ -517,7 +517,7 @@ void RouterTable::UpdateRouterIdSet(uint8_t aRouterIdSequence, const Mle::Router { Router *router = GetRouter(routerId); - OT_ASSERT(router != NULL); + OT_ASSERT(router != nullptr); router->SetNextHop(Mle::kInvalidRouterId); RemoveRouterLink(*router); diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index 2e2e415f4..1709f992c 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -73,13 +73,13 @@ public: * @retval FALSE The iterator currently points to a valid entry. * */ - bool IsDone(void) const { return (mRouter == NULL); } + bool IsDone(void) const { return (mRouter == nullptr); } /** * This method advances the iterator. * * The iterator is moved to point to the next entry. If there are no more entries matching the iterator - * becomes empty (i.e., `GetRouter()` returns `NULL` and `IsDone()` returns `true`). + * becomes empty (i.e., `GetRouter()` returns `nullptr` and `IsDone()` returns `true`). * */ void Advance(void); @@ -88,7 +88,7 @@ public: * This method overloads `++` operator (pre-increment) to advance the iterator. * * The iterator is moved to point to the next entry. If there are no more entries matching the iterator - * becomes empty (i.e., `GetRouter()` returns `NULL` and `IsDone()` returns `true`). + * becomes empty (i.e., `GetRouter()` returns `nullptr` and `IsDone()` returns `true`). * */ void operator++(void) { Advance(); } @@ -97,7 +97,7 @@ public: * This method overloads `++` operator (post-increment) to advance the iterator. * * The iterator is moved to point to the next entry. If there are no more entries matching the iterator - * becomes empty (i.e., `GetRouter()` returns `NULL` and `IsDone()` returns `true`). + * becomes empty (i.e., `GetRouter()` returns `nullptr` and `IsDone()` returns `true`). * */ void operator++(int) { Advance(); } @@ -105,7 +105,7 @@ public: /** * This method gets the entry to which the iterator is currently pointing. * - * @returns A pointer to the current entry, or `NULL` if the iterator is done/empty. + * @returns A pointer to the current entry, or `nullptr` if the iterator is done/empty. * */ Router *GetRouter(void) { return mRouter; } @@ -137,7 +137,7 @@ public: /** * This method allocates a router with a random router id. * - * @returns A pointer to the allocated router or NULL if a router ID is not available. + * @returns A pointer to the allocated router or nullptr if a router ID is not available. * */ Router *Allocate(void); @@ -145,7 +145,7 @@ public: /** * This method allocates a router with a specified router id. * - * @returns A pointer to the allocated router or NULL if the router id could not be allocated. + * @returns A pointer to the allocated router or nullptr if the router id could not be allocated. * */ Router *Allocate(uint8_t aRouterId); @@ -217,7 +217,7 @@ public: * * @param[in] aRloc16 The RLOC16 value. * - * @returns A pointer to the router or NULL if the router could not be found. + * @returns A pointer to the router or nullptr if the router could not be found. * */ Router *GetNeighbor(uint16_t aRloc16); @@ -227,7 +227,7 @@ public: * * @param[in] aExtAddress A reference to the IEEE Extended Address. * - * @returns A pointer to the router or NULL if the router could not be found. + * @returns A pointer to the router or nullptr if the router could not be found. * */ Router *GetNeighbor(const Mac::ExtAddress &aExtAddress); @@ -237,7 +237,7 @@ public: * * @param[in] aRouterId The router id. * - * @returns A pointer to the router or NULL if the router could not be found. + * @returns A pointer to the router or nullptr if the router could not be found. * */ Router *GetRouter(uint8_t aRouterId) @@ -250,7 +250,7 @@ public: * * @param[in] aRouterId The router id. * - * @returns A pointer to the router or NULL if the router could not be found. + * @returns A pointer to the router or nullptr if the router could not be found. * */ const Router *GetRouter(uint8_t aRouterId) const; @@ -260,7 +260,7 @@ public: * * @param[in] aExtAddress A reference to the IEEE Extended Address. * - * @returns A pointer to the router or NULL if the router could not be found. + * @returns A pointer to the router or nullptr if the router could not be found. * */ Router *GetRouter(const Mac::ExtAddress &aExtAddress); diff --git a/src/core/thread/time_sync_service.cpp b/src/core/thread/time_sync_service.cpp index 51c1a1434..0bf5d4a78 100644 --- a/src/core/thread/time_sync_service.cpp +++ b/src/core/thread/time_sync_service.cpp @@ -61,8 +61,8 @@ TimeSync::TimeSync(Instance &aInstance) #endif , mLastTimeSyncReceived(0) , mNetworkTimeOffset(0) - , mTimeSyncCallback(NULL) - , mTimeSyncCallbackContext(NULL) + , mTimeSyncCallback(nullptr) + , mTimeSyncCallbackContext(nullptr) , mTimer(aInstance, HandleTimeout, this) , mCurrentStatus(OT_NETWORK_TIME_UNSYNCHRONIZED) { @@ -142,7 +142,7 @@ void TimeSync::IncrementTimeSyncSeq(void) void TimeSync::NotifyTimeSyncCallback(void) { - if (mTimeSyncCallback != NULL) + if (mTimeSyncCallback != nullptr) { mTimeSyncCallback(mTimeSyncCallbackContext); } diff --git a/src/core/utils/channel_manager.cpp b/src/core/utils/channel_manager.cpp index e76a96c77..977ee6f07 100644 --- a/src/core/utils/channel_manager.cpp +++ b/src/core/utils/channel_manager.cpp @@ -204,7 +204,7 @@ void ChannelManager::PreparePendingDataset(void) dataset.mDelay = delayInMs; dataset.mComponents.mIsDelayPresent = true; - error = Get().SendSetRequest(dataset, NULL, 0); + error = Get().SendSetRequest(dataset, nullptr, 0); if (error == OT_ERROR_NONE) { diff --git a/src/core/utils/channel_monitor.cpp b/src/core/utils/channel_monitor.cpp index f26d04599..901a6e620 100644 --- a/src/core/utils/channel_monitor.cpp +++ b/src/core/utils/channel_monitor.cpp @@ -132,7 +132,7 @@ void ChannelMonitor::HandleEnergyScanResult(Mac::EnergyScanResult *aResult, void void ChannelMonitor::HandleEnergyScanResult(Mac::EnergyScanResult *aResult) { - if (aResult == NULL) + if (aResult == nullptr) { if (mChannelMaskIndex == kNumChannelMasks - 1) { diff --git a/src/core/utils/child_supervision.cpp b/src/core/utils/child_supervision.cpp index 09e3128e7..16ce303ac 100644 --- a/src/core/utils/child_supervision.cpp +++ b/src/core/utils/child_supervision.cpp @@ -63,7 +63,7 @@ void ChildSupervisor::SetSupervisionInterval(uint16_t aInterval) Child *ChildSupervisor::GetDestination(const Message &aMessage) const { - Child * child = NULL; + Child * child = nullptr; uint16_t childIndex; VerifyOrExit(aMessage.GetType() == Message::kTypeSupervision, OT_NOOP); @@ -77,13 +77,13 @@ exit: void ChildSupervisor::SendMessage(Child &aChild) { - Message *message = NULL; + Message *message = nullptr; uint16_t childIndex; VerifyOrExit(aChild.GetIndirectMessageCount() == 0, OT_NOOP); message = Get().New(Message::kTypeSupervision, sizeof(uint8_t)); - VerifyOrExit(message != NULL, OT_NOOP); + VerifyOrExit(message != nullptr, OT_NOOP); // Supervision message is an empty payload 15.4 data frame. // The child index is stored here in the message content to allow @@ -94,13 +94,13 @@ void ChildSupervisor::SendMessage(Child &aChild) SuccessOrExit(message->Append(&childIndex, sizeof(childIndex))); SuccessOrExit(Get().SendMessage(*message)); - message = NULL; + message = nullptr; otLogInfoUtil("Sending supervision message to child 0x%04x", aChild.GetRloc16()); exit: - if (message != NULL) + if (message != nullptr) { message->Free(); } diff --git a/src/core/utils/child_supervision.hpp b/src/core/utils/child_supervision.hpp index cd8a2190a..619e71597 100644 --- a/src/core/utils/child_supervision.hpp +++ b/src/core/utils/child_supervision.hpp @@ -135,7 +135,8 @@ public: * * @param[in] aMessage The message for which to get the destination. * - * @returns A pointer to the destination child of the message, or NULL if @p aMessage is not of supervision type. + * @returns A pointer to the destination child of the message, or nullptr if @p aMessage is not of supervision + * type. * */ Child *GetDestination(const Message &aMessage) const; @@ -177,7 +178,7 @@ public: void Stop(void) {} void SetSupervisionInterval(uint16_t) {} uint16_t GetSupervisionInterval(void) const { return 0; } - Child * GetDestination(const Message &) const { return NULL; } + Child * GetDestination(const Message &) const { return nullptr; } void UpdateOnSend(Child &) {} }; diff --git a/src/core/utils/flash.cpp b/src/core/utils/flash.cpp index 7102a7ddd..4487427fe 100644 --- a/src/core/utils/flash.cpp +++ b/src/core/utils/flash.cpp @@ -170,7 +170,7 @@ otError Flash::Set(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength) otError Flash::Add(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength) { - bool first = (Get(aKey, 0, NULL, NULL) == OT_ERROR_NOT_FOUND); + bool first = (Get(aKey, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND); return Add(aKey, first, aValue, aValueLength); } diff --git a/src/core/utils/flash.hpp b/src/core/utils/flash.hpp index 709aace27..3ff665b39 100644 --- a/src/core/utils/flash.hpp +++ b/src/core/utils/flash.hpp @@ -70,12 +70,12 @@ public: * @param[in] aKey The key associated with the requested value. * @param[in] aIndex The index of the specific item to get. * @param[out] aValue A pointer to where the value of the setting should be written. - * May be NULL if just testing for the presence or length of a key. + * May be nullptr if just testing for the presence or length of a key. * @param[inout] aValueLength A pointer to the length of the value. * When called, this should point to an integer containing the maximum bytes that * can be written to @p aValue. * At return, the actual length of the setting is written. - * May be NULL if performing a presence check. + * May be nullptr if performing a presence check. * * @retval OT_ERROR_NONE The value was fetched successfully. * @retval OT_ERROR_NOT_FOUND The key was not found. @@ -91,7 +91,7 @@ public: * * @param[in] aKey The key associated with the value. * @param[in] aValue A pointer to where the new value of the setting should be read from. - * MUST NOT be NULL if @p aValueLength is non-zero. + * MUST NOT be nullptr if @p aValueLength is non-zero. * @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero. * * @retval OT_ERROR_NONE The value was changed. @@ -105,7 +105,7 @@ public: * * @param[in] aKey The key associated with the value. * @param[in] aValue A pointer to where the new value of the setting should be read from. - * MUST NOT be NULL if @p aValueLength is non-zero. + * MUST NOT be nullptr if @p aValueLength is non-zero. * @param[in] aValueLength The length of the data pointed to by @p aValue. May be zero. * * @retval OT_ERROR_NONE The value was added. diff --git a/src/core/utils/heap.cpp b/src/core/utils/heap.cpp index 6bc7c8116..36b13d8e4 100644 --- a/src/core/utils/heap.cpp +++ b/src/core/utils/heap.cpp @@ -61,9 +61,9 @@ Heap::Heap(void) void *Heap::CAlloc(size_t aCount, size_t aSize) { - void * ret = NULL; - Block * prev = NULL; - Block * curr = NULL; + void * ret = nullptr; + Block * prev = nullptr; + Block * curr = nullptr; uint16_t size = static_cast(aCount * aSize); VerifyOrExit(size, OT_NOOP); @@ -144,7 +144,7 @@ Block &Heap::BlockPrev(const Block &aBlock) void Heap::Free(void *aPointer) { - if (aPointer == NULL) + if (aPointer == nullptr) { return; } diff --git a/src/core/utils/heap.hpp b/src/core/utils/heap.hpp index 99bbdad3c..a7d2a1f68 100644 --- a/src/core/utils/heap.hpp +++ b/src/core/utils/heap.hpp @@ -193,7 +193,7 @@ public: * * @returns A pointer to the allocated memory. * - * @retval NULL Indicates not enough memory. + * @retval nullptr Indicates not enough memory. * */ void *CAlloc(size_t aCount, size_t aSize); diff --git a/src/core/utils/jam_detector.cpp b/src/core/utils/jam_detector.cpp index 6abc68820..2d2064f09 100644 --- a/src/core/utils/jam_detector.cpp +++ b/src/core/utils/jam_detector.cpp @@ -48,8 +48,8 @@ namespace Utils { JamDetector::JamDetector(Instance &aInstance) : InstanceLocator(aInstance) , Notifier::Receiver(aInstance, JamDetector::HandleNotifierEvents) - , mHandler(NULL) - , mContext(NULL) + , mHandler(nullptr) + , mContext(nullptr) , mTimer(aInstance, JamDetector::HandleTimer, this) , mHistoryBitmap(0) , mCurSecondStartTime(0) @@ -68,7 +68,7 @@ otError JamDetector::Start(Handler aHandler, void *aContext) otError error = OT_ERROR_NONE; VerifyOrExit(!mEnabled, error = OT_ERROR_ALREADY); - VerifyOrExit(aHandler != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aHandler != nullptr, error = OT_ERROR_INVALID_ARGS); mHandler = aHandler; mContext = aContext; diff --git a/src/core/utils/parse_cmdline.hpp b/src/core/utils/parse_cmdline.hpp index 8af5b6ccf..670ccd9da 100644 --- a/src/core/utils/parse_cmdline.hpp +++ b/src/core/utils/parse_cmdline.hpp @@ -63,7 +63,7 @@ public: * and @p aArgs will point to the arguments in the input @p aString. Backslash ('\') can be used * to escape separators (' ', '\t', '\r', '\n') and the backslash itself. * - * @param[in] aString A NULL-terminated input string. + * @param[in] aString A null-terminated input string. * @param[out] aArgsLength The argument counter of the command line. * @param[out] aArgs The argument vector of the command line. * @param[in] aArgsLengthMax The maximum argument counter. diff --git a/src/core/utils/slaac_address.cpp b/src/core/utils/slaac_address.cpp index 171abd1df..70a23e7de 100644 --- a/src/core/utils/slaac_address.cpp +++ b/src/core/utils/slaac_address.cpp @@ -51,7 +51,7 @@ Slaac::Slaac(Instance &aInstance) : InstanceLocator(aInstance) , Notifier::Receiver(aInstance, Slaac::HandleNotifierEvents) , mEnabled(true) - , mFilter(NULL) + , mFilter(nullptr) { memset(mAddresses, 0, sizeof(mAddresses)); } @@ -85,7 +85,7 @@ void Slaac::SetFilter(otIp6SlaacPrefixFilter aFilter) VerifyOrExit(aFilter != mFilter, OT_NOOP); mFilter = aFilter; - otLogInfoUtil("SLAAC: Filter %s", (mFilter != NULL) ? "updated" : "disabled"); + otLogInfoUtil("SLAAC: Filter %s", (mFilter != nullptr) ? "updated" : "disabled"); VerifyOrExit(mEnabled, OT_NOOP); Update(kModeAdd | kModeRemove); @@ -96,7 +96,7 @@ exit: bool Slaac::ShouldFilter(const otIp6Prefix &aPrefix) const { - return (mFilter != NULL) && mFilter(&GetInstance(), &aPrefix); + return (mFilter != nullptr) && mFilter(&GetInstance(), &aPrefix); } void Slaac::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents) @@ -210,7 +210,7 @@ void Slaac::Update(UpdateMode aMode) found = false; for (const Ip6::NetifUnicastAddress *netifAddr = Get().GetUnicastAddresses(); - netifAddr != NULL; netifAddr = netifAddr->GetNext()) + netifAddr != nullptr; netifAddr = netifAddr->GetNext()) { if ((netifAddr->mPrefixLength == prefix.mLength) && (netifAddr->GetAddress().PrefixMatch(prefix.mPrefix) >= prefix.mLength)) @@ -272,7 +272,7 @@ otError Slaac::GenerateIid(Ip6::NetifUnicastAddress &aAddress, * - RID is random (but stable) Identifier. * - For pseudo-random function `F()` SHA-256 is used in this method. * - `Net_Iface` is set to constant string "wpan". - * - `Network_ID` is not used if `aNetworkId` is NULL (optional per RF-7217). + * - `Network_ID` is not used if `aNetworkId` is nullptr (optional per RF-7217). * - The `secret_key` is randomly generated on first use (using true * random number generator) and saved in non-volatile settings for * future use. diff --git a/src/core/utils/slaac_address.hpp b/src/core/utils/slaac_address.hpp index 5e209a3a1..b391d47a6 100644 --- a/src/core/utils/slaac_address.hpp +++ b/src/core/utils/slaac_address.hpp @@ -115,7 +115,7 @@ public: * boolean value from handler determines whether the address is filtered or added (TRUE to filter the address, * FALSE to add address). * - * The filter can be set to `NULL` to disable filtering (i.e., allow SLAAC addresses for all prefixes). + * The filter can be set to `nullptr` to disable filtering (i.e., allow SLAAC addresses for all prefixes). * */ void SetFilter(otIp6SlaacPrefixFilter aFilter); @@ -136,9 +136,9 @@ public: * */ otError GenerateIid(Ip6::NetifUnicastAddress &aAddress, - uint8_t * aNetworkId = NULL, + uint8_t * aNetworkId = nullptr, uint8_t aNetworkIdLength = 0, - uint8_t * aDadCounter = NULL) const; + uint8_t * aDadCounter = nullptr) const; private: enum diff --git a/src/lib/hdlc/hdlc.hpp b/src/lib/hdlc/hdlc.hpp index 8116a9288..4092f4346 100644 --- a/src/lib/hdlc/hdlc.hpp +++ b/src/lib/hdlc/hdlc.hpp @@ -116,7 +116,7 @@ public: protected: FrameWritePointer(void) - : mWritePointer(NULL) + : mWritePointer(nullptr) , mRemainingLength(0) { } @@ -352,8 +352,9 @@ public: /** * This method iterates through previously saved frames in the buffer, getting a next frame in the queue. * - * @param[inout] aFrame On entry, should point to a previous saved frame or NULL to get the first frame. - * On exit, the pointer variable is updated to next frame or set to NULL if there are none. + * @param[inout] aFrame On entry, should point to a previous saved frame or nullptr to get the first frame. + * On exit, the pointer variable is updated to next frame or set to nullptr if there are + * none. * @param[inout] aLength On entry, should be a reference to the frame length of the previous saved frame. * On exit, the reference is updated to the frame length (number of bytes) of next frame. * @@ -365,9 +366,9 @@ public: { otError error = OT_ERROR_NONE; - OT_ASSERT(aFrame == NULL || (mBuffer <= aFrame && aFrame < OT_ARRAY_END(mBuffer))); + OT_ASSERT(aFrame == nullptr || (mBuffer <= aFrame && aFrame < OT_ARRAY_END(mBuffer))); - aFrame = (aFrame == NULL) ? mBuffer : aFrame + aLength; + aFrame = (aFrame == nullptr) ? mBuffer : aFrame + aLength; if (aFrame != mWriteFrameStart) { @@ -380,7 +381,7 @@ public: else { aLength = 0; - aFrame = NULL; + aFrame = nullptr; error = OT_ERROR_NOT_FOUND; } diff --git a/src/lib/spinel/radio_spinel.hpp b/src/lib/spinel/radio_spinel.hpp index 600f7c1cc..c228a5a14 100644 --- a/src/lib/spinel/radio_spinel.hpp +++ b/src/lib/spinel/radio_spinel.hpp @@ -323,7 +323,7 @@ public: * @param[out] aCoexMetrics A reference to the coexistence metrics structure. * * @retval OT_ERROR_NONE Successfully retrieved the coex metrics. - * @retval OT_ERROR_INVALID_ARGS @p aCoexMetrics was NULL. + * @retval OT_ERROR_INVALID_ARGS @p aCoexMetrics was nullptr. * */ otError GetCoexMetrics(otRadioCoexMetrics &aCoexMetrics); @@ -565,7 +565,7 @@ public: /** * This method processes platform diagnostics commands. * - * @param[in] aString A NULL-terminated input string. + * @param[in] aString A null-terminated input string. * @param[out] aOutput The diagnostics execution result. * @param[in] aOutputMaxLen The output buffer size. * diff --git a/src/lib/spinel/radio_spinel_impl.hpp b/src/lib/spinel/radio_spinel_impl.hpp index 9fb118bd4..6542d110a 100644 --- a/src/lib/spinel/radio_spinel_impl.hpp +++ b/src/lib/spinel/radio_spinel_impl.hpp @@ -170,7 +170,7 @@ void RadioSpinel::HandleReceivedFrame(void *a template RadioSpinel::RadioSpinel(void) - : mInstance(NULL) + : mInstance(nullptr) , mRxFrameBuffer() , mSpinelInterface(HandleReceivedFrame, this, mRxFrameBuffer) , mCmdTidsInUse(0) @@ -178,10 +178,10 @@ RadioSpinel::RadioSpinel(void) , mTxRadioTid(0) , mWaitingTid(0) , mWaitingKey(SPINEL_PROP_LAST_STATUS) - , mPropertyFormat(NULL) + , mPropertyFormat(nullptr) , mExpectedCommand(0) , mError(OT_ERROR_NONE) - , mTransmitFrame(NULL) + , mTransmitFrame(nullptr) , mShortAddress(0) , mPanId(0xffff) , mRadioCaps(0) @@ -194,7 +194,7 @@ RadioSpinel::RadioSpinel(void) , mIsTimeSynced(false) #if OPENTHREAD_CONFIG_DIAG_ENABLE , mDiagMode(false) - , mDiagOutput(NULL) + , mDiagOutput(nullptr) , mDiagOutputMaxLen(0) #endif , mTxRadioEndUs(UINT64_MAX) @@ -410,7 +410,7 @@ void RadioSpinel::HandleNotification(SpinelIn spinel_prop_key_t key; spinel_size_t len = 0; spinel_ssize_t unpacked; - uint8_t * data = NULL; + uint8_t * data = nullptr; uint32_t cmd; uint8_t header; otError error = OT_ERROR_NONE; @@ -464,7 +464,7 @@ void RadioSpinel::HandleNotification(const ui spinel_prop_key_t key; spinel_size_t len = 0; spinel_ssize_t unpacked; - uint8_t * data = NULL; + uint8_t * data = nullptr; uint32_t cmd; uint8_t header; otError error = OT_ERROR_NONE; @@ -483,7 +483,7 @@ template void RadioSpinel::HandleResponse(const uint8_t *aBuffer, uint16_t aLength) { spinel_prop_key_t key; - uint8_t * data = NULL; + uint8_t * data = nullptr; spinel_size_t len = 0; uint8_t header = 0; uint32_t cmd = 0; @@ -693,7 +693,7 @@ void RadioSpinel::HandleWaitingResponse(uint3 { spinel_ssize_t unpacked; - VerifyOrExit(mDiagOutput != NULL, OT_NOOP); + VerifyOrExit(mDiagOutput != nullptr, OT_NOOP); unpacked = spinel_datatype_unpack_in_place(aBuffer, aLength, SPINEL_DATATYPE_UTF8_S, mDiagOutput, &mDiagOutputMaxLen); VerifyOrExit(unpacked > 0, mError = OT_ERROR_PARSE); @@ -708,7 +708,7 @@ void RadioSpinel::HandleWaitingResponse(uint3 // reserved SPINEL_DATATYPE_VOID_C indicate caller want to parse the spinel response itself ResponseHandler handler = va_arg(mPropertyArgs, ResponseHandler); - assert(handler != NULL); + assert(handler != nullptr); mError = (this->*handler)(aBuffer, aLength); } else @@ -900,7 +900,7 @@ exit: template void RadioSpinel::ProcessFrameQueue(void) { - uint8_t *frame = NULL; + uint8_t *frame = nullptr; uint16_t length; while (mRxFrameBuffer.GetNextSavedFrame(frame, length) == OT_ERROR_NONE) @@ -969,7 +969,7 @@ void RadioSpinel::ProcessRadioStateMachine(vo mState = kStateReceive; mTxRadioEndUs = UINT64_MAX; - TransmitDone(mTransmitFrame, (mAckRadioFrame.mLength != 0) ? &mAckRadioFrame : NULL, mTxError); + TransmitDone(mTransmitFrame, (mAckRadioFrame.mLength != 0) ? &mAckRadioFrame : nullptr, mTxError); } else if (mState == kStateTransmitting && otPlatTimeGet() >= mTxRadioEndUs) { @@ -1119,13 +1119,13 @@ otError RadioSpinel::ClearSrcMatchExtEntry(co template otError RadioSpinel::ClearSrcMatchShortEntries(void) { - return Set(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, NULL); + return Set(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, nullptr); } template otError RadioSpinel::ClearSrcMatchExtEntries(void) { - return Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, NULL); + return Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr); } template @@ -1254,9 +1254,9 @@ otError RadioSpinel::Get(spinel_prop_key_t aK mPropertyFormat = aFormat; va_start(mPropertyArgs, aFormat); - error = RequestV(true, SPINEL_CMD_PROP_VALUE_GET, aKey, NULL, mPropertyArgs); + error = RequestV(true, SPINEL_CMD_PROP_VALUE_GET, aKey, nullptr, mPropertyArgs); va_end(mPropertyArgs); - mPropertyFormat = NULL; + mPropertyFormat = nullptr; return error; } @@ -1277,7 +1277,7 @@ otError RadioSpinel::GetWithParam(spinel_prop va_start(mPropertyArgs, aFormat); error = Request(true, SPINEL_CMD_PROP_VALUE_GET, aKey, SPINEL_DATATYPE_DATA_S, aParam, aParamSize); va_end(mPropertyArgs); - mPropertyFormat = NULL; + mPropertyFormat = nullptr; return error; } @@ -1657,7 +1657,7 @@ otError RadioSpinel::Disable(void) SuccessOrDie(Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, false)); mState = kStateDisabled; - mInstance = NULL; + mInstance = nullptr; exit: return error; @@ -1676,7 +1676,7 @@ otError RadioSpinel::PlatDiagProcess(const ch error = Set(SPINEL_PROP_NEST_STREAM_MFG, SPINEL_DATATYPE_UTF8_S, aString); - mDiagOutput = NULL; + mDiagOutput = nullptr; mDiagOutputMaxLen = 0; return error; diff --git a/src/lib/spinel/spinel_buffer.cpp b/src/lib/spinel/spinel_buffer.cpp index 408708898..c6869f2bb 100644 --- a/src/lib/spinel/spinel_buffer.cpp +++ b/src/lib/spinel/spinel_buffer.cpp @@ -38,7 +38,7 @@ namespace ot { namespace Spinel { -const Buffer::FrameTag Buffer::kInvalidTag = NULL; +const Buffer::FrameTag Buffer::kInvalidTag = nullptr; Buffer::Buffer(uint8_t *aBuffer, uint16_t aBufferLength) : mBuffer(aBuffer) @@ -54,8 +54,8 @@ Buffer::Buffer(uint8_t *aBuffer, uint16_t aBufferLength) otMessageQueueInit(&mWriteFrameMessageQueue); #endif - SetFrameAddedCallback(NULL, NULL); - SetFrameRemovedCallback(NULL, NULL); + SetFrameAddedCallback(nullptr, nullptr); + SetFrameRemovedCallback(nullptr, nullptr); Clear(); } @@ -85,13 +85,13 @@ void Buffer::Clear(void) mReadPointer = mBuffer; #if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE - mReadMessage = NULL; + mReadMessage = nullptr; mReadMessageOffset = 0; mReadMessageTail = mMessageBuffer; // Free all messages in the queues. - while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL) + while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != nullptr) { otMessageQueueDequeue(&mWriteFrameMessageQueue, message); @@ -102,7 +102,7 @@ void Buffer::Clear(void) for (uint8_t priority = 0; priority < kNumPrios; priority++) { - while ((message = otMessageQueueGetHead(&mMessageQueue[priority])) != NULL) + while ((message = otMessageQueueGetHead(&mMessageQueue[priority])) != nullptr) { otMessageQueueDequeue(&mMessageQueue[priority], message); otMessageFree(message); @@ -315,7 +315,7 @@ void Buffer::InFrameDiscard(void) mWriteSegmentHead = mWriteSegmentTail = mWriteFrameStart[mWriteDirection]; #if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE - while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL) + while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != nullptr) { otMessageQueueDequeue(&mWriteFrameMessageQueue, message); @@ -396,7 +396,7 @@ otError Buffer::InFrameFeedMessage(otMessage *aMessage) { otError error = OT_ERROR_NONE; - VerifyOrExit(aMessage != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aMessage != nullptr, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(mWriteDirection != kUnknown, error = OT_ERROR_INVALID_STATE); // Begin a new segment (if we are not in middle of segment already). @@ -518,14 +518,14 @@ otError Buffer::InFrameEnd(void) #if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE // Move all the messages from the frame queue to the main queue. - while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL) + while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != nullptr) { otMessageQueueDequeue(&mWriteFrameMessageQueue, message); otMessageQueueEnqueue(&mMessageQueue[mWriteDirection], message); } #endif - if (mFrameAddedCallback != NULL) + if (mFrameAddedCallback != nullptr) { mFrameAddedCallback(mFrameAddedContext, mWriteFrameTag, static_cast(mWriteDirection), this); } @@ -635,10 +635,10 @@ otError Buffer::OutFramePrepareMessage(void) VerifyOrExit((header & kSegmentHeaderMessageIndicatorFlag) != 0, error = OT_ERROR_NOT_FOUND); // Update the current message from the queue. - mReadMessage = (mReadMessage == NULL) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection]) - : otMessageQueueGetNext(&mMessageQueue[mReadDirection], mReadMessage); + mReadMessage = (mReadMessage == nullptr) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection]) + : otMessageQueueGetNext(&mMessageQueue[mReadDirection], mReadMessage); - VerifyOrExit(mReadMessage != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(mReadMessage != nullptr, error = OT_ERROR_NOT_FOUND); // Reset the offset for reading the message. mReadMessageOffset = 0; @@ -660,7 +660,7 @@ otError Buffer::OutFrameFillMessageBuffer(void) otError error = OT_ERROR_NONE; int readLength; - VerifyOrExit(mReadMessage != NULL, error = OT_ERROR_NOT_FOUND); + VerifyOrExit(mReadMessage != nullptr, error = OT_ERROR_NOT_FOUND); VerifyOrExit(mReadMessageOffset < otMessageGetLength(mReadMessage), error = OT_ERROR_NOT_FOUND); @@ -694,7 +694,7 @@ otError Buffer::OutFrameBegin(void) mReadSegmentHead = mReadSegmentTail = mReadFrameStart[mReadDirection]; #if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE - mReadMessage = NULL; + mReadMessage = nullptr; #endif // Prepare the current segment for reading. @@ -829,7 +829,7 @@ otError Buffer::OutFrameRemove(void) { otMessage *message; - if ((message = otMessageQueueGetHead(&mMessageQueue[mReadDirection])) != NULL) + if ((message = otMessageQueueGetHead(&mMessageQueue[mReadDirection])) != nullptr) { otMessageQueueDequeue(&mMessageQueue[mReadDirection], message); otMessageFree(message); @@ -854,7 +854,7 @@ otError Buffer::OutFrameRemove(void) mReadState = kReadStateNotActive; mReadFrameLength = kUnknownFrameLength; - if (mFrameRemovedCallback != NULL) + if (mFrameRemovedCallback != nullptr) { mFrameRemovedCallback(mFrameRemovedContext, tag, static_cast(mReadDirection), this); } @@ -893,7 +893,7 @@ uint16_t Buffer::OutFrameGetLength(void) uint8_t *bufPtr; uint8_t numSegments; #if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE - otMessage *message = NULL; + otMessage *message = nullptr; #endif // If the frame length was calculated before, return the previously calculated length. @@ -927,10 +927,10 @@ uint16_t Buffer::OutFrameGetLength(void) // If current segment has an associated message, add its length to frame length. if (header & kSegmentHeaderMessageIndicatorFlag) { - message = (message == NULL) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection]) - : otMessageQueueGetNext(&mMessageQueue[mReadDirection], message); + message = (message == nullptr) ? otMessageQueueGetHead(&mMessageQueue[mReadDirection]) + : otMessageQueueGetNext(&mMessageQueue[mReadDirection], message); - if (message != NULL) + if (message != nullptr) { frameLength += otMessageGetLength(message); } diff --git a/src/lib/spinel/spinel_buffer.hpp b/src/lib/spinel/spinel_buffer.hpp index c1de00775..2c216ce09 100644 --- a/src/lib/spinel/spinel_buffer.hpp +++ b/src/lib/spinel/spinel_buffer.hpp @@ -222,7 +222,7 @@ public: * @retval OT_ERROR_NONE Successfully added the message to the frame. * @retval OT_ERROR_NO_BUFS Insufficient buffer space available to add the message. * @retval OT_ERROR_INVALID_STATE `InFrameBegin()` has not been called earlier to start the frame. - * @retval OT_ERROR_INVALID_ARGS If @p aMessage is NULL. + * @retval OT_ERROR_INVALID_ARGS If @p aMessage is nullptr. * */ otError InFrameFeedMessage(otMessage *aMessage); @@ -405,7 +405,7 @@ public: * * When a frame is removed all its associated messages will be freed. * - * If the remove operation is successful, this method will invoke the `FrameRemovedCallback` (if not NULL) before + * If the remove operation is successful, this method will invoke the `FrameRemovedCallback` (if not nullptr) before * returning the success state. * * @retval OT_ERROR_NONE Successfully removed the front frame. diff --git a/src/lib/spinel/spinel_decoder.cpp b/src/lib/spinel/spinel_decoder.cpp index 0c26259e4..1d36c38b3 100644 --- a/src/lib/spinel/spinel_decoder.cpp +++ b/src/lib/spinel/spinel_decoder.cpp @@ -39,7 +39,7 @@ namespace ot { namespace Spinel { Decoder::Decoder(void) - : mFrame(NULL) + : mFrame(nullptr) , mLength(0) , mIndex(0) , mEnd(0) @@ -53,7 +53,7 @@ Decoder::Decoder(void) void Decoder::Init(const uint8_t *aFrame, uint16_t aLength) { mFrame = aFrame; - mLength = (mFrame != NULL) ? aLength : 0; + mLength = (mFrame != nullptr) ? aLength : 0; Reset(); ClearSavedPosition(); diff --git a/src/lib/spinel/spinel_encoder.hpp b/src/lib/spinel/spinel_encoder.hpp index f0487d856..84f2df6f7 100644 --- a/src/lib/spinel/spinel_encoder.hpp +++ b/src/lib/spinel/spinel_encoder.hpp @@ -561,7 +561,7 @@ public: * @retval OT_ERROR_NONE Successfully added the message to the frame. * @retval OT_ERROR_NO_BUFS Insufficient buffer space available to add the message. * @retval OT_ERROR_INVALID_STATE `BeginFrame()` has not been called earlier to start the frame. - * @retval OT_ERROR_INVALID_ARGS If @p aMessage is NULL. + * @retval OT_ERROR_INVALID_ARGS If @p aMessage is nullptr. * */ otError WriteMessage(otMessage *aMessage) { return mNcpBuffer.InFrameFeedMessage(aMessage); } diff --git a/src/ncp/changed_props_set.hpp b/src/ncp/changed_props_set.hpp index aa8fc0c25..0b7040c58 100644 --- a/src/ncp/changed_props_set.hpp +++ b/src/ncp/changed_props_set.hpp @@ -127,10 +127,13 @@ public: * * @param[in] aIndex The index to an entry. * - * @returns A pointer to the entry associated with @p aIndex, or NULL if the index is beyond end of array. + * @returns A pointer to the entry associated with @p aIndex, or nullptr if the index is beyond end of array. * */ - const Entry *GetEntry(uint8_t aIndex) const { return (aIndex < GetNumEntries()) ? &mSupportedProps[aIndex] : NULL; } + const Entry *GetEntry(uint8_t aIndex) const + { + return (aIndex < GetNumEntries()) ? &mSupportedProps[aIndex] : nullptr; + } /** * This method indicates if the entry associated with an index is in the set (i.e., it has been changed and diff --git a/src/ncp/example_vendor_hook.cpp b/src/ncp/example_vendor_hook.cpp index 58a530480..195e08400 100644 --- a/src/ncp/example_vendor_hook.cpp +++ b/src/ncp/example_vendor_hook.cpp @@ -142,12 +142,12 @@ static OT_DEFINE_ALIGNED_VAR(sNcpVendorRaw, sizeof(NcpVendorUart), uint64_t); extern "C" void otNcpInit(otInstance *aInstance) { - NcpVendorUart *ncpVendor = NULL; + NcpVendorUart *ncpVendor = nullptr; ot::Instance * instance = static_cast(aInstance); ncpVendor = new (&sNcpVendorRaw) NcpVendorUart(instance); - if (ncpVendor == NULL || ncpVendor != ot::Ncp::NcpBase::GetNcpInstance()) + if (ncpVendor == nullptr || ncpVendor != ot::Ncp::NcpBase::GetNcpInstance()) { // assert(false); } diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 7e1c6b6c2..fe5c497d0 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -191,7 +191,7 @@ static spinel_status_t ResetReasonToSpinelStatus(otPlatResetReason aReason) // MARK: Class Boilerplate // ---------------------------------------------------------------------------- -NcpBase *NcpBase::sNcpInstance = NULL; +NcpBase *NcpBase::sNcpInstance = nullptr; NcpBase::NcpBase(Instance *aInstance) : mInstance(aInstance) @@ -212,8 +212,8 @@ NcpBase::NcpBase(Instance *aInstance) , mHostPowerReplyFrameTag(Spinel::Buffer::kInvalidTag) , mHostPowerStateHeader(0) #if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE - , mAllowPeekDelegate(NULL) - , mAllowPokeDelegate(NULL) + , mAllowPeekDelegate(nullptr) + , mAllowPokeDelegate(nullptr) #endif , mNextExpectedTid(0) , mResponseQueueHead(0) @@ -250,7 +250,7 @@ NcpBase::NcpBase(Instance *aInstance) , mDidInitialUpdates(false) , mLogTimestampBase(0) { - OT_ASSERT(mInstance != NULL); + OT_ASSERT(mInstance != nullptr); sNcpInstance = this; @@ -279,7 +279,7 @@ NcpBase::NcpBase(Instance *aInstance) #endif // OPENTHREAD_FTD #if OPENTHREAD_CONFIG_LEGACY_ENABLE mLegacyNodeDidJoin = false; - mLegacyHandlers = NULL; + mLegacyHandlers = nullptr; memset(mLegacyUlaPrefix, 0, sizeof(mLegacyUlaPrefix)); memset(&mLegacyLastJoinedNode, 0, sizeof(mLegacyLastJoinedNode)); #endif @@ -965,7 +965,7 @@ otError NcpBase::HandleCommandPropertySet(uint8_t aHeader, spinel_prop_key_t aKe otError error = OT_ERROR_NONE; PropertyHandler handler = FindSetPropertyHandler(aKey); - if (handler != NULL) + if (handler != nullptr) { mDisableStreamWrite = false; error = (this->*handler)(); @@ -1016,7 +1016,7 @@ exit: otError NcpBase::HandleCommandPropertyInsertRemove(uint8_t aHeader, spinel_prop_key_t aKey, unsigned int aCommand) { otError error = OT_ERROR_NONE; - PropertyHandler handler = NULL; + PropertyHandler handler = nullptr; unsigned int responseCommand = 0; const uint8_t * valuePtr; uint16_t valueLen; @@ -1038,7 +1038,7 @@ otError NcpBase::HandleCommandPropertyInsertRemove(uint8_t aHeader, spinel_prop_ OT_UNREACHABLE_CODE(break); } - VerifyOrExit(handler != NULL, error = PrepareLastStatusResponse(aHeader, SPINEL_STATUS_PROP_NOT_FOUND)); + VerifyOrExit(handler != nullptr, error = PrepareLastStatusResponse(aHeader, SPINEL_STATUS_PROP_NOT_FOUND)); // Save current read position in the decoder. Read the entire // content as a data blob (which is used in forming the response @@ -1097,7 +1097,7 @@ otError NcpBase::WritePropertyValueIsFrame(uint8_t aHeader, spinel_prop_key_t aP otError error = OT_ERROR_NONE; PropertyHandler handler = FindGetPropertyHandler(aPropKey); - if (handler != NULL) + if (handler != nullptr) { SuccessOrExit(error = mEncoder.BeginFrame(aHeader, SPINEL_CMD_PROP_VALUE_IS, aPropKey)); SuccessOrExit(error = (this->*handler)()); @@ -1191,7 +1191,7 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader) mUpdateChangedPropsTask.Post(); } - sNcpInstance = NULL; + sNcpInstance = nullptr; return error; } @@ -1242,7 +1242,7 @@ otError NcpBase::CommandHandler_PEEK(uint8_t aHeader) VerifyOrExit(count != 0, parseError = OT_ERROR_INVALID_ARGS); - if (mAllowPeekDelegate != NULL) + if (mAllowPeekDelegate != nullptr) { VerifyOrExit(mAllowPeekDelegate(address, count), parseError = OT_ERROR_INVALID_ARGS); } @@ -1267,7 +1267,7 @@ otError NcpBase::CommandHandler_POKE(uint8_t aHeader) otError parseError = OT_ERROR_NONE; uint32_t address; uint16_t count; - const uint8_t *dataPtr = NULL; + const uint8_t *dataPtr = nullptr; uint16_t dataLen; SuccessOrExit(parseError = mDecoder.ReadUint32(address)); @@ -1277,7 +1277,7 @@ otError NcpBase::CommandHandler_POKE(uint8_t aHeader) VerifyOrExit(count != 0, parseError = OT_ERROR_INVALID_ARGS); VerifyOrExit(count <= dataLen, parseError = OT_ERROR_INVALID_ARGS); - if (mAllowPokeDelegate != NULL) + if (mAllowPokeDelegate != nullptr) { VerifyOrExit(mAllowPokeDelegate(address, count), parseError = OT_ERROR_INVALID_ARGS); } @@ -1298,7 +1298,7 @@ exit: otError NcpBase::HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader) { - const char *string = NULL; + const char *string = nullptr; char output[OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE]; otError error = OT_ERROR_NONE; @@ -2370,7 +2370,7 @@ void otNcpRegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDelegat { ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); - if (ncp != NULL) + if (ncp != nullptr) { ncp->RegisterPeekPokeDelagates(aAllowPeekDelegate, aAllowPokeDelegate); } @@ -2386,7 +2386,7 @@ otError otNcpStreamWrite(int aStreamId, const uint8_t *aDataPtr, int aDataLen) otError error = OT_ERROR_INVALID_STATE; ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); - if (ncp != NULL) + if (ncp != nullptr) { error = ncp->StreamWrite(aStreamId, aDataPtr, aDataLen); } @@ -2425,7 +2425,7 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch if (vsnprintf(logString, sizeof(logString), aFormat, args) > 0) { - if (ncp != NULL) + if (ncp != nullptr) { ncp->Log(aLogLevel, aLogRegion, logString); } diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 97ca3e06c..aecffeea2 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -92,7 +92,7 @@ public: * @param[in] aStreamId A numeric identifier for the stream to write to. * If set to '0', will default to the debug stream. * @param[in] aDataPtr A pointer to the data to send on the stream. - * If aDataLen is non-zero, this param MUST NOT be NULL. + * If aDataLen is non-zero, this param MUST NOT be nullptr. * @param[in] aDataLen The number of bytes of data from aDataPtr to send. * * @retval OT_ERROR_NONE The data was queued for delivery to the host. @@ -335,9 +335,9 @@ protected: otError EncodeOperationalDataset(const otOperationalDataset &aDataset); otError DecodeOperationalDataset(otOperationalDataset &aDataset, - const uint8_t ** aTlvs = NULL, - uint8_t * aTlvsLength = NULL, - const otIp6Address ** aDestIpAddress = NULL, + const uint8_t ** aTlvs = nullptr, + uint8_t * aTlvsLength = nullptr, + const otIp6Address ** aDestIpAddress = nullptr, bool aAllowEmptyValues = false); otError EncodeNeighborInfo(const otNeighborInfo &aNeighborInfo); diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index bf6eb5e32..47fa7bed6 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -656,7 +656,7 @@ NcpBase::PropertyHandler NcpBase::FindPropertyHandler(const HandlerEntry *aHandl } } - return aHandlerEntries[l].mKey == aKey ? aHandlerEntries[l].mHandler : NULL; + return aHandlerEntries[l].mKey == aKey ? aHandlerEntries[l].mHandler : nullptr; } } // namespace Ncp diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index d932488c9..2e6262212 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -334,7 +334,7 @@ template <> otError NcpBase::HandlePropertyGet(void) template <> otError NcpBase::HandlePropertySet(void) { - const uint8_t *ptr = NULL; + const uint8_t *ptr = nullptr; uint16_t len; otError error = OT_ERROR_NONE; @@ -526,7 +526,7 @@ template <> otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertyInsert otError NcpBase::HandlePropertyRemove otError NcpBase::HandlePropertyInsert(void) { otError error = OT_ERROR_NONE; - const otExtAddress *eui64 = NULL; - const char * pskd = NULL; + const otExtAddress *eui64 = nullptr; + const char * pskd = nullptr; uint32_t joinerTimeout = 0; SuccessOrExit(error = mDecoder.ReadUtf8(pskd)); @@ -828,7 +828,7 @@ template <> otError NcpBase::HandlePropertyInsert(vo if (mDecoder.ReadEui64(eui64) != OT_ERROR_NONE) { - eui64 = NULL; + eui64 = nullptr; } error = otCommissionerAddJoiner(mInstance, eui64, pskd, joinerTimeout); diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index ebf20aa37..7ffe78e8e 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -366,7 +366,7 @@ template <> otError NcpBase::HandlePropertyGet(voi template <> otError NcpBase::HandlePropertySet(void) { - const char *string = NULL; + const char *string = nullptr; otError error = OT_ERROR_NONE; SuccessOrExit(mDecoder.ReadUtf8(string)); @@ -384,7 +384,7 @@ template <> otError NcpBase::HandlePropertyGet(void) template <> otError NcpBase::HandlePropertySet(void) { - const uint8_t *ptr = NULL; + const uint8_t *ptr = nullptr; uint16_t len; otError error = OT_ERROR_NONE; @@ -405,7 +405,7 @@ template <> otError NcpBase::HandlePropertyGet(void) template <> otError NcpBase::HandlePropertySet(void) { - const uint8_t *ptr = NULL; + const uint8_t *ptr = nullptr; uint16_t len; otError error = OT_ERROR_NONE; @@ -1114,19 +1114,19 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, memset(&aDataset, 0, sizeof(otOperationalDataset)); - if (aTlvs != NULL) + if (aTlvs != nullptr) { - *aTlvs = NULL; + *aTlvs = nullptr; } - if (aTlvsLength != NULL) + if (aTlvsLength != nullptr) { *aTlvsLength = 0; } - if (aDestIpAddress != NULL) + if (aDestIpAddress != nullptr) { - *aDestIpAddress = NULL; + *aDestIpAddress = nullptr; } while (!mDecoder.IsAllReadInStruct()) @@ -1308,12 +1308,12 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, SuccessOrExit(error = mDecoder.ReadData(tlvs, len)); VerifyOrExit(len <= 255, error = OT_ERROR_INVALID_ARGS); - if (aTlvs != NULL) + if (aTlvs != nullptr) { *aTlvs = tlvs; } - if (aTlvsLength != NULL) + if (aTlvsLength != nullptr) { *aTlvsLength = static_cast(len); } @@ -1329,7 +1329,7 @@ otError NcpBase::DecodeOperationalDataset(otOperationalDataset &aDataset, SuccessOrExit(error = mDecoder.ReadIp6Address(addr)); - if (aDestIpAddress != NULL) + if (aDestIpAddress != nullptr) { *aDestIpAddress = addr; } @@ -1463,12 +1463,12 @@ template <> otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertyGet(void) const otMeshLocalPrefix *mlPrefix = otThreadGetMeshLocalPrefix(mInstance); otIp6Address addr; - VerifyOrExit(mlPrefix != NULL, OT_NOOP); // If `mlPrefix` is NULL send empty response. + VerifyOrExit(mlPrefix != nullptr, OT_NOOP); // If `mlPrefix` is nullptr send empty response. memcpy(addr.mFields.m8, mlPrefix->m8, 8); @@ -1575,7 +1575,7 @@ template <> otError NcpBase::HandlePropertyGet(void) otError error = OT_ERROR_NONE; const otIp6Address *ml64 = otThreadGetMeshLocalEid(mInstance); - VerifyOrExit(ml64 != NULL, OT_NOOP); + VerifyOrExit(ml64 != nullptr, OT_NOOP); SuccessOrExit(error = mEncoder.WriteIp6Address(*ml64)); exit: @@ -1587,7 +1587,7 @@ template <> otError NcpBase::HandlePropertyGet(void) otError error = OT_ERROR_NONE; const otIp6Address *address = otThreadGetLinkLocalIp6Address(mInstance); - VerifyOrExit(address != NULL, OT_NOOP); + VerifyOrExit(address != nullptr, OT_NOOP); SuccessOrExit(error = mEncoder.WriteIp6Address(*address)); exit: @@ -1931,11 +1931,11 @@ exit: template <> otError NcpBase::HandlePropertySet(void) { - const uint8_t *framePtr = NULL; + const uint8_t *framePtr = nullptr; uint16_t frameLen = 0; - const uint8_t *metaPtr = NULL; + const uint8_t *metaPtr = nullptr; uint16_t metaLen = 0; - otMessage * message = NULL; + otMessage * message = nullptr; otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadDataWithLen(framePtr, frameLen)); @@ -1945,8 +1945,8 @@ template <> otError NcpBase::HandlePropertySet(void) // May later include TX power, allow retransmits, etc... // STREAM_NET requires layer 2 security. - message = otIp6NewMessageFromBuffer(mInstance, framePtr, frameLen, NULL); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + message = otIp6NewMessageFromBuffer(mInstance, framePtr, frameLen, nullptr); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); error = otIp6Send(mInstance, message); @@ -2461,7 +2461,7 @@ template <> otError NcpBase::HandlePropertyGet(vo otError error = OT_ERROR_NONE; const otMleCounters *counters = otThreadGetMleCounters(mInstance); - OT_ASSERT(counters != NULL); + OT_ASSERT(counters != nullptr); SuccessOrExit(error = mEncoder.WriteUint16(counters->mDisabledRole)); SuccessOrExit(error = mEncoder.WriteUint16(counters->mDetachedRole)); @@ -2489,7 +2489,7 @@ template <> otError NcpBase::HandlePropertyGet otError error = OT_ERROR_NONE; const otIpCounters *counters = otThreadGetIp6Counters(mInstance); - OT_ASSERT(counters != NULL); + OT_ASSERT(counters != nullptr); // Encode Tx related counters SuccessOrExit(error = mEncoder.OpenStruct()); @@ -2519,8 +2519,8 @@ template <> otError NcpBase::HandlePropertyGet otError NcpBase::HandlePropertySet(void) while (mDecoder.GetRemainingLengthInStruct() > 0) { - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; int8_t rss; SuccessOrExit(error = mDecoder.OpenStruct()); @@ -2709,7 +2709,7 @@ template <> otError NcpBase::HandlePropertySet(void) while (mDecoder.GetRemainingLengthInStruct() > 0) { - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; SuccessOrExit(error = mDecoder.OpenStruct()); SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2778,7 +2778,7 @@ template <> otError NcpBase::HandlePropertySet(void) } else { - extAddress = NULL; + extAddress = nullptr; } SuccessOrExit(error = mDecoder.ReadInt8(rss)); @@ -2871,11 +2871,11 @@ template <> otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertySet(void) { - const uint8_t * framePtr = NULL; + const uint8_t * framePtr = nullptr; uint16_t frameLen = 0; - const uint8_t * metaPtr = NULL; + const uint8_t * metaPtr = nullptr; uint16_t metaLen = 0; - otMessage * message = NULL; + otMessage * message = nullptr; otError error = OT_ERROR_NONE; otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL}; @@ -2887,7 +2887,7 @@ template <> otError NcpBase::HandlePropertySet( // STREAM_NET_INSECURE packets are not secured at layer 2. message = otIp6NewMessageFromBuffer(mInstance, framePtr, frameLen, &msgSettings); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); // Ensure the insecure message is forwarded using direct transmission. otMessageSetDirectTransmission(message, true); @@ -2937,7 +2937,7 @@ exit: template <> otError NcpBase::HandlePropertyInsert(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2968,7 +2968,7 @@ exit: template <> otError NcpBase::HandlePropertyInsert(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -2986,7 +2986,7 @@ exit: template <> otError NcpBase::HandlePropertyInsert(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; int8_t rss = OT_MAC_FILTER_FIXED_RSS_DISABLED; if (mDecoder.GetRemainingLength() > sizeof(int8_t)) @@ -3028,7 +3028,7 @@ exit: template <> otError NcpBase::HandlePropertyRemove(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -3046,7 +3046,7 @@ exit: template <> otError NcpBase::HandlePropertyRemove(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -3064,7 +3064,7 @@ exit: template <> otError NcpBase::HandlePropertyRemove(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; if (mDecoder.GetRemainingLength() > 0) { @@ -3121,7 +3121,7 @@ void NcpBase::RegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers) mLegacyHandlers = aHandlers; bool isEnabled; - VerifyOrExit(mLegacyHandlers != NULL, OT_NOOP); + VerifyOrExit(mLegacyHandlers != nullptr, OT_NOOP); isEnabled = (otThreadGetDeviceRole(mInstance) != OT_DEVICE_ROLE_DISABLED); @@ -3171,7 +3171,7 @@ template <> otError NcpBase::HandlePropertyGet otError NcpBase::HandlePropertySet(void) { - const uint8_t *ptr = NULL; + const uint8_t *ptr = nullptr; uint16_t len; otError error = OT_ERROR_NONE; @@ -3182,7 +3182,7 @@ template <> otError NcpBase::HandlePropertySetmSetLegacyUlaPrefix != NULL)) + if ((mLegacyHandlers != nullptr) && (mLegacyHandlers->mSetLegacyUlaPrefix != nullptr)) { mLegacyHandlers->mSetLegacyUlaPrefix(mLegacyUlaPrefix); } @@ -3205,7 +3205,7 @@ void NcpBase::StartLegacy(void) { mLegacyNodeDidJoin = false; - if ((mLegacyHandlers != NULL) && (mLegacyHandlers->mStartLegacy != NULL)) + if ((mLegacyHandlers != nullptr) && (mLegacyHandlers->mStartLegacy != nullptr)) { mLegacyHandlers->mStartLegacy(); } @@ -3215,7 +3215,7 @@ void NcpBase::StopLegacy(void) { mLegacyNodeDidJoin = false; - if ((mLegacyHandlers != NULL) && (mLegacyHandlers->mStopLegacy != NULL)) + if ((mLegacyHandlers != nullptr) && (mLegacyHandlers->mStopLegacy != nullptr)) { mLegacyHandlers->mStopLegacy(); } @@ -3396,7 +3396,7 @@ void NcpBase::HandleDatagramFromStack(otMessage *aMessage, void *aContext) void NcpBase::HandleDatagramFromStack(otMessage *aMessage) { - VerifyOrExit(aMessage != NULL, OT_NOOP); + VerifyOrExit(aMessage != nullptr, OT_NOOP); // Do not forward frames larger than SPINEL payload size. VerifyOrExit(otMessageGetLength(aMessage) <= SPINEL_FRAME_MAX_COMMAND_PAYLOAD_SIZE, otMessageFree(aMessage)); @@ -3452,7 +3452,7 @@ otError NcpBase::SendQueuedDatagramMessages(void) otError error = OT_ERROR_NONE; otMessage *message; - while ((message = otMessageQueueGetHead(&mMessageQueue)) != NULL) + while ((message = otMessageQueueGetHead(&mMessageQueue)) != nullptr) { // Since an `otMessage` instance can be in one queue at a time, // it is first dequeued from `mMessageQueue` before attempting @@ -3479,7 +3479,7 @@ exit: #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE template <> otError NcpBase::HandlePropertySet(void) { - const uint8_t * framePtr = NULL; + const uint8_t * framePtr = nullptr; uint16_t frameLen = 0; const otIp6Address *peerAddr; uint16_t peerPort; @@ -3489,7 +3489,7 @@ template <> otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertySet(voi } else { - otLinkSetPcapCallback(mInstance, NULL, NULL); + otLinkSetPcapCallback(mInstance, nullptr, nullptr); } exit: @@ -3764,7 +3764,7 @@ void otNcpRegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers) #if OPENTHREAD_CONFIG_LEGACY_ENABLE ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); - if (ncp != NULL) + if (ncp != nullptr) { ncp->RegisterLegacyHandlers(aHandlers); } @@ -3779,7 +3779,7 @@ void otNcpHandleDidReceiveNewLegacyUlaPrefix(const uint8_t *aUlaPrefix) #if OPENTHREAD_CONFIG_LEGACY_ENABLE ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); - if (ncp != NULL) + if (ncp != nullptr) { ncp->HandleDidReceiveNewLegacyUlaPrefix(aUlaPrefix); } @@ -3794,7 +3794,7 @@ void otNcpHandleLegacyNodeDidJoin(const otExtAddress *aExtAddr) #if OPENTHREAD_CONFIG_LEGACY_ENABLE ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); - if (ncp != NULL) + if (ncp != nullptr) { ncp->HandleLegacyNodeDidJoin(aExtAddr); } diff --git a/src/ncp/ncp_base_radio.cpp b/src/ncp/ncp_base_radio.cpp index a383d7f9e..0d23a697f 100644 --- a/src/ncp/ncp_base_radio.cpp +++ b/src/ncp/ncp_base_radio.cpp @@ -57,7 +57,7 @@ otError NcpBase::PackRadioFrame(otRadioFrame *aFrame, otError aError) otError error = OT_ERROR_FAILED; uint16_t flags = 0; - if (aFrame != NULL && aError == OT_ERROR_NONE) + if (aFrame != nullptr && aError == OT_ERROR_NONE) { // Append the frame contents SuccessOrExit(mEncoder.WriteDataWithLen(aFrame->mPsdu, aFrame->mLength)); @@ -72,7 +72,7 @@ otError NcpBase::PackRadioFrame(otRadioFrame *aFrame, otError aError) SuccessOrExit(mEncoder.WriteInt8(aFrame ? aFrame->mInfo.mRxInfo.mRssi : 0)); // RSSI SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused) - if (aFrame != NULL) + if (aFrame != nullptr) { if (aFrame->mInfo.mRxInfo.mAckedWithFramePending) { @@ -142,7 +142,7 @@ void NcpBase::LinkRawTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, if (mCurTransmitTID) { uint8_t header = SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0 | mCurTransmitTID; - bool framePending = (aAckFrame != NULL && static_cast(aAckFrame)->GetFramePending()); + bool framePending = (aAckFrame != nullptr && static_cast(aAckFrame)->GetFramePending()); // Clear cached transmit TID mCurTransmitTID = 0; @@ -329,7 +329,7 @@ exit: template <> otError NcpBase::HandlePropertyInsert(void) { otError error = OT_ERROR_NONE; - const otExtAddress *extAddress = NULL; + const otExtAddress *extAddress = nullptr; SuccessOrExit(error = mDecoder.ReadEui64(extAddress)); @@ -425,7 +425,7 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_STREAM_RAW(uint8_t aHeader) VerifyOrExit(otLinkRawIsEnabled(mInstance), error = OT_ERROR_INVALID_STATE); frame = otLinkRawGetTransmitBuffer(mInstance); - VerifyOrExit(frame != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(frame != nullptr, error = OT_ERROR_NO_BUFS); SuccessOrExit(error = DecodeStreamRawTxRequest(*frame)); diff --git a/src/ncp/ncp_spi.cpp b/src/ncp/ncp_spi.cpp index 3424bc333..286b18fb4 100644 --- a/src/ncp/ncp_spi.cpp +++ b/src/ncp/ncp_spi.cpp @@ -64,12 +64,12 @@ static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpSpi), uint64_t); extern "C" void otNcpInit(otInstance *aInstance) { - NcpSpi * ncpSpi = NULL; + NcpSpi * ncpSpi = nullptr; Instance *instance = static_cast(aInstance); ncpSpi = new (&sNcpRaw) NcpSpi(instance); - if (ncpSpi == NULL || ncpSpi != NcpBase::GetNcpInstance()) + if (ncpSpi == nullptr || ncpSpi != NcpBase::GetNcpInstance()) { OT_ASSERT(false); } @@ -287,7 +287,7 @@ void NcpSpi::PrepareNextSpiSendFrame(void) // Prepare new transaction by using `mSendFrame` as the output // frame while keeping the input frame unchanged. - error = otPlatSpiSlavePrepareTransaction(mSendFrame, mSendFrameLength, NULL, 0, /* aRequestTrans */ true); + error = otPlatSpiSlavePrepareTransaction(mSendFrame, mSendFrameLength, nullptr, 0, /* aRequestTrans */ true); if (error == OT_ERROR_BUSY) { diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index 2c624588f..3ef967f98 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -68,12 +68,12 @@ static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpUart), uint64_t); extern "C" void otNcpInit(otInstance *aInstance) { - NcpUart * ncpUart = NULL; + NcpUart * ncpUart = nullptr; Instance *instance = static_cast(aInstance); ncpUart = new (&sNcpRaw) NcpUart(instance); - if (ncpUart == NULL || ncpUart != NcpBase::GetNcpInstance()) + if (ncpUart == nullptr || ncpUart != NcpBase::GetNcpInstance()) { OT_ASSERT(false); } @@ -217,7 +217,7 @@ extern "C" void otPlatUartSendDone(void) { NcpUart *ncpUart = static_cast(NcpBase::GetNcpInstance()); - if (ncpUart != NULL) + if (ncpUart != nullptr) { ncpUart->HandleUartSendDone(); } @@ -233,7 +233,7 @@ extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength) { NcpUart *ncpUart = static_cast(NcpBase::GetNcpInstance()); - if (ncpUart != NULL) + if (ncpUart != nullptr) { ncpUart->HandleUartReceiveDone(aBuf, aBufLength); } diff --git a/src/posix/client.cpp b/src/posix/client.cpp index 5da065cc2..8ac5da4a9 100644 --- a/src/posix/client.cpp +++ b/src/posix/client.cpp @@ -64,7 +64,7 @@ static int sSessionFd = -1; #if OPENTHREAD_USE_READLINE static void InputCallback(char *aLine) { - if (aLine != NULL) + if (aLine != nullptr) { add_history(aLine); dprintf(sSessionFd, "%s\n", aLine); @@ -259,7 +259,7 @@ int main(int argc, char *argv[]) } } - ret = select(maxFd + 1, &readFdSet, NULL, NULL, NULL); + ret = select(maxFd + 1, &readFdSet, nullptr, nullptr, nullptr); VerifyOrExit(ret != -1, perror("select"); ret = OT_EXIT_FAILURE); @@ -273,7 +273,7 @@ int main(int argc, char *argv[]) #if OPENTHREAD_USE_READLINE rl_callback_read_char(); #else - VerifyOrExit(fgets(buffer, sizeof(buffer), stdin) != NULL, ret = OT_EXIT_FAILURE); + VerifyOrExit(fgets(buffer, sizeof(buffer), stdin) != nullptr, ret = OT_EXIT_FAILURE); VerifyOrExit(DoWrite(sSessionFd, buffer, strlen(buffer)), ret = OT_EXIT_FAILURE); #endif diff --git a/src/posix/console_cli.cpp b/src/posix/console_cli.cpp index 9f7d54471..91a620fd8 100644 --- a/src/posix/console_cli.cpp +++ b/src/posix/console_cli.cpp @@ -64,7 +64,7 @@ static int sReadFd; static void InputCallback(char *aLine) { - if (aLine != NULL) + if (aLine != nullptr) { size_t len; @@ -95,7 +95,7 @@ void otxConsoleInit(otInstance *aInstance) rl_inhibit_completion = true; sReadFd = fileno(rl_instream); rl_callback_handler_install(sPrompt, InputCallback); - otCliConsoleInit(aInstance, OutputCallback, NULL); + otCliConsoleInit(aInstance, OutputCallback, nullptr); } void otxConsoleDeinit(void) diff --git a/src/posix/platform/alarm.cpp b/src/posix/platform/alarm.cpp index 838d38232..dd5d47e90 100644 --- a/src/posix/platform/alarm.cpp +++ b/src/posix/platform/alarm.cpp @@ -122,7 +122,7 @@ void platformAlarmUpdateTimeout(struct timeval *aTimeout) int64_t remaining = INT32_MAX; uint64_t now = platformAlarmGetNow(); - assert(aTimeout != NULL); + assert(aTimeout != nullptr); if (sIsMsRunning) { diff --git a/src/posix/platform/entropy.cpp b/src/posix/platform/entropy.cpp index 4fad7c573..561f27971 100644 --- a/src/posix/platform/entropy.cpp +++ b/src/posix/platform/entropy.cpp @@ -58,7 +58,7 @@ void platformRandomInit(void) #if __SANITIZE_ADDRESS__ != 0 // Multiplying gNodeId assures that no two nodes gets the same seed within an hour. - sState = (uint32_t)time(NULL) + (3600 * gNodeId); + sState = (uint32_t)time(nullptr) + (3600 * gNodeId); #endif // __SANITIZE_ADDRESS__ } @@ -95,20 +95,20 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) #if __SANITIZE_ADDRESS__ == 0 - FILE * file = NULL; + FILE * file = nullptr; size_t readLength; VerifyOrExit(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS); file = fopen("/dev/urandom", "rb"); - VerifyOrExit(file != NULL, error = OT_ERROR_FAILED); + VerifyOrExit(file != nullptr, error = OT_ERROR_FAILED); readLength = fread(aOutput, 1, aOutputLength, file); VerifyOrExit(readLength == aOutputLength, error = OT_ERROR_FAILED); exit: - if (file != NULL) + if (file != nullptr) { fclose(file); } diff --git a/src/posix/platform/hdlc_interface.cpp b/src/posix/platform/hdlc_interface.cpp index c497a3746..4a3aa2a30 100644 --- a/src/posix/platform/hdlc_interface.cpp +++ b/src/posix/platform/hdlc_interface.cpp @@ -179,7 +179,7 @@ void HdlcInterface::Deinit(void) VerifyOrExit(mSockFd != -1, OT_NOOP); VerifyOrExit(0 == close(mSockFd), perror("close RCP")); - VerifyOrExit(-1 != wait(NULL) || errno == ECHILD, perror("wait RCP")); + VerifyOrExit(-1 != wait(nullptr) || errno == ECHILD, perror("wait RCP")); mSockFd = -1; @@ -295,7 +295,7 @@ otError HdlcInterface::WaitForFrame(uint64_t aTimeoutUs) FD_SET(mSockFd, &read_fds); FD_SET(mSockFd, &error_fds); - rval = select(mSockFd + 1, &read_fds, NULL, &error_fds, &timeout); + rval = select(mSockFd + 1, &read_fds, nullptr, &error_fds, &timeout); if (rval > 0) { @@ -364,7 +364,7 @@ otError HdlcInterface::WaitForWritable(void) FD_SET(mSockFd, &writeFds); FD_SET(mSockFd, &errorFds); - rval = select(mSockFd + 1, NULL, &writeFds, &errorFds, &timeout); + rval = select(mSockFd + 1, nullptr, &writeFds, &errorFds, &timeout); if (rval > 0) { @@ -434,7 +434,7 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments) tios.c_cflag = CS8 | HUPCL | CREAD | CLOCAL; - if ((value = aArguments.GetValue("uart-parity")) != NULL) + if ((value = aArguments.GetValue("uart-parity")) != nullptr) { if (strncmp(value, "odd", 3) == 0) { @@ -451,7 +451,7 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments) } } - if ((value = aArguments.GetValue("uart-stop")) != NULL) + if ((value = aArguments.GetValue("uart-stop")) != nullptr) { stopBit = atoi(value); } @@ -561,7 +561,7 @@ int HdlcInterface::OpenFile(const char *aFile, Arguments &aArguments) break; } - if (aArguments.GetValue("uart-flow-control") != NULL) + if (aArguments.GetValue("uart-flow-control") != nullptr) { tios.c_cflag |= CRTSCTS; } @@ -594,7 +594,7 @@ int HdlcInterface::ForkPty(const char *aCommand, const char *aArguments) cfmakeraw(&tios); tios.c_cflag = CS8 | HUPCL | CREAD | CLOCAL; - VerifyOrExit((pid = forkpty(&fd, NULL, &tios, NULL)) != -1, perror("forkpty()")); + VerifyOrExit((pid = forkpty(&fd, nullptr, &tios, nullptr)) != -1, perror("forkpty()")); } if (0 == pid) @@ -602,7 +602,7 @@ int HdlcInterface::ForkPty(const char *aCommand, const char *aArguments) const int kMaxCommand = 255; char cmd[kMaxCommand]; - if (aArguments == NULL) + if (aArguments == nullptr) { rval = snprintf(cmd, sizeof(cmd), "exec %s", aCommand); } @@ -615,7 +615,7 @@ int HdlcInterface::ForkPty(const char *aCommand, const char *aArguments) rval = -1); VerifyOrExit((rval = execl(SOCKET_UTILS_DEFAULT_SHELL, SOCKET_UTILS_DEFAULT_SHELL, "-c", cmd, - static_cast(NULL))) != -1, + static_cast(nullptr))) != -1, perror("execl(OT_RCP)")); } else diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 2b1372aef..b3942124b 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -206,7 +206,7 @@ struct in6_ifreq static otError destroyTunnel(void); #endif -static otInstance *sInstance = NULL; +static otInstance *sInstance = nullptr; static int sTunFd = -1; ///< Used to exchange IPv6 packets. static int sIpFd = -1; ///< Used to manage IPv6 stack on Thread interface. static int sNetlinkFd = -1; ///< Used to receive netlink events. @@ -256,7 +256,7 @@ static bool UnicastAddressIsSubscribed(otInstance *aInstance, const otNetifAddre { const otNetifAddress *address = otIp6GetUnicastAddresses(aInstance); - while (address != NULL) + while (address != nullptr) { if (memcmp(address->mAddress.mFields.m8, netAddr->mAddress.mFields.m8, sizeof(address->mAddress.mFields.m8)) == 0) @@ -513,7 +513,7 @@ exit: static void processTransmit(otInstance *aInstance) { - otMessage *message = NULL; + otMessage *message = nullptr; ssize_t rval; char packet[kMaxIp6Size]; otError error = OT_ERROR_NONE; @@ -524,8 +524,8 @@ static void processTransmit(otInstance *aInstance) rval = read(sTunFd, packet, sizeof(packet)); VerifyOrExit(rval > 0, error = OT_ERROR_FAILED); - message = otIp6NewMessage(aInstance, NULL); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + message = otIp6NewMessage(aInstance, nullptr); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); #if defined(__APPLE__) || defined(__NetBSD__) || defined(__FreeBSD__) // BSD tunnel drivers have (for legacy reasons), may have a 4-byte header on them @@ -544,10 +544,10 @@ static void processTransmit(otInstance *aInstance) SuccessOrExit(error = otMessageAppend(message, &packet[offset], static_cast(rval))); error = otIp6Send(aInstance, message); - message = NULL; + message = nullptr; exit: - if (message != NULL) + if (message != nullptr) { otMessageFree(message); } @@ -1084,7 +1084,7 @@ static void processMLDEvent(otInstance *aInstance) MLDv2Header * hdr = reinterpret_cast(buffer); size_t offset; uint8_t type; - struct ifaddrs * ifAddrs = NULL; + struct ifaddrs * ifAddrs = nullptr; char addressString[INET6_ADDRSTRLEN + 1]; bufferLen = recvfrom(sMLDMonitorFd, buffer, sizeof(buffer), 0, reinterpret_cast(&srcAddr), &addrLen); @@ -1095,9 +1095,9 @@ static void processMLDEvent(otInstance *aInstance) // Check whether it is sent by self VerifyOrExit(getifaddrs(&ifAddrs) == 0, OT_NOOP); - for (struct ifaddrs *ifAddr = ifAddrs; ifAddr != NULL; ifAddr = ifAddr->ifa_next) + for (struct ifaddrs *ifAddr = ifAddrs; ifAddr != nullptr; ifAddr = ifAddr->ifa_next) { - if (ifAddr->ifa_addr != NULL && ifAddr->ifa_addr->sa_family == AF_INET6 && + if (ifAddr->ifa_addr != nullptr && ifAddr->ifa_addr->sa_family == AF_INET6 && strncmp(sTunName, ifAddr->ifa_name, IFNAMSIZ) == 0) { struct sockaddr_in6 *addr6 = reinterpret_cast(ifAddr->ifa_addr); @@ -1293,7 +1293,7 @@ static void platformConfigureTunDevice(otInstance *aInstance, VerifyOrDie(err == 0, OT_EXIT_ERROR_ERRNO); last_slash = strrchr(OPENTHREAD_POSIX_TUN_DEVICE, '/'); - VerifyOrDie(last_slash != NULL, OT_EXIT_ERROR_ERRNO); + VerifyOrDie(last_slash != nullptr, OT_EXIT_ERROR_ERRNO); last_slash++; strncpy(deviceName, last_slash, deviceNameLen); diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp index 50786af5e..14ca3a22a 100644 --- a/src/posix/platform/radio.cpp +++ b/src/posix/platform/radio.cpp @@ -97,25 +97,25 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) void platformRadioInit(otPosixRadioArguments *aArguments) { ot::Posix::Arguments *args = reinterpret_cast(aArguments); - bool resetRadio = (args->GetValue("no-reset") == NULL); - bool restoreDataset = (args->GetValue("ncp-dataset") != NULL); + bool resetRadio = (args->GetValue("no-reset") == nullptr); + bool restoreDataset = (args->GetValue("ncp-dataset") != nullptr); #if OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE uint8_t channel = ot::Radio::kChannelMin; int8_t power = ot::Posix::MaxPowerTable::kPowerDefault; const char *maxPowerTable = args->GetValue("max-power-table"); - if (maxPowerTable != NULL) + if (maxPowerTable != nullptr) { - const char *str = NULL; + const char *str = nullptr; - for (str = strtok(const_cast(maxPowerTable), ","); str != NULL && channel <= ot::Radio::kChannelMax; - str = strtok(NULL, ",")) + for (str = strtok(const_cast(maxPowerTable), ","); str != nullptr && channel <= ot::Radio::kChannelMax; + str = strtok(nullptr, ",")) { - power = static_cast(strtol(str, NULL, 0)); + power = static_cast(strtol(str, nullptr, 0)); sMaxPowerTable.SetTransmitPower(channel++, power); } - VerifyOrDie(str == NULL, OT_EXIT_INVALID_ARGUMENTS); + VerifyOrDie(str == nullptr, OT_EXIT_INVALID_ARGUMENTS); } // Use the last power if omitted. @@ -333,7 +333,7 @@ otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint1 otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) { OT_UNUSED_VARIABLE(aInstance); - assert(aPower != NULL); + assert(aPower != nullptr); return sRadioSpinel.GetTransmitPower(*aPower); } @@ -346,7 +346,7 @@ otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t *aThreshold) { OT_UNUSED_VARIABLE(aInstance); - assert(aThreshold != NULL); + assert(aThreshold != nullptr); return sRadioSpinel.GetCcaEnergyDetectThreshold(*aThreshold); } @@ -381,7 +381,7 @@ otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCo otError error = OT_ERROR_NONE; - VerifyOrExit(aCoexMetrics != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aCoexMetrics != nullptr, error = OT_ERROR_INVALID_ARGS); error = sRadioSpinel.GetCoexMetrics(*aCoexMetrics); @@ -413,7 +413,7 @@ otError otPlatDiagProcess(otInstance *aInstance, void otPlatDiagModeSet(bool aMode) { - SuccessOrExit(sRadioSpinel.PlatDiagProcess(aMode ? "start" : "stop", NULL, 0)); + SuccessOrExit(sRadioSpinel.PlatDiagProcess(aMode ? "start" : "stop", nullptr, 0)); sRadioSpinel.SetDiagEnabled(aMode); exit: @@ -430,7 +430,7 @@ void otPlatDiagTxPowerSet(int8_t aTxPower) char cmd[OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE]; snprintf(cmd, sizeof(cmd), "power %d", aTxPower); - SuccessOrExit(sRadioSpinel.PlatDiagProcess(cmd, NULL, 0)); + SuccessOrExit(sRadioSpinel.PlatDiagProcess(cmd, nullptr, 0)); exit: return; @@ -441,7 +441,7 @@ void otPlatDiagChannelSet(uint8_t aChannel) char cmd[OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE]; snprintf(cmd, sizeof(cmd), "channel %d", aChannel); - SuccessOrExit(sRadioSpinel.PlatDiagProcess(cmd, NULL, 0)); + SuccessOrExit(sRadioSpinel.PlatDiagProcess(cmd, nullptr, 0)); exit: return; diff --git a/src/posix/platform/radio_url.cpp b/src/posix/platform/radio_url.cpp index ac566525b..f73ed7697 100644 --- a/src/posix/platform/radio_url.cpp +++ b/src/posix/platform/radio_url.cpp @@ -100,28 +100,28 @@ Arguments::Arguments(const char *aUrl) { char *url = &mUrl[0]; - mPath = NULL; - mStart = NULL; - mEnd = NULL; + mPath = nullptr; + mStart = nullptr; + mEnd = nullptr; - VerifyOrExit(aUrl != NULL, OT_NOOP); + VerifyOrExit(aUrl != nullptr, OT_NOOP); VerifyOrExit(strnlen(aUrl, sizeof(mUrl)) < sizeof(mUrl), OT_NOOP); strncpy(mUrl, aUrl, sizeof(mUrl) - 1); url = strstr(url, "://"); - VerifyOrExit(url != NULL, OT_NOOP); + VerifyOrExit(url != nullptr, OT_NOOP); url += sizeof("://") - 1; mPath = url; mStart = strstr(url, "?"); - if (mStart != NULL) + if (mStart != nullptr) { mStart[0] = '\0'; mStart++; mEnd = mStart + strlen(mStart); - for (char *cur = strtok(mStart, "&"); cur != NULL; cur = strtok(NULL, "&")) + for (char *cur = strtok(mStart, "&"); cur != nullptr; cur = strtok(nullptr, "&")) ; } else @@ -135,13 +135,13 @@ exit: const char *Arguments::GetValue(const char *aName, const char *aLastValue) { - const char * rval = NULL; + const char * rval = nullptr; const size_t len = strlen(aName); - char * start = (aLastValue == NULL ? mStart : (const_cast(aLastValue) + strlen(aLastValue) + 1)); + char * start = (aLastValue == nullptr ? mStart : (const_cast(aLastValue) + strlen(aLastValue) + 1)); while (start < mEnd) { - char *last = NULL; + char *last = nullptr; if (!strncmp(aName, start, len)) { @@ -208,7 +208,7 @@ void TestMultipleProtocolsAndDuplicateParameters() { char url[] = "spinel+exec:///path/to/ot-rcp?arg=1&arg=arg2&arg=3"; ot::Posix::Arguments args(url); - const char * arg = NULL; + const char * arg = nullptr; assert(!strcmp(args.GetPath(), "/path/to/ot-rcp")); diff --git a/src/posix/platform/radio_url.hpp b/src/posix/platform/radio_url.hpp index f9c0aa08a..10f07768d 100644 --- a/src/posix/platform/radio_url.hpp +++ b/src/posix/platform/radio_url.hpp @@ -59,12 +59,12 @@ public: * This method returns the url agument value. * * @param[in] aName Argument name. - * @param[in] aLastValue The last iterated argument value, NULL for first value. + * @param[in] aLastValue The last iterated argument value, nullptr for first value. * * @returns The argument value. * */ - const char *GetValue(const char *aName, const char *aLastValue = NULL); + const char *GetValue(const char *aName, const char *aLastValue = nullptr); private: enum diff --git a/src/posix/platform/settings.cpp b/src/posix/platform/settings.cpp index b316a666d..ec6aa7984 100644 --- a/src/posix/platform/settings.cpp +++ b/src/posix/platform/settings.cpp @@ -65,7 +65,7 @@ static void getSettingsFileName(otInstance *aInstance, char aFileName[kMaxFileNa otPlatRadioGetIeeeEui64(aInstance, reinterpret_cast(&nodeId)); nodeId = ot::Encoding::BigEndian::HostSwap64(nodeId); snprintf(aFileName, kMaxFileNameSize, OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH "/%s_%" PRIx64 ".%s", - offset == NULL ? "0" : offset, nodeId, (aSwap ? "swap" : "data")); + offset == nullptr ? "0" : offset, nodeId, (aSwap ? "swap" : "data")); } static int swapOpen(otInstance *aInstance) @@ -293,7 +293,7 @@ otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *a otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) { - return platformSettingsDelete(aInstance, aKey, aIndex, NULL); + return platformSettingsDelete(aInstance, aKey, aIndex, nullptr); } /** @@ -374,7 +374,7 @@ static otError platformSettingsDelete(otInstance *aInstance, uint16_t aKey, int exit: VerifyOrDie(error != OT_ERROR_PARSE, OT_EXIT_FAILURE); - if (aSwapFd != NULL) + if (aSwapFd != nullptr) { *aSwapFd = swapFd; } @@ -411,7 +411,7 @@ void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64) int main() { - otInstance *instance = NULL; + otInstance *instance = nullptr; uint8_t data[60]; for (uint8_t i = 0; i < sizeof(data); ++i) @@ -438,8 +438,8 @@ int main() uint8_t value[sizeof(data)]; uint16_t length = sizeof(value); - assert(otPlatSettingsGet(instance, 0, 0, NULL, NULL) == OT_ERROR_NONE); - assert(otPlatSettingsGet(instance, 0, 0, NULL, &length) == OT_ERROR_NONE); + assert(otPlatSettingsGet(instance, 0, 0, nullptr, nullptr) == OT_ERROR_NONE); + assert(otPlatSettingsGet(instance, 0, 0, nullptr, &length) == OT_ERROR_NONE); assert(length == sizeof(data) / 2); length = sizeof(value); @@ -457,9 +457,9 @@ int main() assert(value[length] == 0); // wrong index - assert(otPlatSettingsGet(instance, 0, 1, NULL, NULL) == OT_ERROR_NOT_FOUND); + assert(otPlatSettingsGet(instance, 0, 1, nullptr, nullptr) == OT_ERROR_NOT_FOUND); // wrong key - assert(otPlatSettingsGet(instance, 1, 0, NULL, NULL) == OT_ERROR_NOT_FOUND); + assert(otPlatSettingsGet(instance, 1, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND); } otPlatSettingsWipe(instance); @@ -522,7 +522,7 @@ int main() // delete all records assert(otPlatSettingsDelete(instance, 0, -1) == OT_ERROR_NONE); - assert(otPlatSettingsGet(instance, 0, 0, NULL, NULL) == OT_ERROR_NOT_FOUND); + assert(otPlatSettingsGet(instance, 0, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND); } otPlatSettingsWipe(instance); @@ -541,7 +541,7 @@ int main() assert(0 == memcmp(value, data, length)); assert(otPlatSettingsDelete(instance, 0, 0) == OT_ERROR_NOT_FOUND); - assert(otPlatSettingsGet(instance, 0, 0, NULL, NULL) == OT_ERROR_NOT_FOUND); + assert(otPlatSettingsGet(instance, 0, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND); } otPlatSettingsWipe(instance); otPlatSettingsDeinit(instance); diff --git a/src/posix/platform/spi_interface.cpp b/src/posix/platform/spi_interface.cpp index 8e4ea191d..395db018a 100644 --- a/src/posix/platform/spi_interface.cpp +++ b/src/posix/platform/spi_interface.cpp @@ -159,7 +159,7 @@ otError SpiInterface::Init(Arguments &aArguments) mSpiSmallPacketSize = spiSmallPacketSize; mSpiAlignAllowance = spiAlignAllowance; - if (spiGpioIntDevice != NULL) + if (spiGpioIntDevice != nullptr) { // If the interrupt pin is not set, SPI interface will use polling mode. InitIntPin(spiGpioIntDevice, spiGpioIntLine); @@ -270,7 +270,7 @@ void SpiInterface::InitResetPin(const char *aCharDev, uint8_t aLine) otLogDebgPlat("InitResetPin: charDev=%s, line=%" PRIu8, aCharDev, aLine); - VerifyOrDie((aCharDev != NULL) && (aLine < GPIOHANDLES_MAX), OT_EXIT_INVALID_ARGUMENTS); + VerifyOrDie((aCharDev != nullptr) && (aLine < GPIOHANDLES_MAX), OT_EXIT_INVALID_ARGUMENTS); VerifyOrDie((fd = open(aCharDev, O_RDWR)) != -1, OT_EXIT_ERROR_ERRNO); mResetGpioValueFd = SetupGpioHandle(fd, aLine, GPIOHANDLE_REQUEST_OUTPUT, label); @@ -284,7 +284,7 @@ void SpiInterface::InitIntPin(const char *aCharDev, uint8_t aLine) otLogDebgPlat("InitIntPin: charDev=%s, line=%" PRIu8, aCharDev, aLine); - VerifyOrDie((aCharDev != NULL) && (aLine < GPIOHANDLES_MAX), OT_EXIT_INVALID_ARGUMENTS); + VerifyOrDie((aCharDev != nullptr) && (aLine < GPIOHANDLES_MAX), OT_EXIT_INVALID_ARGUMENTS); VerifyOrDie((fd = open(aCharDev, O_RDWR)) != -1, OT_EXIT_ERROR_ERRNO); mIntGpioValueFd = SetupGpioEvent(fd, aLine, GPIOHANDLE_REQUEST_INPUT, GPIOEVENT_REQUEST_FALLING_EDGE, label); @@ -299,7 +299,7 @@ void SpiInterface::InitSpiDev(const char *aPath, uint8_t aMode, uint32_t aSpeed) otLogDebgPlat("InitSpiDev: path=%s, mode=%" PRIu8 ", speed=%" PRIu32, aPath, aMode, aSpeed); - VerifyOrDie((aPath != NULL) && (aMode <= kSpiModeMax), OT_EXIT_INVALID_ARGUMENTS); + VerifyOrDie((aPath != nullptr) && (aMode <= kSpiModeMax), OT_EXIT_INVALID_ARGUMENTS); VerifyOrDie((fd = open(aPath, O_RDWR | O_CLOEXEC)) != -1, OT_EXIT_ERROR_ERRNO); VerifyOrExit(ioctl(fd, SPI_IOC_WR_MODE, &aMode) != -1, LogError("ioctl(SPI_IOC_WR_MODE)")); VerifyOrExit(ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &aSpeed) != -1, LogError("ioctl(SPI_IOC_WR_MAX_SPEED_HZ)")); @@ -784,7 +784,7 @@ otError SpiInterface::WaitForFrame(uint64_t aTimeoutUs) timeout = spiTimeout; } - ret = select(mIntGpioValueFd + 1, &readFdSet, NULL, NULL, &timeout); + ret = select(mIntGpioValueFd + 1, &readFdSet, nullptr, nullptr, &timeout); if (ret > 0 && FD_ISSET(mIntGpioValueFd, &readFdSet)) { diff --git a/src/posix/platform/system.cpp b/src/posix/platform/system.cpp index 8bdc6b263..f314406a0 100644 --- a/src/posix/platform/system.cpp +++ b/src/posix/platform/system.cpp @@ -49,20 +49,20 @@ uint64_t gNodeId = 0; otInstance *otSysInit(otPlatformConfig *aPlatformConfig) { - otInstance * instance = NULL; + otInstance * instance = nullptr; ot::Posix::Arguments args(aPlatformConfig->mRadioUrl); #if OPENTHREAD_POSIX_VIRTUAL_TIME virtualTimeInit(static_cast(atoi(args.GetValue("forkpty-arg")))); #endif - VerifyOrDie(args.GetPath() != NULL, OT_EXIT_INVALID_ARGUMENTS); + VerifyOrDie(args.GetPath() != nullptr, OT_EXIT_INVALID_ARGUMENTS); platformAlarmInit(aPlatformConfig->mSpeedUpFactor); platformRadioInit(&args); platformRandomInit(); instance = otInstanceInitSingle(); - assert(instance != NULL); + assert(instance != nullptr); #if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE platformNetifInit(instance, aPlatformConfig->mInterfaceName); @@ -174,7 +174,7 @@ int otSysMainloopPoll(otSysMainloopContext *aMainloop) } rval = select(aMainloop->mMaxFd + 1, &aMainloop->mReadFdSet, &aMainloop->mWriteFdSet, - &aMainloop->mErrorFdSet, NULL); + &aMainloop->mErrorFdSet, nullptr); } } else diff --git a/src/posix/platform/uart.cpp b/src/posix/platform/uart.cpp index f21e00829..42f20dcfb 100644 --- a/src/posix/platform/uart.cpp +++ b/src/posix/platform/uart.cpp @@ -56,7 +56,7 @@ static int sSessionSocket = -1; #endif static bool sEnabled = false; -static const uint8_t *sWriteBuffer = NULL; +static const uint8_t *sWriteBuffer = nullptr; static uint16_t sWriteLength = 0; otError otPlatUartEnable(void) @@ -171,7 +171,7 @@ void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aE { VerifyOrExit(sEnabled, OT_NOOP); - if (aReadFdSet != NULL) + if (aReadFdSet != nullptr) { #if OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE int fd = (sSessionSocket == -1 ? sUartSocket : sSessionSocket); @@ -181,17 +181,17 @@ void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aE FD_SET(fd, aReadFdSet); - if (aErrorFdSet != NULL) + if (aErrorFdSet != nullptr) { FD_SET(fd, aErrorFdSet); } - if (aMaxFd != NULL && *aMaxFd < fd) + if (aMaxFd != nullptr && *aMaxFd < fd) { *aMaxFd = fd; } } - if ((aWriteFdSet != NULL) && (sWriteLength > 0)) + if ((aWriteFdSet != nullptr) && (sWriteLength > 0)) { #if OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE int fd = (sSessionSocket == -1 ? sUartSocket : sSessionSocket); @@ -201,12 +201,12 @@ void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aE FD_SET(fd, aWriteFdSet); - if (aErrorFdSet != NULL) + if (aErrorFdSet != nullptr) { FD_SET(fd, aErrorFdSet); } - if (aMaxFd != NULL && *aMaxFd < fd) + if (aMaxFd != nullptr && *aMaxFd < fd) { *aMaxFd = fd; } @@ -221,7 +221,7 @@ static void InitializeSessionSocket(void) { int rval; - VerifyOrExit((rval = accept(sUartSocket, NULL, NULL)) != -1, OT_NOOP); + VerifyOrExit((rval = accept(sUartSocket, nullptr, nullptr)) != -1, OT_NOOP); if (sSessionSocket != -1) { @@ -265,10 +265,10 @@ void platformUartProcess(const fd_set *aReadFdSet, const fd_set *aWriteFdSet, co InitializeSessionSocket(); } - if (sSessionSocket == -1 && sWriteBuffer != NULL) + if (sSessionSocket == -1 && sWriteBuffer != nullptr) { IgnoreReturnValue(write(STDERR_FILENO, sWriteBuffer, sWriteLength)); - sWriteBuffer = NULL; + sWriteBuffer = nullptr; sWriteLength = 0; otPlatUartSendDone(); } diff --git a/src/posix/platform/udp.cpp b/src/posix/platform/udp.cpp index 4c62a5de5..06bea026a 100644 --- a/src/posix/platform/udp.cpp +++ b/src/posix/platform/udp.cpp @@ -191,7 +191,7 @@ static otError receivePacket(int aFd, uint8_t *aPayload, uint16_t &aLength, otMe VerifyOrExit(rval > 0, perror("recvmsg")); aLength = static_cast(rval); - for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) + for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg)) { if (cmsg->cmsg_level == IPPROTO_IPV6) { @@ -226,7 +226,7 @@ otError otPlatUdpSocket(otUdpSocket *aUdpSocket) otError error = OT_ERROR_NONE; int fd; - assert(aUdpSocket->mHandle == NULL); + assert(aUdpSocket->mHandle == nullptr); fd = SocketWithCloseExec(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, kSocketNonBlock); VerifyOrExit(fd >= 0, error = OT_ERROR_FAILED); @@ -242,11 +242,11 @@ otError otPlatUdpClose(otUdpSocket *aUdpSocket) otError error = OT_ERROR_NONE; int fd; - VerifyOrExit(aUdpSocket->mHandle != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS); fd = FdFromHandle(aUdpSocket->mHandle); VerifyOrExit(0 == close(fd), error = OT_ERROR_FAILED); - aUdpSocket->mHandle = NULL; + aUdpSocket->mHandle = nullptr; exit: return error; @@ -258,9 +258,9 @@ otError otPlatUdpBind(otUdpSocket *aUdpSocket) int fd; assert(sPlatNetifIndex != 0); - assert(aUdpSocket->mHandle != NULL); + assert(aUdpSocket->mHandle != nullptr); VerifyOrExit(sPlatNetifIndex != 0, error = OT_ERROR_INVALID_STATE); - VerifyOrExit(aUdpSocket->mHandle != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aUdpSocket->mSockName.mPort != 0, error = OT_ERROR_INVALID_ARGS); fd = FdFromHandle(aUdpSocket->mHandle); @@ -300,7 +300,7 @@ otError otPlatUdpConnect(otUdpSocket *aUdpSocket) bool isDisconnect = memcmp(&aUdpSocket->mPeerName.mAddress, &in6addr_any, sizeof(in6addr_any)) == 0 && aUdpSocket->mPeerName.mPort == 0; - VerifyOrExit(aUdpSocket->mHandle != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS); fd = FdFromHandle(aUdpSocket->mHandle); @@ -349,7 +349,7 @@ otError otPlatUdpSend(otUdpSocket *aUdpSocket, otMessage *aMessage, const otMess otError error = OT_ERROR_NONE; int fd; - VerifyOrExit(aUdpSocket->mHandle != NULL, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS); fd = FdFromHandle(aUdpSocket->mHandle); { @@ -373,11 +373,11 @@ void platformUdpUpdateFdSet(otInstance *aInstance, fd_set *aReadFdSet, int *aMax { VerifyOrExit(sPlatNetifIndex != 0, OT_NOOP); - for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != NULL; socket = socket->mNext) + for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != nullptr; socket = socket->mNext) { int fd; - if (socket->mHandle == NULL) + if (socket->mHandle == nullptr) { continue; } @@ -385,7 +385,7 @@ void platformUdpUpdateFdSet(otInstance *aInstance, fd_set *aReadFdSet, int *aMax fd = FdFromHandle(socket->mHandle); FD_SET(fd, aReadFdSet); - if (aMaxFd != NULL && *aMaxFd < fd) + if (aMaxFd != nullptr && *aMaxFd < fd) { *aMaxFd = fd; } @@ -397,7 +397,7 @@ exit: void platformUdpInit(const char *aIfName) { - if (aIfName == NULL) + if (aIfName == nullptr) { DieNow(OT_EXIT_INVALID_ARGUMENTS); } @@ -416,14 +416,14 @@ void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet) VerifyOrExit(sPlatNetifIndex != 0, OT_NOOP); - for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != NULL; socket = socket->mNext) + for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != nullptr; socket = socket->mNext) { int fd = FdFromHandle(socket->mHandle); if (fd > 0 && FD_ISSET(fd, aReadFdSet)) { otMessageInfo messageInfo; - otMessage * message = NULL; + otMessage * message = nullptr; uint8_t payload[kMaxUdpSize]; uint16_t length = sizeof(payload); @@ -437,7 +437,7 @@ void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet) message = otUdpNewMessage(aInstance, &msgSettings); - if (message == NULL) + if (message == nullptr) { continue; } diff --git a/src/posix/platform/virtual_time.cpp b/src/posix/platform/virtual_time.cpp index 9a0fe7bb8..1e33e1fba 100644 --- a/src/posix/platform/virtual_time.cpp +++ b/src/posix/platform/virtual_time.cpp @@ -125,7 +125,7 @@ static void virtualTimeSendEvent(struct VirtualTimeEvent *aEvent, size_t aLength void virtualTimeReceiveEvent(struct VirtualTimeEvent *aEvent) { - ssize_t rval = recvfrom(sSockFd, aEvent, sizeof(*aEvent), 0, NULL, NULL); + ssize_t rval = recvfrom(sSockFd, aEvent, sizeof(*aEvent), 0, nullptr, nullptr); if (rval < 0 || (uint16_t)rval < offsetof(struct VirtualTimeEvent, mData)) { diff --git a/tests/fuzz/cli_uart_received.cpp b/tests/fuzz/cli_uart_received.cpp index f791a93c4..591caf841 100644 --- a/tests/fuzz/cli_uart_received.cpp +++ b/tests/fuzz/cli_uart_received.cpp @@ -47,8 +47,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const otPanId panId = 0xdead; - otInstance *instance = NULL; - uint8_t * buf = NULL; + otInstance *instance = nullptr; + uint8_t * buf = nullptr; VerifyOrExit(size <= 65536, OT_NOOP); @@ -81,12 +81,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) exit: - if (buf != NULL) + if (buf != nullptr) { free(buf); } - if (instance != NULL) + if (instance != nullptr) { otInstanceFinalize(instance); } diff --git a/tests/fuzz/fuzzer_platform.cpp b/tests/fuzz/fuzzer_platform.cpp index b21dfadbc..a2620446a 100644 --- a/tests/fuzz/fuzzer_platform.cpp +++ b/tests/fuzz/fuzzer_platform.cpp @@ -109,7 +109,7 @@ void FuzzerPlatformProcess(otInstance *aInstance) } else { - otPlatRadioTxDone(aInstance, &sRadioTransmitFrame, NULL, OT_ERROR_NONE); + otPlatRadioTxDone(aInstance, &sRadioTransmitFrame, nullptr, OT_ERROR_NONE); } } diff --git a/tests/fuzz/ip6_send.cpp b/tests/fuzz/ip6_send.cpp index b5f2b4a83..b11f03c3c 100644 --- a/tests/fuzz/ip6_send.cpp +++ b/tests/fuzz/ip6_send.cpp @@ -45,8 +45,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const otPanId panId = 0xdead; - otInstance * instance = NULL; - otMessage * message = NULL; + otInstance * instance = nullptr; + otMessage * message = nullptr; otError error = OT_ERROR_NONE; otMessageSettings settings; @@ -64,14 +64,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) settings.mPriority = OT_MESSAGE_PRIORITY_NORMAL; message = otIp6NewMessage(instance, &settings); - VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS); + VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS); error = otMessageAppend(message, data + 1, static_cast(size - 1)); SuccessOrExit(error); error = otIp6Send(instance, message); - message = NULL; + message = nullptr; VerifyOrExit(!FuzzerPlatformResetWasRequested(), OT_NOOP); @@ -87,12 +87,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) exit: - if (message != NULL) + if (message != nullptr) { otMessageFree(message); } - if (instance != NULL) + if (instance != nullptr) { otInstanceFinalize(instance); } diff --git a/tests/fuzz/ncp_uart_received.cpp b/tests/fuzz/ncp_uart_received.cpp index debb9219e..10f08ec3e 100644 --- a/tests/fuzz/ncp_uart_received.cpp +++ b/tests/fuzz/ncp_uart_received.cpp @@ -47,8 +47,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const otPanId panId = 0xdead; - otInstance *instance = NULL; - uint8_t * buf = NULL; + otInstance *instance = nullptr; + uint8_t * buf = nullptr; VerifyOrExit(size <= 65536, OT_NOOP); @@ -81,12 +81,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) exit: - if (buf != NULL) + if (buf != nullptr) { free(buf); } - if (instance != NULL) + if (instance != nullptr) { otInstanceFinalize(instance); } diff --git a/tests/fuzz/radio_receive_done.cpp b/tests/fuzz/radio_receive_done.cpp index 1a7feaf60..70aba45b5 100644 --- a/tests/fuzz/radio_receive_done.cpp +++ b/tests/fuzz/radio_receive_done.cpp @@ -46,9 +46,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const otPanId panId = 0xdead; - otInstance * instance = NULL; + otInstance * instance = nullptr; otRadioFrame frame; - uint8_t * buf = NULL; + uint8_t * buf = nullptr; VerifyOrExit(size <= OT_RADIO_FRAME_MAX_SIZE, OT_NOOP); @@ -85,12 +85,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) exit: - if (buf != NULL) + if (buf != nullptr) { free(buf); } - if (instance != NULL) + if (instance != nullptr) { otInstanceFinalize(instance); } diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index ee77cdbb6..03cc44c57 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -491,3 +491,9 @@ target_link_libraries(test-timer add_test(NAME test-timer COMMAND test-timer) +set_target_properties( + test-aes test-child test-child-table test-flash test-heap test-hmac-sha256 test-ip6-address test-link-quality test-linked-list test-lowpan test-mac-frame test-message test-message-queue test-netif test-network-data test-priority-queue test-pskc test-steering-data test-string test-timer + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 11 +) diff --git a/tests/unit/test_aes.cpp b/tests/unit/test_aes.cpp index d5633087e..362c96b09 100644 --- a/tests/unit/test_aes.cpp +++ b/tests/unit/test_aes.cpp @@ -65,7 +65,7 @@ void TestMacBeaconFrame(void) 0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x02, }; - VerifyOrQuit(instance != NULL, "Null OpenThread instance"); + VerifyOrQuit(instance != nullptr, "Null OpenThread instance"); aesCcm.SetKey(key, sizeof(key)); aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce)); diff --git a/tests/unit/test_child.cpp b/tests/unit/test_child.cpp index de5a15483..4fed9fa85 100644 --- a/tests/unit/test_child.cpp +++ b/tests/unit/test_child.cpp @@ -117,7 +117,7 @@ void TestChildIp6Address(void) const uint8_t meshLocalIid[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; sInstance = testInitInstance(); - VerifyOrQuit(sInstance != NULL, "Null instance"); + VerifyOrQuit(sInstance != nullptr, "Null instance"); child.Init(*sInstance); @@ -145,7 +145,7 @@ void TestChildIp6Address(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - printf("Child state after init"); child.Clear(); - VerifyChildIp6Addresses(child, 0, NULL); + VerifyChildIp6Addresses(child, 0, nullptr); printf(" -- PASS\n"); //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -157,7 +157,7 @@ void TestChildIp6Address(void) VerifyChildIp6Addresses(child, 1, &addresses[index]); child.ClearIp6Addresses(); - VerifyChildIp6Addresses(child, 0, NULL); + VerifyChildIp6Addresses(child, 0, nullptr); } printf(" -- PASS\n"); @@ -197,7 +197,7 @@ void TestChildIp6Address(void) "RemoveIp6Address() did not fail when removing an address not on the list"); } - VerifyChildIp6Addresses(child, 0, NULL); + VerifyChildIp6Addresses(child, 0, nullptr); printf(" -- PASS\n"); //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/unit/test_child_table.cpp b/tests/unit/test_child_table.cpp index 056362f91..00da31c2e 100644 --- a/tests/unit/test_child_table.cpp +++ b/tests/unit/test_child_table.cpp @@ -126,21 +126,21 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons } child = aTable.FindChild(aChildList[listIndex].mRloc16, filter); - VerifyOrQuit(child != NULL, "FindChild(rloc) failed"); + VerifyOrQuit(child != nullptr, "FindChild(rloc) failed"); VerifyOrQuit(ChildMatches(*child, aChildList[listIndex]), "FindChild(rloc) returned incorrect child"); child = aTable.FindChild(static_cast(aChildList[listIndex].mExtAddress), filter); - VerifyOrQuit(child != NULL, "FindChild(ExtAddress) failed"); + VerifyOrQuit(child != nullptr, "FindChild(ExtAddress) failed"); VerifyOrQuit(ChildMatches(*child, aChildList[listIndex]), "FindChild(ExtAddress) returned incorrect child"); address.SetShort(aChildList[listIndex].mRloc16); child = aTable.FindChild(address, filter); - VerifyOrQuit(child != NULL, "FindChild(address) failed"); + VerifyOrQuit(child != nullptr, "FindChild(address) failed"); VerifyOrQuit(ChildMatches(*child, aChildList[listIndex]), "FindChild(address) returned incorrect child"); address.SetExtended(static_cast(aChildList[listIndex].mExtAddress)); child = aTable.FindChild(address, filter); - VerifyOrQuit(child != NULL, "FindChild(address) failed"); + VerifyOrQuit(child != nullptr, "FindChild(address) failed"); VerifyOrQuit(ChildMatches(*child, aChildList[listIndex]), "FindChild(address) returned incorrect child"); } @@ -148,12 +148,12 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons for (uint16_t listIndex = 0; listIndex <= aChildListLength; listIndex++) { - Child *startingChild = NULL; + Child *startingChild = nullptr; if (listIndex < aChildListLength) { startingChild = aTable.FindChild(aChildList[listIndex].mRloc16, Child::kInStateAnyExceptInvalid); - VerifyOrQuit(startingChild != NULL, "FindChild() failed"); + VerifyOrQuit(startingChild != nullptr, "FindChild() failed"); } // Test an iterator starting from `startingChild`. @@ -167,10 +167,10 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons // Check if the first entry matches the `startingChild` - if ((startingChild != NULL) && StateMatchesFilter(startingChild->GetState(), filter)) + if ((startingChild != nullptr) && StateMatchesFilter(startingChild->GetState(), filter)) { VerifyOrQuit(!iter.IsDone(), "iterator IsDone() failed"); - VerifyOrQuit(iter.GetChild() != NULL, "iterator GetChild() failed"); + VerifyOrQuit(iter.GetChild() != nullptr, "iterator GetChild() failed"); VerifyOrQuit(iter.GetChild() == startingChild, "Iterator failed to start from the given child entry"); @@ -187,7 +187,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons bool didFind = false; uint16_t childIndex; - VerifyOrQuit(child != NULL, "iter.GetChild() failed"); + VerifyOrQuit(child != nullptr, "iter.GetChild() failed"); childIndex = aTable.GetChildIndex(*child); VerifyOrQuit(childIndex < aTable.GetMaxChildrenAllowed(), "Child Index is out of bound"); @@ -207,13 +207,13 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons VerifyOrQuit(didFind, "ChildTable::Iterator returned an entry not in the expected list"); } - // Verify that when iterator is done, it points to `NULL`. + // Verify that when iterator is done, it points to `nullptr`. - VerifyOrQuit(iter.GetChild() == NULL, "iterator GetChild() failed"); + VerifyOrQuit(iter.GetChild() == nullptr, "iterator GetChild() failed"); iter++; VerifyOrQuit(iter.IsDone(), "iterator Advance() (after iterator is done) failed"); - VerifyOrQuit(iter.GetChild() == NULL, "iterator GetChild() failed"); + VerifyOrQuit(iter.GetChild() == nullptr, "iterator GetChild() failed"); // Verify that the number of children matches the number of entries we get from iterator. @@ -304,7 +304,7 @@ void TestChildTable(void) otError error; sInstance = testInitInstance(); - VerifyOrQuit(sInstance != NULL, "Null instance"); + VerifyOrQuit(sInstance != nullptr, "Null instance"); table = &sInstance->Get(); @@ -337,7 +337,7 @@ void TestChildTable(void) Child *child; child = table->GetNewChild(); - VerifyOrQuit(child != NULL, "GetNewChild() failed"); + VerifyOrQuit(child != nullptr, "GetNewChild() failed"); child->SetState(testChildList[i].mState); child->SetRloc16(testChildList[i].mRloc16); @@ -359,7 +359,7 @@ void TestChildTable(void) Child *child; child = table->GetNewChild(); - VerifyOrQuit(child != NULL, "GetNewChild() failed"); + VerifyOrQuit(child != nullptr, "GetNewChild() failed"); child->SetState(testChildList[i - 1].mState); child->SetRloc16(testChildList[i - 1].mRloc16); @@ -389,11 +389,11 @@ void TestChildTable(void) { Child *child = table->GetNewChild(); - VerifyOrQuit(child != NULL, "GetNewChild() failed"); + VerifyOrQuit(child != nullptr, "GetNewChild() failed"); child->SetState(Child::kStateValid); } - VerifyOrQuit(table->GetNewChild() == NULL, "GetNewChild() did not fail when table was full"); + VerifyOrQuit(table->GetNewChild() == nullptr, "GetNewChild() did not fail when table was full"); printf(" -- PASS\n"); diff --git a/tests/unit/test_flash.cpp b/tests/unit/test_flash.cpp index b973e8ca9..92f8ccb43 100644 --- a/tests/unit/test_flash.cpp +++ b/tests/unit/test_flash.cpp @@ -57,7 +57,7 @@ void TestFlash(void) // No records in settings VerifyOrQuit(flash.Delete(0, 0) == OT_ERROR_NOT_FOUND, "Delete() failed"); - VerifyOrQuit(flash.Get(0, 0, NULL, NULL) == OT_ERROR_NOT_FOUND, "Get() failed"); + VerifyOrQuit(flash.Get(0, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND, "Get() failed"); // Multiple records with different keys @@ -85,7 +85,7 @@ void TestFlash(void) for (uint16_t key = 0; key < 16; key++) { VerifyOrQuit(flash.Delete(key, 0) == OT_ERROR_NOT_FOUND, "Delete() failed"); - VerifyOrQuit(flash.Get(key, 0, NULL, NULL) == OT_ERROR_NOT_FOUND, "Get() failed"); + VerifyOrQuit(flash.Get(key, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND, "Get() failed"); } // Multiple records with the same key @@ -112,7 +112,7 @@ void TestFlash(void) } VerifyOrQuit(flash.Delete(0, 0) == OT_ERROR_NOT_FOUND, "Delete() failed"); - VerifyOrQuit(flash.Get(0, 0, NULL, NULL) == OT_ERROR_NOT_FOUND, "Get() failed"); + VerifyOrQuit(flash.Get(0, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND, "Get() failed"); // Multiple records with the same key @@ -145,7 +145,7 @@ void TestFlash(void) } VerifyOrQuit(flash.Delete(0, 0) == OT_ERROR_NOT_FOUND, "Delete() failed"); - VerifyOrQuit(flash.Get(0, 0, NULL, NULL) == OT_ERROR_NOT_FOUND, "Get() failed"); + VerifyOrQuit(flash.Get(0, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND, "Get() failed"); // Wipe() @@ -161,7 +161,7 @@ void TestFlash(void) for (uint16_t key = 0; key < 16; key++) { VerifyOrQuit(flash.Delete(key, 0) == OT_ERROR_NOT_FOUND, "Delete() failed"); - VerifyOrQuit(flash.Get(key, 0, NULL, NULL) == OT_ERROR_NOT_FOUND, "Get() failed"); + VerifyOrQuit(flash.Get(key, 0, nullptr, nullptr) == OT_ERROR_NOT_FOUND, "Get() failed"); } // Test swap diff --git a/tests/unit/test_hdlc.cpp b/tests/unit/test_hdlc.cpp index df4121f4e..8db427a75 100644 --- a/tests/unit/test_hdlc.cpp +++ b/tests/unit/test_hdlc.cpp @@ -129,8 +129,8 @@ void TestHdlcFrameBuffer(void) void TestHdlcMultiFrameBuffer(void) { Hdlc::MultiFrameBuffer frameBuffer; - uint8_t * frame = NULL; - uint8_t * newFrame = NULL; + uint8_t * frame = nullptr; + uint8_t * newFrame = nullptr; uint16_t length; uint16_t newLength; @@ -209,7 +209,7 @@ void TestHdlcMultiFrameBuffer(void) "GetFrame() content is incorrect"); // Read the first saved frame and check the content - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sMottoText) - 1, "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sMottoText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -228,7 +228,7 @@ void TestHdlcMultiFrameBuffer(void) newLength = length; VerifyOrQuit(frameBuffer.GetNextSavedFrame(newFrame, newLength) == OT_ERROR_NOT_FOUND, "GetNextSavedFrame() incorrect behavior after all frames were read"); - VerifyOrQuit(newFrame == NULL, "GetNextSavedFrame() incorrect behavior after all frames were read"); + VerifyOrQuit(newFrame == nullptr, "GetNextSavedFrame() incorrect behavior after all frames were read"); VerifyOrQuit(frameBuffer.GetLength() == sizeof(sOpenThreadText) - 1, "GetLength() failed"); VerifyOrQuit(memcmp(frameBuffer.GetFrame(), sOpenThreadText, frameBuffer.GetLength()) == 0, @@ -242,7 +242,7 @@ void TestHdlcMultiFrameBuffer(void) VerifyOrQuit(memcmp(frame, sOpenThreadText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); // Re-read all the saved frames - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sMottoText) - 1, "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sMottoText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -278,13 +278,13 @@ void TestHdlcMultiFrameBuffer(void) frameBuffer.SaveFrame(); VerifyOrQuit(frameBuffer.HasSavedFrame(), "HasFrame() incorrect behavior after SaveFrame()"); - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(frameBuffer.HasSavedFrame(), "HasFrame() incorrect behavior after SaveFrame()"); frameBuffer.Clear(); - frame = NULL; + frame = nullptr; VerifyOrQuit(frameBuffer.GetNextSavedFrame(frame, length) == OT_ERROR_NOT_FOUND, "GetNextSavedFrame() incorrect behavior after Clear()"); @@ -306,7 +306,7 @@ void TestHdlcMultiFrameBuffer(void) frameBuffer.SaveFrame(); SuccessOrQuit(WriteToBuffer(sHexText, frameBuffer), "WriteByte() failed"); - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sHelloText) - 1, "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sHelloText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -324,7 +324,7 @@ void TestHdlcMultiFrameBuffer(void) SuccessOrQuit(WriteToBuffer(sHelloText, frameBuffer), "WriteByte() failed"); - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sHexText) - 1, "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sHexText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -353,7 +353,7 @@ void TestHdlcMultiFrameBuffer(void) "GetFrame() content is incorrect"); frameBuffer.SaveFrame(); - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sHelloText) - 1, "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sHelloText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -394,7 +394,7 @@ void TestHdlcMultiFrameBuffer(void) VerifyOrQuit(frameBuffer.HasSavedFrame(), "HasFrame() incorrect behavior after SaveFrame()"); VerifyOrQuit(frameBuffer.GetSkipLength() == 0, "GetSkipLength() incorrect behavior after SaveFrame()"); - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sMottoText) - 1, "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sMottoText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -417,28 +417,28 @@ void TestHdlcMultiFrameBuffer(void) // Verify behavior of `SetLength()` and `GetLength()` frameBuffer.Clear(); - VerifyOrQuit((frame = frameBuffer.GetFrame()) != NULL, "GetFrame() failed"); + VerifyOrQuit((frame = frameBuffer.GetFrame()) != nullptr, "GetFrame() failed"); memcpy(frame, sHelloText, sizeof(sHelloText)); VerifyOrQuit(frameBuffer.SetLength(sizeof(sHelloText)) == OT_ERROR_NONE, "SetLength() failed"); VerifyOrQuit(frameBuffer.GetLength() == sizeof(sHelloText), "GetLength() failed"); VerifyOrQuit(frameBuffer.HasFrame(), "HasFrame() is incorrect"); frameBuffer.SaveFrame(); - VerifyOrQuit((frame = frameBuffer.GetFrame()) != NULL, "GetFrame() failed"); + VerifyOrQuit((frame = frameBuffer.GetFrame()) != nullptr, "GetFrame() failed"); memcpy(frame, sMottoText, sizeof(sMottoText)); VerifyOrQuit(frameBuffer.SetLength(sizeof(sMottoText)) == OT_ERROR_NONE, "SetLength() failed"); VerifyOrQuit(frameBuffer.GetLength() == sizeof(sMottoText), "GetLength() failed"); VerifyOrQuit(frameBuffer.HasFrame(), "HasFrame() is incorrect"); frameBuffer.SaveFrame(); - VerifyOrQuit((frame = frameBuffer.GetFrame()) != NULL, "GetFrame() failed"); + VerifyOrQuit((frame = frameBuffer.GetFrame()) != nullptr, "GetFrame() failed"); memcpy(frame, sHexText, sizeof(sHexText)); VerifyOrQuit(frameBuffer.SetLength(sizeof(sHexText)) == OT_ERROR_NONE, "SetLength() failed"); VerifyOrQuit(frameBuffer.GetLength() == sizeof(sHexText), "GetLength() failed"); frameBuffer.DiscardFrame(); VerifyOrQuit(!frameBuffer.HasFrame(), "HasFrame() is incorrect"); - frame = NULL; + frame = nullptr; SuccessOrQuit(frameBuffer.GetNextSavedFrame(frame, length), "GetNextSavedFrame() failed unexpectedly"); VerifyOrQuit(length == sizeof(sHelloText), "GetNextSavedFrame() length is incorrect"); VerifyOrQuit(memcmp(frame, sHelloText, length) == 0, "GetNextSavedFrame() frame content is incorrect"); @@ -519,7 +519,7 @@ void TestEncoderDecoder(void) encoderBuffer.SaveFrame(); // Feed the encoded frames to decoder and save the content - for (frame = NULL; encoderBuffer.GetNextSavedFrame(frame, length) == OT_ERROR_NONE;) + for (frame = nullptr; encoderBuffer.GetNextSavedFrame(frame, length) == OT_ERROR_NONE;) { decoderContext.mWasCalled = false; @@ -532,7 +532,7 @@ void TestEncoderDecoder(void) } // Verify the decoded frames match the original frames - frame = NULL; + frame = nullptr; SuccessOrQuit(decoderBuffer.GetNextSavedFrame(frame, length), "Incorrect decoded frame"); VerifyOrQuit(length == sizeof(sOpenThreadText) - 1, "Decoded frame length does not match original frame"); VerifyOrQuit(memcmp(frame, sOpenThreadText, length) == 0, "Decoded frame content does not match original frame"); diff --git a/tests/unit/test_heap.cpp b/tests/unit/test_heap.cpp index f95a6b2fe..651d60a08 100644 --- a/tests/unit/test_heap.cpp +++ b/tests/unit/test_heap.cpp @@ -50,11 +50,11 @@ void TestAllocateSingle(void) { void *p = heap.CAlloc(1, 0); - VerifyOrQuit(p == NULL && totalSize == heap.GetFreeSize(), "TestAllocateSingle allocate 1 x 0 byte failed!"); + VerifyOrQuit(p == nullptr && totalSize == heap.GetFreeSize(), "TestAllocateSingle allocate 1 x 0 byte failed!"); heap.Free(p); p = heap.CAlloc(0, 1); - VerifyOrQuit(p == NULL && totalSize == heap.GetFreeSize(), "TestAllocateSingle allocate 0 x 1 byte failed!"); + VerifyOrQuit(p == nullptr && totalSize == heap.GetFreeSize(), "TestAllocateSingle allocate 0 x 1 byte failed!"); heap.Free(p); } @@ -62,7 +62,7 @@ void TestAllocateSingle(void) { printf("%s allocating %zu bytes...\n", __func__, size); void *p = heap.CAlloc(1, size); - VerifyOrQuit(p != NULL && !heap.IsClean() && heap.GetFreeSize() + size <= totalSize, "allocating failed!"); + VerifyOrQuit(p != nullptr && !heap.IsClean() && heap.GetFreeSize() + size <= totalSize, "allocating failed!"); memset(p, 0xff, size); heap.Free(p); VerifyOrQuit(heap.IsClean() && heap.GetFreeSize() == totalSize, "freeing failed!\n"); @@ -100,12 +100,12 @@ void TestAllocateRandomly(size_t aSizeLimit, unsigned int aSeed) last->mNext = static_cast(heap.CAlloc(1, size)); // No more memory for allocation. - if (last->mNext == NULL) + if (last->mNext == nullptr) { break; } - VerifyOrQuit(last->mNext->mNext == NULL, "TestAllocateRandomly memory not initialized to zero!"); + VerifyOrQuit(last->mNext->mNext == nullptr, "TestAllocateRandomly memory not initialized to zero!"); last = last->mNext; last->mSize = size; ++nnodes; diff --git a/tests/unit/test_hmac_sha256.cpp b/tests/unit/test_hmac_sha256.cpp index 35fcb58a5..056302862 100644 --- a/tests/unit/test_hmac_sha256.cpp +++ b/tests/unit/test_hmac_sha256.cpp @@ -51,8 +51,8 @@ void TestHmacSha256(void) }, }, { - NULL, - NULL, + nullptr, + nullptr, {}, }, }; @@ -64,9 +64,9 @@ void TestHmacSha256(void) ot::Crypto::HmacSha256 hmac; uint8_t hash[ot::Crypto::HmacSha256::kHashSize]; - VerifyOrQuit(instance != NULL, "Null OpenThread instance"); + VerifyOrQuit(instance != nullptr, "Null OpenThread instance"); - for (int i = 0; tests[i].key != NULL; i++) + for (int i = 0; tests[i].key != nullptr; i++) { hmac.Start(reinterpret_cast(tests[i].key), static_cast(strlen(tests[i].key))); hmac.Update(reinterpret_cast(tests[i].data), static_cast(strlen(tests[i].data))); diff --git a/tests/unit/test_link_quality.cpp b/tests/unit/test_link_quality.cpp index 0f93e78f8..c6bf83be3 100644 --- a/tests/unit/test_link_quality.cpp +++ b/tests/unit/test_link_quality.cpp @@ -92,7 +92,7 @@ void TestLinkQualityData(RssTestData aRssData) size_t i; sInstance = testInitInstance(); - VerifyOrQuit(sInstance != NULL, "Null instance"); + VerifyOrQuit(sInstance != nullptr, "Null instance"); linkInfo.Init(*sInstance); printf("- - - - - - - - - - - - - - - - - -\n"); diff --git a/tests/unit/test_linked_list.cpp b/tests/unit/test_linked_list.cpp index 5fc51f368..36e692867 100644 --- a/tests/unit/test_linked_list.cpp +++ b/tests/unit/test_linked_list.cpp @@ -52,7 +52,7 @@ void VerifyLinkedListContent(const ot::LinkedList *aList, ...) { va_list args; Entry * argEntry; - Entry * argPrev = NULL; + Entry * argPrev = nullptr; va_start(args, aList); @@ -61,7 +61,7 @@ void VerifyLinkedListContent(const ot::LinkedList *aList, ...) Entry *prev; argEntry = va_arg(args, Entry *); - VerifyOrQuit(argEntry != NULL, "List contains more entries than expected"); + VerifyOrQuit(argEntry != nullptr, "List contains more entries than expected"); VerifyOrQuit(argEntry == entry, "List does not contain the same entry"); VerifyOrQuit(aList->Contains(*argEntry), "List::Contains() failed"); @@ -72,7 +72,7 @@ void VerifyLinkedListContent(const ot::LinkedList *aList, ...) } argEntry = va_arg(args, Entry *); - VerifyOrQuit(argEntry == NULL, "List contains less entries than expected"); + VerifyOrQuit(argEntry == nullptr, "List contains less entries than expected"); VerifyOrQuit(aList->GetTail() == argPrev, "List::GetTail() failed"); } @@ -83,26 +83,26 @@ void TestLinkedList(void) ot::LinkedList list; VerifyOrQuit(list.IsEmpty(), "LinkedList::IsEmpty() failed after init"); - VerifyOrQuit(list.GetHead() == NULL, "LinkedList::GetHead() failed after init"); - VerifyOrQuit(list.Pop() == NULL, "LinkedList::Pop() failed when empty"); + VerifyOrQuit(list.GetHead() == nullptr, "LinkedList::GetHead() failed after init"); + VerifyOrQuit(list.Pop() == nullptr, "LinkedList::Pop() failed when empty"); - VerifyLinkedListContent(&list, NULL); + VerifyLinkedListContent(&list, nullptr); list.Push(a); VerifyOrQuit(!list.IsEmpty(), "LinkedList::IsEmpty() failed"); - VerifyLinkedListContent(&list, &a, NULL); + VerifyLinkedListContent(&list, &a, nullptr); SuccessOrQuit(list.Add(b), "LinkedList::Add() failed"); - VerifyLinkedListContent(&list, &b, &a, NULL); + VerifyLinkedListContent(&list, &b, &a, nullptr); list.Push(c); - VerifyLinkedListContent(&list, &c, &b, &a, NULL); + VerifyLinkedListContent(&list, &c, &b, &a, nullptr); SuccessOrQuit(list.Add(d), "LinkedList::Add() failed"); - VerifyLinkedListContent(&list, &d, &c, &b, &a, NULL); + VerifyLinkedListContent(&list, &d, &c, &b, &a, nullptr); SuccessOrQuit(list.Add(e), "LinkedList::Add() failed"); - VerifyLinkedListContent(&list, &e, &d, &c, &b, &a, NULL); + VerifyLinkedListContent(&list, &e, &d, &c, &b, &a, nullptr); VerifyOrQuit(list.Add(a) == OT_ERROR_ALREADY, "LinkedList::Add() did not detect duplicate"); VerifyOrQuit(list.Add(b) == OT_ERROR_ALREADY, "LinkedList::Add() did not detect duplicate"); @@ -110,53 +110,53 @@ void TestLinkedList(void) VerifyOrQuit(list.Add(e) == OT_ERROR_ALREADY, "LinkedList::Add() did not detect duplicate"); VerifyOrQuit(list.Pop() == &e, "LinkedList::Pop() failed"); - VerifyLinkedListContent(&list, &d, &c, &b, &a, NULL); + VerifyLinkedListContent(&list, &d, &c, &b, &a, nullptr); list.SetHead(&e); - VerifyLinkedListContent(&list, &e, &d, &c, &b, &a, NULL); + VerifyLinkedListContent(&list, &e, &d, &c, &b, &a, nullptr); SuccessOrQuit(list.Remove(c), "LinkedList::Remove() failed"); - VerifyLinkedListContent(&list, &e, &d, &b, &a, NULL); + VerifyLinkedListContent(&list, &e, &d, &b, &a, nullptr); VerifyOrQuit(list.Remove(c) == OT_ERROR_NOT_FOUND, "LinkedList::Remove() failed"); - VerifyLinkedListContent(&list, &e, &d, &b, &a, NULL); + VerifyLinkedListContent(&list, &e, &d, &b, &a, nullptr); SuccessOrQuit(list.Remove(e), "LinkedList::Remove() failed"); - VerifyLinkedListContent(&list, &d, &b, &a, NULL); + VerifyLinkedListContent(&list, &d, &b, &a, nullptr); SuccessOrQuit(list.Remove(a), "LinkedList::Remove() failed"); - VerifyLinkedListContent(&list, &d, &b, NULL); + VerifyLinkedListContent(&list, &d, &b, nullptr); list.Push(a); list.Push(c); list.Push(e); - VerifyLinkedListContent(&list, &e, &c, &a, &d, &b, NULL); + VerifyLinkedListContent(&list, &e, &c, &a, &d, &b, nullptr); VerifyOrQuit(list.PopAfter(&a) == &d, "LinkedList::PopAfter() failed"); - VerifyLinkedListContent(&list, &e, &c, &a, &b, NULL); + VerifyLinkedListContent(&list, &e, &c, &a, &b, nullptr); - VerifyOrQuit(list.PopAfter(&b) == NULL, "LinkedList::PopAfter() failed"); - VerifyLinkedListContent(&list, &e, &c, &a, &b, NULL); + VerifyOrQuit(list.PopAfter(&b) == nullptr, "LinkedList::PopAfter() failed"); + VerifyLinkedListContent(&list, &e, &c, &a, &b, nullptr); VerifyOrQuit(list.PopAfter(&e) == &c, "LinkedList::PopAfter() failed"); - VerifyLinkedListContent(&list, &e, &a, &b, NULL); + VerifyLinkedListContent(&list, &e, &a, &b, nullptr); list.PushAfter(c, b); - VerifyLinkedListContent(&list, &e, &a, &b, &c, NULL); + VerifyLinkedListContent(&list, &e, &a, &b, &c, nullptr); list.PushAfter(d, a); - VerifyLinkedListContent(&list, &e, &a, &d, &b, &c, NULL); + VerifyLinkedListContent(&list, &e, &a, &d, &b, &c, nullptr); - VerifyOrQuit(list.PopAfter(NULL) == &e, "LinkedList::PopAfter() failed"); - VerifyLinkedListContent(&list, &a, &d, &b, &c, NULL); + VerifyOrQuit(list.PopAfter(nullptr) == &e, "LinkedList::PopAfter() failed"); + VerifyLinkedListContent(&list, &a, &d, &b, &c, nullptr); - VerifyOrQuit(list.PopAfter(NULL) == &a, "LinkedList::PopAfter() failed"); - VerifyLinkedListContent(&list, &d, &b, &c, NULL); + VerifyOrQuit(list.PopAfter(nullptr) == &a, "LinkedList::PopAfter() failed"); + VerifyLinkedListContent(&list, &d, &b, &c, nullptr); list.Clear(); VerifyOrQuit(list.IsEmpty(), "LinkedList::IsEmpty() failed after Clear()"); - VerifyOrQuit(list.PopAfter(NULL) == NULL, "LinkedList::PopAfter() failed"); - VerifyLinkedListContent(&list, NULL); + VerifyOrQuit(list.PopAfter(nullptr) == nullptr, "LinkedList::PopAfter() failed"); + VerifyLinkedListContent(&list, nullptr); } int main(void) diff --git a/tests/unit/test_lowpan.cpp b/tests/unit/test_lowpan.cpp index bf10b5bc7..db86f8475 100644 --- a/tests/unit/test_lowpan.cpp +++ b/tests/unit/test_lowpan.cpp @@ -129,7 +129,7 @@ static void Init(void) }; Message *message = sInstance->Get().New(Message::kTypeIp6, 0); - VerifyOrQuit(message != NULL, "6lo: Ip6::NewMessage failed"); + VerifyOrQuit(message != nullptr, "6lo: Ip6::NewMessage failed"); SuccessOrQuit(message->Append(mockNetworkData, sizeof(mockNetworkData)), "6lo: Message::Append failed"); @@ -149,7 +149,7 @@ static void Init(void) */ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress) { - Message *message = NULL; + Message *message = nullptr; uint8_t result[512]; uint8_t iphc[512]; uint8_t ip6[512]; @@ -175,7 +175,7 @@ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress) { Lowpan::BufferWriter buffer(result, 127); - VerifyOrQuit((message = sInstance->Get().New(Message::kTypeIp6, 0)) != NULL, + VerifyOrQuit((message = sInstance->Get().New(Message::kTypeIp6, 0)) != nullptr, "6lo: Ip6::NewMessage failed"); aVector.GetUncompressedStream(*message); @@ -199,12 +199,12 @@ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress) } message->Free(); - message = NULL; + message = nullptr; } if (aDecompress) { - VerifyOrQuit((message = sInstance->Get().New(Message::kTypeIp6, 0)) != NULL, + VerifyOrQuit((message = sInstance->Get().New(Message::kTypeIp6, 0)) != nullptr, "6lo: Ip6::NewMessage failed"); int decompressedBytes = @@ -232,7 +232,7 @@ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress) } message->Free(); - message = NULL; + message = nullptr; } printf("PASS\n\n"); @@ -1745,7 +1745,7 @@ void TestLowpanIphc(void) { sInstance = testInitInstance(); - VerifyOrQuit(sInstance != NULL, "NULL instance"); + VerifyOrQuit(sInstance != nullptr, "nullptr instance"); sIp6 = &sInstance->Get(); sLowpan = &sInstance->Get(); diff --git a/tests/unit/test_mac_frame.cpp b/tests/unit/test_mac_frame.cpp index c5863d0da..c7a4b2440 100644 --- a/tests/unit/test_mac_frame.cpp +++ b/tests/unit/test_mac_frame.cpp @@ -64,7 +64,7 @@ void TestMacAddress(void) uint8_t buffer[OT_EXT_ADDRESS_SIZE]; instance = testInitInstance(); - VerifyOrQuit(instance != NULL, "NULL instance\n"); + VerifyOrQuit(instance != nullptr, "nullptr instance\n"); // Mac::ExtAddress @@ -201,7 +201,7 @@ void TestMacNetworkName(void) VerifyOrQuit(networkName.Set(Mac::NameData(kLongName, sizeof(kLongName) - 1)) == OT_ERROR_ALREADY, "NetworkName::Set() accepted same name without returning OT_ERROR_ALREADY"); - SuccessOrQuit(networkName.Set(Mac::NameData(NULL, 0)), "NetworkName::Set() failed"); + SuccessOrQuit(networkName.Set(Mac::NameData(nullptr, 0)), "NetworkName::Set() failed"); CompareNetworkName(networkName, kEmptyName); SuccessOrQuit(networkName.Set(Mac::NameData(kName1, sizeof(kName1))), "NetworkName::Set() failed"); @@ -363,7 +363,7 @@ void TestMacChannelMask(void) mask1.Clear(); VerifyOrQuit(mask1.IsEmpty(), "ChannelMask.IsEmpty failed"); - VerifyChannelMaskContent(mask1, NULL, 0); + VerifyChannelMaskContent(mask1, nullptr, 0); for (uint16_t index = 0; index < sizeof(channels1); index++) { diff --git a/tests/unit/test_message.cpp b/tests/unit/test_message.cpp index 80cf7d8bf..7ad049026 100644 --- a/tests/unit/test_message.cpp +++ b/tests/unit/test_message.cpp @@ -42,7 +42,7 @@ void TestMessage(void) uint8_t readBuffer[1024]; instance = static_cast(testInitInstance()); - VerifyOrQuit(instance != NULL, "Null OpenThread instance\n"); + VerifyOrQuit(instance != nullptr, "Null OpenThread instance\n"); messagePool = &instance->Get(); @@ -51,7 +51,7 @@ void TestMessage(void) writeBuffer[i] = static_cast(random()); } - VerifyOrQuit((message = messagePool->New(ot::Message::kTypeIp6, 0)) != NULL, "Message::New failed"); + VerifyOrQuit((message = messagePool->New(ot::Message::kTypeIp6, 0)) != nullptr, "Message::New failed"); SuccessOrQuit(message->SetLength(sizeof(writeBuffer)), "Message::SetLength failed"); VerifyOrQuit(message->Write(0, sizeof(writeBuffer), writeBuffer) == sizeof(writeBuffer), "Message::Write failed"); VerifyOrQuit(message->Read(0, sizeof(readBuffer), readBuffer) == sizeof(readBuffer), "Message::Read failed"); diff --git a/tests/unit/test_message_queue.cpp b/tests/unit/test_message_queue.cpp index bb1c58c64..35af431ad 100644 --- a/tests/unit/test_message_queue.cpp +++ b/tests/unit/test_message_queue.cpp @@ -55,11 +55,11 @@ void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLen if (aExpectedLength == 0) { message = aMessageQueue.GetHead(); - VerifyOrQuit(message == NULL, "MessageQueue is not empty when expected len is zero."); + VerifyOrQuit(message == nullptr, "MessageQueue is not empty when expected len is zero."); } else { - for (message = aMessageQueue.GetHead(); message != NULL; message = message->GetNext()) + for (message = aMessageQueue.GetHead(); message != nullptr; message = message->GetNext()) { VerifyOrQuit(aExpectedLength != 0, "MessageQueue contains more entries than expected"); @@ -82,14 +82,14 @@ void TestMessageQueue(void) uint16_t msgCount, bufferCount; sInstance = testInitInstance(); - VerifyOrQuit(sInstance != NULL, "Null instance"); + VerifyOrQuit(sInstance != nullptr, "Null instance"); sMessagePool = &sInstance->Get(); for (int i = 0; i < kNumTestMessages; i++) { msg[i] = sMessagePool->New(ot::Message::kTypeIp6, 0); - VerifyOrQuit(msg[i] != NULL, "Message::New failed"); + VerifyOrQuit(msg[i] != nullptr, "Message::New failed"); } VerifyMessageQueueContent(messageQueue, 0); @@ -189,11 +189,12 @@ void VerifyMessageQueueContentUsingOtApi(otMessageQueue *aQueue, int aExpectedLe if (aExpectedLength == 0) { message = otMessageQueueGetHead(aQueue); - VerifyOrQuit(message == NULL, "MessageQueue is not empty when expected len is zero."); + VerifyOrQuit(message == nullptr, "MessageQueue is not empty when expected len is zero."); } else { - for (message = otMessageQueueGetHead(aQueue); message != NULL; message = otMessageQueueGetNext(aQueue, message)) + for (message = otMessageQueueGetHead(aQueue); message != nullptr; + message = otMessageQueueGetNext(aQueue, message)) { VerifyOrQuit(aExpectedLength != 0, "MessageQueue contains more entries than expected"); @@ -217,12 +218,12 @@ void TestMessageQueueOtApis(void) otMessageQueue queue, queue2; sInstance = testInitInstance(); - VerifyOrQuit(sInstance != NULL, "Null instance"); + VerifyOrQuit(sInstance != nullptr, "Null instance"); for (int i = 0; i < kNumTestMessages; i++) { - msg[i] = otIp6NewMessage(sInstance, NULL); - VerifyOrQuit(msg[i] != NULL, "otIp6NewMessage() failed."); + msg[i] = otIp6NewMessage(sInstance, nullptr); + VerifyOrQuit(msg[i] != nullptr, "otIp6NewMessage() failed."); } otMessageQueueInit(&queue); @@ -250,10 +251,10 @@ void TestMessageQueueOtApis(void) VerifyMessageQueueContentUsingOtApi(&queue, 1, msg[2]); // Check the failure cases for otMessageQueueGetNext() - message = otMessageQueueGetNext(&queue, NULL); - VerifyOrQuit(message == NULL, "otMessageQueueGetNext(queue, NULL) did not return NULL."); + message = otMessageQueueGetNext(&queue, nullptr); + VerifyOrQuit(message == nullptr, "otMessageQueueGetNext(queue, nullptr) did not return nullptr."); message = otMessageQueueGetNext(&queue, msg[1]); - VerifyOrQuit(message == NULL, "otMessageQueueGetNext() did not return NULL for a message not in the queue."); + VerifyOrQuit(message == nullptr, "otMessageQueueGetNext() did not return nullptr for a message not in the queue."); // Check the failure case when attempting to do otMessageQueueGetNext() but passing in a wrong queue pointer. otMessageQueueEnqueue(&queue2, msg[0]); @@ -264,7 +265,7 @@ void TestMessageQueueOtApis(void) message = otMessageQueueGetNext(&queue2, msg[0]); VerifyOrQuit(message == msg[1], "otMessageQueueGetNext() failed"); message = otMessageQueueGetNext(&queue, msg[0]); - VerifyOrQuit(message == NULL, "otMessageQueueGetNext() did not return NULL for message not in the queue."); + VerifyOrQuit(message == nullptr, "otMessageQueueGetNext() did not return nullptr for message not in the queue."); // Remove all element and make sure queue is empty otMessageQueueDequeue(&queue, msg[2]); diff --git a/tests/unit/test_netif.cpp b/tests/unit/test_netif.cpp index 83dd77ffa..f8ddc2aa5 100644 --- a/tests/unit/test_netif.cpp +++ b/tests/unit/test_netif.cpp @@ -191,7 +191,7 @@ void TestNetifMulticastAddresses(void) VerifyMulticastAddressList(netif, &addresses[2], 3); netif.UnsubscribeAllNodesMulticast(); - VerifyMulticastAddressList(netif, NULL, 0); + VerifyMulticastAddressList(netif, nullptr, 0); // The first five elements in `addresses[]` are the default/fixed addresses: // kLinkLocalAllRouters, kRealmLocalAllRouters, kLinkLocalAllNodes, diff --git a/tests/unit/test_network_data.cpp b/tests/unit/test_network_data.cpp index cddb34479..8dc885049 100644 --- a/tests/unit/test_network_data.cpp +++ b/tests/unit/test_network_data.cpp @@ -78,7 +78,7 @@ void TestNetworkDataIterator(void) ExternalRouteConfig config; instance = testInitInstance(); - VerifyOrQuit(instance != NULL, "Null OpenThread instance\n"); + VerifyOrQuit(instance != nullptr, "Null OpenThread instance\n"); { const uint8_t kNetworkData[] = {0x08, 0x04, 0x0B, 0x02, 0x00, 0x00, 0x03, 0x14, 0x00, 0x40, diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index b7ed87f16..12edc30c9 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -32,20 +32,20 @@ bool g_testPlatAlarmSet = false; uint32_t g_testPlatAlarmNext = 0; -testPlatAlarmStop g_testPlatAlarmStop = NULL; -testPlatAlarmStartAt g_testPlatAlarmStartAt = NULL; -testPlatAlarmGetNow g_testPlatAlarmGetNow = NULL; +testPlatAlarmStop g_testPlatAlarmStop = nullptr; +testPlatAlarmStartAt g_testPlatAlarmStartAt = nullptr; +testPlatAlarmGetNow g_testPlatAlarmGetNow = nullptr; otRadioCaps g_testPlatRadioCaps = OT_RADIO_CAPS_NONE; -testPlatRadioSetPanId g_testPlatRadioSetPanId = NULL; -testPlatRadioSetExtendedAddress g_testPlatRadioSetExtendedAddress = NULL; -testPlatRadioIsEnabled g_testPlatRadioIsEnabled = NULL; -testPlatRadioEnable g_testPlatRadioEnable = NULL; -testPlatRadioDisable g_testPlatRadioDisable = NULL; -testPlatRadioSetShortAddress g_testPlatRadioSetShortAddress = NULL; -testPlatRadioReceive g_testPlatRadioReceive = NULL; -testPlatRadioTransmit g_testPlatRadioTransmit = NULL; -testPlatRadioGetTransmitBuffer g_testPlatRadioGetTransmitBuffer = NULL; +testPlatRadioSetPanId g_testPlatRadioSetPanId = nullptr; +testPlatRadioSetExtendedAddress g_testPlatRadioSetExtendedAddress = nullptr; +testPlatRadioIsEnabled g_testPlatRadioIsEnabled = nullptr; +testPlatRadioEnable g_testPlatRadioEnable = nullptr; +testPlatRadioDisable g_testPlatRadioDisable = nullptr; +testPlatRadioSetShortAddress g_testPlatRadioSetShortAddress = nullptr; +testPlatRadioReceive g_testPlatRadioReceive = nullptr; +testPlatRadioTransmit g_testPlatRadioTransmit = nullptr; +testPlatRadioGetTransmitBuffer g_testPlatRadioGetTransmitBuffer = nullptr; enum { @@ -57,18 +57,18 @@ uint8_t g_flash[FLASH_SWAP_SIZE * FLASH_SWAP_NUM]; ot::Instance *testInitInstance(void) { - otInstance *instance = NULL; + otInstance *instance = nullptr; #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE size_t instanceBufferLength = 0; - uint8_t *instanceBuffer = NULL; + uint8_t *instanceBuffer = nullptr; // Call to query the buffer size - (void)otInstanceInit(NULL, &instanceBufferLength); + (void)otInstanceInit(nullptr, &instanceBufferLength); // Call to allocate the buffer instanceBuffer = (uint8_t *)malloc(instanceBufferLength); - VerifyOrQuit(instanceBuffer != NULL, "Failed to allocate otInstance"); + VerifyOrQuit(instanceBuffer != nullptr, "Failed to allocate otInstance"); memset(instanceBuffer, 0, instanceBufferLength); // Initialize OpenThread with the buffer @@ -147,7 +147,7 @@ uint32_t otPlatAlarmMilliGetNow(void) else { struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); return (uint32_t)((tv.tv_sec * 1000) + (tv.tv_usec / 1000) + 123456); } } @@ -186,7 +186,7 @@ uint32_t otPlatAlarmMicroGetNow(void) else { struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); return (uint32_t)((tv.tv_sec * 1000000) + tv.tv_usec + 123456); } } @@ -596,7 +596,7 @@ uint64_t otPlatTimeGet(void) { struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec; } diff --git a/tests/unit/test_priority_queue.cpp b/tests/unit/test_priority_queue.cpp index 89d2f381a..feadba37d 100644 --- a/tests/unit/test_priority_queue.cpp +++ b/tests/unit/test_priority_queue.cpp @@ -57,21 +57,21 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected if (aExpectedLength == 0) { message = aPriorityQueue.GetHead(); - VerifyOrQuit(message == NULL, "PriorityQueue is not empty when expected len is zero."); + VerifyOrQuit(message == nullptr, "PriorityQueue is not empty when expected len is zero."); - VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityLow) == NULL, - "GetHeadForPriority() non-NULL when empty"); - VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityNormal) == NULL, - "GetHeadForPriority() non-NULL when empty"); - VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityHigh) == NULL, - "GetHeadForPriority() non-NULL when empty"); - VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityNet) == NULL, - "GetHeadForPriority() non-NULL when empty"); + VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityLow) == nullptr, + "GetHeadForPriority() non-nullptr when empty"); + VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityNormal) == nullptr, + "GetHeadForPriority() non-nullptr when empty"); + VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityHigh) == nullptr, + "GetHeadForPriority() non-nullptr when empty"); + VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityNet) == nullptr, + "GetHeadForPriority() non-nullptr when empty"); } else { // Go through all messages in the queue and verify they match the passed-in messages - for (message = aPriorityQueue.GetHead(); message != NULL; message = message->GetNext()) + for (message = aPriorityQueue.GetHead(); message != nullptr; message = message->GetNext()) { VerifyOrQuit(aExpectedLength != 0, "PriorityQueue contains more entries than expected."); @@ -81,10 +81,11 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected { for (curPriority--; curPriority != msgArg->GetPriority(); curPriority--) { - // Check the `GetHeadForPriority` is NULL if there are no expected message for this priority level. + // Check the `GetHeadForPriority` is nullptr if there are no expected message for this priority + // level. VerifyOrQuit( - aPriorityQueue.GetHeadForPriority(static_cast(curPriority)) == NULL, - "PriorityQueue::GetHeadForPriority is non-NULL when no expected msg for this priority."); + aPriorityQueue.GetHeadForPriority(static_cast(curPriority)) == nullptr, + "PriorityQueue::GetHeadForPriority is non-nullptr when no expected msg for this priority."); } // Check the `GetHeadForPriority`. @@ -101,11 +102,11 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected VerifyOrQuit(aExpectedLength == 0, "PriorityQueue contains less entries than expected."); - // Check the `GetHeadForPriority` is NULL if there are no expected message for any remaining priority level. + // Check the `GetHeadForPriority` is nullptr if there are no expected message for any remaining priority level. for (curPriority--; curPriority >= 0; curPriority--) { - VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast(curPriority)) == NULL, - "PriorityQueue::GetHeadForPriority is non-NULL when no expected msg for this priority."); + VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast(curPriority)) == nullptr, + "PriorityQueue::GetHeadForPriority is non-nullptr when no expected msg for this priority."); } } @@ -124,11 +125,11 @@ void VerifyMsgQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLength, if (aExpectedLength == 0) { message = aMessageQueue.GetHead(); - VerifyOrQuit(message == NULL, "MessageQueue is not empty when expected len is zero."); + VerifyOrQuit(message == nullptr, "MessageQueue is not empty when expected len is zero."); } else { - for (message = aMessageQueue.GetHead(); message != NULL; message = message->GetNext()) + for (message = aMessageQueue.GetHead(); message != nullptr; message = message->GetNext()) { VerifyOrQuit(aExpectedLength != 0, "MessageQueue contains more entries than expected"); @@ -156,7 +157,7 @@ void TestPriorityQueue(void) ot::Message * msgLow[kNumTestMessages]; instance = testInitInstance(); - VerifyOrQuit(instance != NULL, "Null OpenThread instance"); + VerifyOrQuit(instance != nullptr, "Null OpenThread instance"); messagePool = &instance->Get(); @@ -164,29 +165,29 @@ void TestPriorityQueue(void) for (int i = 0; i < kNumNewPriorityTestMessages; i++) { msgNet[i] = messagePool->New(ot::Message::kTypeIp6, 0, ot::Message::kPriorityNet); - VerifyOrQuit(msgNet[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgNet[i] != nullptr, "Message::New failed"); msgHigh[i] = messagePool->New(ot::Message::kTypeIp6, 0, ot::Message::kPriorityHigh); - VerifyOrQuit(msgHigh[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgHigh[i] != nullptr, "Message::New failed"); msgNor[i] = messagePool->New(ot::Message::kTypeIp6, 0, ot::Message::kPriorityNormal); - VerifyOrQuit(msgNor[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgNor[i] != nullptr, "Message::New failed"); msgLow[i] = messagePool->New(ot::Message::kTypeIp6, 0, ot::Message::kPriorityLow); - VerifyOrQuit(msgLow[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgLow[i] != nullptr, "Message::New failed"); } // Use the function "SetPriority()" to allocate messages with different priorities for (int i = kNumNewPriorityTestMessages; i < kNumTestMessages; i++) { msgNet[i] = messagePool->New(ot::Message::kTypeIp6, 0); - VerifyOrQuit(msgNet[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgNet[i] != nullptr, "Message::New failed"); SuccessOrQuit(msgNet[i]->SetPriority(ot::Message::kPriorityNet), "Message:SetPriority failed"); msgHigh[i] = messagePool->New(ot::Message::kTypeIp6, 0); - VerifyOrQuit(msgHigh[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgHigh[i] != nullptr, "Message::New failed"); SuccessOrQuit(msgHigh[i]->SetPriority(ot::Message::kPriorityHigh), "Message:SetPriority failed"); msgNor[i] = messagePool->New(ot::Message::kTypeIp6, 0); - VerifyOrQuit(msgNor[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgNor[i] != nullptr, "Message::New failed"); SuccessOrQuit(msgNor[i]->SetPriority(ot::Message::kPriorityNormal), "Message:SetPriority failed"); msgLow[i] = messagePool->New(ot::Message::kTypeIp6, 0); - VerifyOrQuit(msgLow[i] != NULL, "Message::New failed"); + VerifyOrQuit(msgLow[i] != nullptr, "Message::New failed"); SuccessOrQuit(msgLow[i]->SetPriority(ot::Message::kPriorityLow), "Message:SetPriority failed"); } diff --git a/tests/unit/test_spinel_buffer.cpp b/tests/unit/test_spinel_buffer.cpp index 21f07b986..9c14fa2ea 100644 --- a/tests/unit/test_spinel_buffer.cpp +++ b/tests/unit/test_spinel_buffer.cpp @@ -133,8 +133,8 @@ void FrameAddedCallback(void * aContext, { CallbackContext *callbackContext = reinterpret_cast(aContext); - VerifyOrQuit(aNcpBuffer != NULL, "Null Spinel::Buffer in the callback"); - VerifyOrQuit(callbackContext != NULL, "Null context in the callback"); + VerifyOrQuit(aNcpBuffer != nullptr, "Null Spinel::Buffer in the callback"); + VerifyOrQuit(callbackContext != nullptr, "Null context in the callback"); VerifyOrQuit(aTag != Spinel::Buffer::kInvalidTag, "Invalid tag in the callback"); VerifyOrQuit(aTag == aNcpBuffer->InFrameGetLastTag(), "InFrameGetLastTag() does not match the tag from callback"); @@ -150,8 +150,8 @@ void FrameRemovedCallback(void * aContext, { CallbackContext *callbackContext = reinterpret_cast(aContext); - VerifyOrQuit(aNcpBuffer != NULL, "Null Spinel::Buffer in the callback"); - VerifyOrQuit(callbackContext != NULL, "Null context in the callback"); + VerifyOrQuit(aNcpBuffer != nullptr, "Null Spinel::Buffer in the callback"); + VerifyOrQuit(callbackContext != nullptr, "Null context in the callback"); VerifyOrQuit(aTag != Spinel::Buffer::kInvalidTag, "Invalid tag in the callback"); VerifyAndRemoveTagFromHistory(aTag, aPriority); @@ -177,7 +177,7 @@ void WriteTestFrame1(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPrior CallbackContext oldContext; message = sMessagePool->New(Message::kTypeIp6, 0); - VerifyOrQuit(message != NULL, "Null Message"); + VerifyOrQuit(message != nullptr, "Null Message"); SuccessOrQuit(message->SetLength(sizeof(sMottoText)), "Could not set the length of message."); message->Write(0, sizeof(sMottoText), sMottoText); @@ -221,12 +221,12 @@ void WriteTestFrame2(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPrior CallbackContext oldContext = sContext; message1 = sMessagePool->New(Message::kTypeIp6, 0); - VerifyOrQuit(message1 != NULL, "Null Message"); + VerifyOrQuit(message1 != nullptr, "Null Message"); SuccessOrQuit(message1->SetLength(sizeof(sMysteryText)), "Could not set the length of message."); message1->Write(0, sizeof(sMysteryText), sMysteryText); message2 = sMessagePool->New(Message::kTypeIp6, 0); - VerifyOrQuit(message2 != NULL, "Null Message"); + VerifyOrQuit(message2 != nullptr, "Null Message"); SuccessOrQuit(message2->SetLength(sizeof(sHelloText)), "Could not set the length of message."); message2->Write(0, sizeof(sHelloText), sHelloText); @@ -266,7 +266,7 @@ void WriteTestFrame3(Spinel::Buffer &aNcpBuffer, Spinel::Buffer::Priority aPrior CallbackContext oldContext = sContext; message1 = sMessagePool->New(Message::kTypeIp6, 0); - VerifyOrQuit(message1 != NULL, "Null Message"); + VerifyOrQuit(message1 != nullptr, "Null Message"); // An empty message with no content. SuccessOrQuit(message1->SetLength(0), "Could not set the length of message."); @@ -527,7 +527,7 @@ void TestBuffer(void) SuccessOrQuit(ncpBuffer.InFrameFeedData(sHelloText, sizeof(sHelloText)), "InFrameFeedData() failed."); message = sMessagePool->New(Message::kTypeIp6, 0); - VerifyOrQuit(message != NULL, "Null Message"); + VerifyOrQuit(message != nullptr, "Null Message"); SuccessOrQuit(message->SetLength(sizeof(sMysteryText)), "Could not set the length of message."); message->Write(0, sizeof(sMysteryText), sMysteryText); @@ -732,7 +732,7 @@ void TestBuffer(void) VerifyOrQuit(ncpBuffer.InFrameFeedData(sOpenThreadText, 0) == OT_ERROR_INVALID_STATE, "Incorrect error status"); VerifyOrQuit(ncpBuffer.InFrameEnd() == OT_ERROR_INVALID_STATE, "Incorrect error status"); message = sMessagePool->New(Message::kTypeIp6, 0); - VerifyOrQuit(message != NULL, "Null Message"); + VerifyOrQuit(message != nullptr, "Null Message"); SuccessOrQuit(message->SetLength(sizeof(sMysteryText)), "Could not set the length of message."); message->Write(0, sizeof(sMysteryText), sMysteryText); VerifyOrQuit(ncpBuffer.InFrameFeedMessage(message) == OT_ERROR_INVALID_STATE, "Incorrect error status"); diff --git a/tests/unit/test_timer.cpp b/tests/unit/test_timer.cpp index e2045c8bd..ad63ed817 100644 --- a/tests/unit/test_timer.cpp +++ b/tests/unit/test_timer.cpp @@ -87,7 +87,7 @@ template class TestTimer : public TimerType { public: TestTimer(ot::Instance &aInstance) - : TimerType(aInstance, TestTimer::HandleTimerFired, NULL) + : TimerType(aInstance, TestTimer::HandleTimerFired, nullptr) , mFiredCounter(0) { }