From a641d3f829257269d8d8bd79eda37d0a4963466e Mon Sep 17 00:00:00 2001 From: qingyan01 <68208925+qingyan01@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:46:25 +0800 Subject: [PATCH] move the following auto *addr above the if and check whether the addr is nullptr --- src/common/network/NetworkUtils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/network/NetworkUtils.cpp b/src/common/network/NetworkUtils.cpp index e615719b8d4..8ec6d6dc4f1 100644 --- a/src/common/network/NetworkUtils.cpp +++ b/src/common/network/NetworkUtils.cpp @@ -65,8 +65,9 @@ StatusOr>> NetworkUtils::listDev return Status::Error("%s", ::strerror(errno)); } for (auto* ifa = iflist; ifa != nullptr; ifa = ifa->ifa_next) { + auto* addr = ifa->ifa_addr; // Skip non-IPv4 devices - if (nullptr == ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET) { + if (nullptr == addr || addr->sa_family != AF_INET) { continue; } auto* addr = reinterpret_cast(ifa->ifa_addr);