From 09a0fbe9c6177a1355f767bec4e2129b36cba898 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 27 Sep 2023 10:59:37 -0700 Subject: [PATCH] [ip6] update where `HandlePayload()` check `message` is not null (#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. --- src/core/net/ip6.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 487093a66a8..b130377a825 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -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