From 352705395e974acbcc3d0b6d93e91f193c4a9c53 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 31 Aug 2022 17:16:51 +0200 Subject: [PATCH] Use new (std::nothrow) instead of new where the result is checked against nullptr (#22264) --- src/controller/CommissioningWindowOpener.cpp | 4 ++-- .../python/ChipCommissionableNodeController-ScriptBinding.cpp | 2 +- src/controller/python/chip/interaction_model/Delegate.cpp | 2 +- src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h | 2 +- src/system/tests/TestSystemPacketBuffer.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/controller/CommissioningWindowOpener.cpp b/src/controller/CommissioningWindowOpener.cpp index c9fd1381927dbf..689717ba9397e7 100644 --- a/src/controller/CommissioningWindowOpener.cpp +++ b/src/controller/CommissioningWindowOpener.cpp @@ -323,7 +323,7 @@ CHIP_ERROR AutoCommissioningWindowOpener::OpenBasicCommissioningWindow(DeviceCon Seconds16 timeout) { // Not using Platform::New because we want to keep our constructor private. - auto * opener = new AutoCommissioningWindowOpener(controller); + auto * opener = new (std::nothrow) AutoCommissioningWindowOpener(controller); if (opener == nullptr) { return CHIP_ERROR_NO_MEMORY; @@ -345,7 +345,7 @@ CHIP_ERROR AutoCommissioningWindowOpener::OpenCommissioningWindow(DeviceControll SetupPayload & payload, bool readVIDPIDAttributes) { // Not using Platform::New because we want to keep our constructor private. - auto * opener = new AutoCommissioningWindowOpener(controller); + auto * opener = new (std::nothrow) AutoCommissioningWindowOpener(controller); if (opener == nullptr) { return CHIP_ERROR_NO_MEMORY; diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index db49bf6e360917..0fd3df5de89bec 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -50,7 +50,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( ChipError::StorageType pychip_CommissionableNodeController_NewController(chip::Controller::CommissionableNodeController ** outCommissionableNodeCtrl) { - *outCommissionableNodeCtrl = new chip::Controller::CommissionableNodeController(); + *outCommissionableNodeCtrl = new (std::nothrow) chip::Controller::CommissionableNodeController(); VerifyOrReturnError(*outCommissionableNodeCtrl != nullptr, CHIP_ERROR_NO_MEMORY.AsInteger()); return CHIP_NO_ERROR.AsInteger(); } diff --git a/src/controller/python/chip/interaction_model/Delegate.cpp b/src/controller/python/chip/interaction_model/Delegate.cpp index 54f73386bfc7fc..20ce1d2747b678 100644 --- a/src/controller/python/chip/interaction_model/Delegate.cpp +++ b/src/controller/python/chip/interaction_model/Delegate.cpp @@ -55,7 +55,7 @@ chip::ChipError::StorageType pychip_InteractionModel_GetCommandSenderHandle(uint { chip::app::CommandSender * commandSenderObj = nullptr; VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_INVALID_ARGUMENT.AsInteger()); - commandSenderObj = new chip::app::CommandSender(nullptr, nullptr); + commandSenderObj = new (std::nothrow) chip::app::CommandSender(nullptr, nullptr); VerifyOrReturnError(commandSenderObj != nullptr, (CHIP_ERROR_NO_MEMORY).AsInteger()); *commandSender = reinterpret_cast(commandSenderObj); return CHIP_NO_ERROR.AsInteger(); diff --git a/src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h b/src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h index aa724573dda04d..9cb7cf6cf03d35 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h +++ b/src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h @@ -44,7 +44,7 @@ class TestQName mStrings[i] = strdup(data[i]); } - mSerializedQNameBuffer = new uint8_t[neededSize]; + mSerializedQNameBuffer = new (std::nothrow) uint8_t[neededSize]; VerifyOrDie(mSerializedQNameBuffer != nullptr); chip::Encoding::BigEndian::BufferWriter writer(mSerializedQNameBuffer, neededSize); diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index d3c7bc362dc645..92cedf5f3b9427 100644 --- a/src/system/tests/TestSystemPacketBuffer.cpp +++ b/src/system/tests/TestSystemPacketBuffer.cpp @@ -221,7 +221,7 @@ int PacketBufferTest::TestSetup(void * inContext) return FAILURE; TestContext * const theContext = reinterpret_cast(inContext); - theContext->test = new PacketBufferTest(theContext); + theContext->test = new (std::nothrow) PacketBufferTest(theContext); if (theContext->test == nullptr) { return FAILURE;