Skip to content

Commit

Permalink
Use new (std::nothrow) instead of new where the result is checked aga…
Browse files Browse the repository at this point in the history
…inst nullptr (#22264)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jun 28, 2023
1 parent 1706f07 commit 3527053
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/controller/CommissioningWindowOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/interaction_model/Delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(commandSenderObj);
return CHIP_NO_ERROR.AsInteger();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/core/tests/QNameStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/system/tests/TestSystemPacketBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ int PacketBufferTest::TestSetup(void * inContext)
return FAILURE;

TestContext * const theContext = reinterpret_cast<TestContext *>(inContext);
theContext->test = new PacketBufferTest(theContext);
theContext->test = new (std::nothrow) PacketBufferTest(theContext);
if (theContext->test == nullptr)
{
return FAILURE;
Expand Down

0 comments on commit 3527053

Please sign in to comment.