Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] Fix some bugprone-use-after-move errors #15476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ble/BtpEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ CHIP_ERROR BtpEngine::HandleCharacteristicReceived(System::PacketBufferHandle &&
}
LogState();

if (!data.IsNull())
if (!data.IsNull()) // NOLINT(bugprone-use-after-move)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a real bug

{
// Tack received data onto rx buffer, to be freed when end point resets protocol engine on close.
if (!mRxBuf.IsNull())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/tests/TestCHIPTLV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4312,7 +4312,7 @@ static void CheckCHIPTLVScopedBuffer(nlTestSuite * inSuite, void * inContext)
{
ScopedBufferTLVWriter writer(std::move(buf), 64);

NL_TEST_ASSERT(inSuite, buf.Get() == nullptr);
NL_TEST_ASSERT(inSuite, buf.Get() == nullptr); // // NOLINT(bugprone-use-after-move)

err = writer.Put(TLV::AnonymousTag(), (uint8_t) 33);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/support/tests/TestVariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void TestVariantMove(nlTestSuite * inSuite, void * inContext)
Variant<Simple, Movable> v1;
v1.Set<Movable>(5, 10);
Variant<Simple, Movable> v2 = std::move(v1);
NL_TEST_ASSERT(inSuite, !v1.Valid());
NL_TEST_ASSERT(inSuite, !v1.Valid()); // NOLINT(bugprone-use-after-move)
NL_TEST_ASSERT(inSuite, v2.Valid());
NL_TEST_ASSERT(inSuite, v2.Get<Movable>().m1 == 5);
NL_TEST_ASSERT(inSuite, v2.Get<Movable>().m2 == 10);
Expand All @@ -204,7 +204,7 @@ void TestVariantMoveAssign(nlTestSuite * inSuite, void * inContext)
Variant<Simple, Pod> v2;
v1.Set<Pod>(5, 10);
v2 = std::move(v1);
NL_TEST_ASSERT(inSuite, !v1.Valid());
NL_TEST_ASSERT(inSuite, !v1.Valid()); // NOLINT(bugprone-use-after-move)
NL_TEST_ASSERT(inSuite, v2.Valid());
NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m1 == 5);
NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m2 == 10);
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ CHIP_ERROR CASESession::ParseSigma1(TLV::ContiguousBufferTLVReader & tlvReader,
}

CHIP_ERROR CASESession::ValidateReceivedMessage(ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle & msg)
const System::PacketBufferHandle & msg)
{
VerifyOrReturnError(ec != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/CASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class DLL_EXPORT CASESession : public Messaging::ExchangeDelegate, public Pairin
CHIP_ERROR SetEffectiveTime();

CHIP_ERROR ValidateReceivedMessage(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle & msg);
const System::PacketBufferHandle & msg);

SessionEstablishmentDelegate * mDelegate = nullptr;

Expand Down
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/PASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ CHIP_ERROR PASESession::OnFailureStatusReport(Protocols::SecureChannel::GeneralS
}

CHIP_ERROR PASESession::ValidateReceivedMessage(ExchangeContext * exchange, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msg)
const System::PacketBufferHandle & msg)
{
VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

Expand Down Expand Up @@ -886,7 +886,7 @@ CHIP_ERROR PASESession::ValidateReceivedMessage(ExchangeContext * exchange, cons
CHIP_ERROR PASESession::OnMessageReceived(ExchangeContext * exchange, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msg)
{
CHIP_ERROR err = ValidateReceivedMessage(exchange, payloadHeader, std::move(msg));
CHIP_ERROR err = ValidateReceivedMessage(exchange, payloadHeader, msg);
SuccessOrExit(err);

switch (static_cast<MsgType>(payloadHeader.GetMessageType()))
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/secure_channel/PASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class DLL_EXPORT PASESession : public Messaging::ExchangeDelegate, public Pairin
CHIP_ERROR Init(uint16_t mySessionId, uint32_t setupCode, SessionEstablishmentDelegate * delegate);

CHIP_ERROR ValidateReceivedMessage(Messaging::ExchangeContext * exchange, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && msg);
const System::PacketBufferHandle & msg);

CHIP_ERROR SetupSpake2p();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DLL_EXPORT UserDirectedCommissioningClient
*
*/

CHIP_ERROR EncodeUDCMessage(System::PacketBufferHandle && payload);
CHIP_ERROR EncodeUDCMessage(const System::PacketBufferHandle & payload);
};

class DLL_EXPORT UserDirectedCommissioningServer : public TransportMgrDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace UserDirectedCommissioning {
CHIP_ERROR UserDirectedCommissioningClient::SendUDCMessage(TransportMgrBase * transportMgr, System::PacketBufferHandle && payload,
chip::Transport::PeerAddress peerAddress)
{
CHIP_ERROR err = EncodeUDCMessage(std::move(payload));
CHIP_ERROR err = EncodeUDCMessage(payload);
if (err != CHIP_NO_ERROR)
{
return err;
Expand All @@ -44,7 +44,7 @@ CHIP_ERROR UserDirectedCommissioningClient::SendUDCMessage(TransportMgrBase * tr
// send UDC message 5 times per spec (no ACK on this message)
for (unsigned int i = 0; i < 5; i++)
{
err = transportMgr->SendMessage(peerAddress, std::move(payload));
err = transportMgr->SendMessage(peerAddress, payload.CloneData());
vivien-apple marked this conversation as resolved.
Show resolved Hide resolved
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "UDC SendMessage failed, err: %s\n", chip::ErrorStr(err));
Expand All @@ -56,7 +56,7 @@ CHIP_ERROR UserDirectedCommissioningClient::SendUDCMessage(TransportMgrBase * tr
return err;
}

CHIP_ERROR UserDirectedCommissioningClient::EncodeUDCMessage(System::PacketBufferHandle && payload)
CHIP_ERROR UserDirectedCommissioningClient::EncodeUDCMessage(const System::PacketBufferHandle & payload)
{
PayloadHeader payloadHeader;
PacketHeader packetHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void TestUDCServerInstanceNameResolver(nlTestSuite * inSuite, void * inContext)
// encode our client message
char nameBuffer[Dnssd::Commission::kInstanceNameMaxLength + 1] = "Chris";
System::PacketBufferHandle payloadBuf = MessagePacketBuffer::NewWithData(nameBuffer, strlen(nameBuffer));
udcClient.EncodeUDCMessage(std::move(payloadBuf));
udcClient.EncodeUDCMessage(payloadBuf);

// prepare peerAddress for handleMessage
Inet::IPAddress commissioner;
Expand All @@ -165,8 +165,10 @@ void TestUDCServerInstanceNameResolver(nlTestSuite * inSuite, void * inContext)
// same instance name is received, there is no callback
testCallback.mFindCommissionableNodeCalled = false;

payloadBuf = MessagePacketBuffer::NewWithData(nameBuffer, strlen(nameBuffer));

// reset the UDC message
udcClient.EncodeUDCMessage(std::move(payloadBuf));
udcClient.EncodeUDCMessage(payloadBuf);

// test OnMessageReceived again
mUdcTransportMgr->HandleMessageReceived(peerAddress, std::move(payloadBuf));
Expand All @@ -177,8 +179,10 @@ void TestUDCServerInstanceNameResolver(nlTestSuite * inSuite, void * inContext)
// next, reset the cache state and confirm the callback
udcServer.ResetUDCClientProcessingStates();

payloadBuf = MessagePacketBuffer::NewWithData(nameBuffer, strlen(nameBuffer));

// reset the UDC message
udcClient.EncodeUDCMessage(std::move(payloadBuf));
udcClient.EncodeUDCMessage(payloadBuf);

// test OnMessageReceived again
mUdcTransportMgr->HandleMessageReceived(peerAddress, std::move(payloadBuf));
Expand All @@ -194,7 +198,7 @@ void TestUserDirectedCommissioningClientMessage(nlTestSuite * inSuite, void * in
UserDirectedCommissioningClient udcClient;

// obtain the UDC message
CHIP_ERROR err = udcClient.EncodeUDCMessage(std::move(payloadBuf));
CHIP_ERROR err = udcClient.EncodeUDCMessage(payloadBuf);

// check the packet header fields
PacketHeader packetHeader;
Expand Down