[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.
This commit is contained in:
Abtin Keshavarzian
2025-06-24 09:30:08 -07:00
committed by GitHub
parent c6f3f1ff31
commit 093d2a8427
2 changed files with 4 additions and 1 deletions
+3 -1
View File
@@ -198,9 +198,9 @@ void Dhcp6PdClient::SendMessage(void)
{
static const uint16_t kRequestedOptions[] = {BigEndian::HostSwap16(Option::kSolMaxRt)};
MsgType msgType = kMsgTypeNone;
OwnedPtr<Message> 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
+1
View File
@@ -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).