From 093d2a84274603263abb64977a70b30c632fb879 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 24 Jun 2025 09:30:08 -0700 Subject: [PATCH] [dhcp6-pd-client] initialize `msgType` to fix compiler warning (#11631) This commit updates `SendMessage()` to initialize the `msgType` variable before the `switch` statement. This change addresses a compiler warning for a possibly uninitialized variable, flagged by `-Werror=maybe-uninitialized`. Note that the situation where `mState` would be an undefined value is not technically possible in the current logic. However, the compiler cannot guarantee this and therefore generates a warning. Initializing the variable upfront resolves this issue. --- src/core/border_router/dhcp6_pd_client.cpp | 4 +++- src/core/net/dhcp6_types.hpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/border_router/dhcp6_pd_client.cpp b/src/core/border_router/dhcp6_pd_client.cpp index 1c8f22d11..1f756e83c 100644 --- a/src/core/border_router/dhcp6_pd_client.cpp +++ b/src/core/border_router/dhcp6_pd_client.cpp @@ -198,9 +198,9 @@ void Dhcp6PdClient::SendMessage(void) { static const uint16_t kRequestedOptions[] = {BigEndian::HostSwap16(Option::kSolMaxRt)}; + MsgType msgType = kMsgTypeNone; OwnedPtr message; Header header; - MsgType msgType; Ip6::Address dstAddr; switch (mState) @@ -226,6 +226,8 @@ void Dhcp6PdClient::SendMessage(void) ExitNow(); } + VerifyOrExit(msgType != kMsgTypeNone); + if (!mRetxTracker.ShouldRetx()) { // Message exchanges can optionally define limits: A maximum diff --git a/src/core/net/dhcp6_types.hpp b/src/core/net/dhcp6_types.hpp index a583ff554..245a1ba00 100644 --- a/src/core/net/dhcp6_types.hpp +++ b/src/core/net/dhcp6_types.hpp @@ -63,6 +63,7 @@ constexpr uint16_t kDhcpServerPort = 547; ///< DHCP Server port number. */ enum MsgType : uint8_t { + kMsgTypeNone = 0, ///< Unused message type (reserved). kMsgTypeSolicit = 1, ///< Solicit message (client sends to locate servers). kMsgTypeAdvertise = 2, ///< Advertise message (server sends to indicate it is available). kMsgTypeRequest = 3, ///< Request message (client sends to request config parameters).