Skip to content

Commit

Permalink
[ip6] update where HandlePayload() check message is not null (ope…
Browse files Browse the repository at this point in the history
…nthread#9462)

This commit updates `Ip6::HandlePayload()` to check the `message`
pointer for null in the common flow, instead of in the `if()` block
where the message is cloned when `aMessageOwnership` is set to
`kCopyToUse`. If `aMessageOwnership` is `kTakeCustody` the `message`
is initialized as `&aMessage` already which cannot be `nullptr`.

This protects against code checker warnings that `message` may remain
null if the given `aMessageOwnership` enum value is not one of its
two defined enumerator values.
  • Loading branch information
abtink authored Sep 27, 2023
1 parent 17286db commit 09a0fbe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/net/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,11 @@ Error Ip6::HandlePayload(Header &aIp6Header,

if (aMessageOwnership == Message::kCopyToUse)
{
VerifyOrExit((message = aMessage.Clone()) != nullptr, error = kErrorNoBufs);
message = aMessage.Clone();
}

VerifyOrExit(message != nullptr, error = kErrorNoBufs);

switch (aIpProto)
{
#if OPENTHREAD_CONFIG_TCP_ENABLE
Expand Down

0 comments on commit 09a0fbe

Please sign in to comment.