Skip to content

Commit a880ec3

Browse files
authored
Use new (std::nothrow) instead of new where the result is checked against nullptr (#22264)
1 parent 1dc0b35 commit a880ec3

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

src/controller/CommissioningWindowOpener.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ CHIP_ERROR AutoCommissioningWindowOpener::OpenBasicCommissioningWindow(DeviceCon
323323
Seconds16 timeout)
324324
{
325325
// Not using Platform::New because we want to keep our constructor private.
326-
auto * opener = new AutoCommissioningWindowOpener(controller);
326+
auto * opener = new (std::nothrow) AutoCommissioningWindowOpener(controller);
327327
if (opener == nullptr)
328328
{
329329
return CHIP_ERROR_NO_MEMORY;
@@ -345,7 +345,7 @@ CHIP_ERROR AutoCommissioningWindowOpener::OpenCommissioningWindow(DeviceControll
345345
SetupPayload & payload, bool readVIDPIDAttributes)
346346
{
347347
// Not using Platform::New because we want to keep our constructor private.
348-
auto * opener = new AutoCommissioningWindowOpener(controller);
348+
auto * opener = new (std::nothrow) AutoCommissioningWindowOpener(controller);
349349
if (opener == nullptr)
350350
{
351351
return CHIP_ERROR_NO_MEMORY;

src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners(
5050
ChipError::StorageType
5151
pychip_CommissionableNodeController_NewController(chip::Controller::CommissionableNodeController ** outCommissionableNodeCtrl)
5252
{
53-
*outCommissionableNodeCtrl = new chip::Controller::CommissionableNodeController();
53+
*outCommissionableNodeCtrl = new (std::nothrow) chip::Controller::CommissionableNodeController();
5454
VerifyOrReturnError(*outCommissionableNodeCtrl != nullptr, CHIP_ERROR_NO_MEMORY.AsInteger());
5555
return CHIP_NO_ERROR.AsInteger();
5656
}

src/controller/python/chip/interaction_model/Delegate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ chip::ChipError::StorageType pychip_InteractionModel_GetCommandSenderHandle(uint
5555
{
5656
chip::app::CommandSender * commandSenderObj = nullptr;
5757
VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_INVALID_ARGUMENT.AsInteger());
58-
commandSenderObj = new chip::app::CommandSender(nullptr, nullptr);
58+
commandSenderObj = new (std::nothrow) chip::app::CommandSender(nullptr, nullptr);
5959
VerifyOrReturnError(commandSenderObj != nullptr, (CHIP_ERROR_NO_MEMORY).AsInteger());
6060
*commandSender = reinterpret_cast<uint64_t>(commandSenderObj);
6161
return CHIP_NO_ERROR.AsInteger();

src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TestQName
4444
mStrings[i] = strdup(data[i]);
4545
}
4646

47-
mSerializedQNameBuffer = new uint8_t[neededSize];
47+
mSerializedQNameBuffer = new (std::nothrow) uint8_t[neededSize];
4848
VerifyOrDie(mSerializedQNameBuffer != nullptr);
4949

5050
chip::Encoding::BigEndian::BufferWriter writer(mSerializedQNameBuffer, neededSize);

src/system/tests/TestSystemPacketBuffer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int PacketBufferTest::TestSetup(void * inContext)
221221
return FAILURE;
222222

223223
TestContext * const theContext = reinterpret_cast<TestContext *>(inContext);
224-
theContext->test = new PacketBufferTest(theContext);
224+
theContext->test = new (std::nothrow) PacketBufferTest(theContext);
225225
if (theContext->test == nullptr)
226226
{
227227
return FAILURE;

0 commit comments

Comments
 (0)