Skip to content

Commit 703a4b5

Browse files
committed
Fix more possible clang-tidy issues.
1 parent a85c335 commit 703a4b5

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

src/linux/libnl-helpers/Netlink80211Interface.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
using namespace Microsoft::Net::Netlink::Nl80211;
3131

32+
// NOLINTBEGIN(concurrency-mt-unsafe)
33+
3234
Nl80211Interface::Nl80211Interface(std::string_view name, nl80211_iftype type, uint32_t index, uint32_t wiphyIndex) noexcept :
3335
Name(name),
3436
Type(type),
@@ -177,3 +179,5 @@ Nl80211Interface::IsAccessPoint() const noexcept
177179
{
178180
return (Type == nl80211_iftype::NL80211_IFTYPE_AP);
179181
}
182+
183+
// NOLINTEND(concurrency-mt-unsafe)

src/linux/libnl-helpers/Netlink80211ProtocolState.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Nl80211ProtocolState::Nl80211ProtocolState()
2323
auto netlinkSocket{ NetlinkSocket::Allocate() };
2424

2525
// Connect the socket to the generic netlink family.
26-
int ret = genl_connect(netlinkSocket);
26+
const int ret = genl_connect(netlinkSocket);
2727
if (ret < 0) {
2828
const auto err = errno;
29-
LOGE << std::format("Failed to connect netlink socket for nl control with error {} ({})", err, strerror(err));
29+
LOGE << std::format("Failed to connect netlink socket for nl control with error {} ({})", err, strerror(err)); // NOLINT(concurrency-mt-unsafe)
3030
throw err;
3131
}
3232

src/linux/libnl-helpers/Netlink80211Wiphy.cxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ HandleNl80211GetWiphyResponse(struct nl_msg *nl80211Message, void *context) noex
7676

7777
/* static */
7878
std::optional<Nl80211Wiphy>
79-
Nl80211Wiphy::FromId(std::function<void(Microsoft::Net::Netlink::NetlinkMessage &)> addWiphyIdentifier)
79+
Nl80211Wiphy::FromId(const std::function<void(Microsoft::Net::Netlink::NetlinkMessage &)> &addWiphyIdentifier)
8080
{
8181
// Allocate a new netlink socket.
8282
auto nl80211SocketOpt{ CreateNl80211Socket() };
@@ -178,7 +178,7 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
178178
std::array<struct nlattr *, NL80211_ATTR_MAX + 1> wiphyAttributes{};
179179
int ret = nla_parse(std::data(wiphyAttributes), std::size(wiphyAttributes), genlmsg_attrdata(genl80211MessageHeader, 0), genlmsg_attrlen(genl80211MessageHeader, 0), nullptr);
180180
if (ret < 0) {
181-
LOGE << std::format("Failed to parse netlink message attributes with error {} ({})", ret, strerror(-ret));
181+
LOGE << std::format("Failed to parse netlink message attributes with error {} ({})", ret, strerror(-ret)); // NOLINT(concurrency-mt-unsafe)
182182
return std::nullopt;
183183
}
184184

@@ -189,14 +189,14 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
189189
}
190190

191191
auto wiphyIndex = static_cast<uint32_t>(nla_get_u32(wiphyAttributes[NL80211_ATTR_WIPHY]));
192-
auto wiphyName = static_cast<const char *>(nla_data(wiphyAttributes[NL80211_ATTR_WIPHY_NAME]));
192+
const auto *wiphyName = static_cast<const char *>(nla_data(wiphyAttributes[NL80211_ATTR_WIPHY_NAME]));
193193

194194
// Process bands.
195-
auto wiphyBands = wiphyAttributes[NL80211_ATTR_WIPHY_BANDS];
195+
auto *wiphyBands = wiphyAttributes[NL80211_ATTR_WIPHY_BANDS];
196196
std::unordered_map<nl80211_band, Nl80211WiphyBand> wiphyBandMap{};
197197
if (wiphyBands != nullptr) {
198-
int remainingBands;
199-
struct nlattr *wiphyBand;
198+
int remainingBands = 0;
199+
struct nlattr *wiphyBand = nullptr;
200200

201201
nla_for_each_nested(wiphyBand, wiphyBands, remainingBands)
202202
{
@@ -214,13 +214,13 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
214214

215215
// Process AKM suites.
216216
// Note: NL80211_ATTR_AKM_SUITES describes the AKMs supported by the PHY (wiphy) and is not specific to an interface.
217-
uint32_t *wiphyAkmSuites;
217+
uint32_t *wiphyAkmSuites = nullptr;
218218
std::size_t wiphyNumAkmSuites = 0;
219219
std::vector<uint32_t> akmSuites{};
220220
if (wiphyAttributes[NL80211_ATTR_AKM_SUITES] != nullptr) {
221221
wiphyAkmSuites = static_cast<uint32_t *>(nla_data(wiphyAttributes[NL80211_ATTR_AKM_SUITES]));
222222
wiphyNumAkmSuites = static_cast<std::size_t>(nla_len(wiphyAttributes[NL80211_ATTR_AKM_SUITES])) / sizeof(*wiphyAkmSuites);
223-
akmSuites = std::vector<uint32_t>(wiphyAkmSuites, wiphyAkmSuites + wiphyNumAkmSuites);
223+
akmSuites = std::vector<uint32_t>(wiphyAkmSuites, wiphyAkmSuites + wiphyNumAkmSuites); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
224224
} else {
225225
// Per nl80211 documentation, if this attribute is not present, userspace should assume all AKMs are supported.
226226
akmSuites = Microsoft::Net::Wifi::AllIeee80211Akms;
@@ -230,17 +230,17 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
230230
std::size_t wiphyNumCipherSuites = 0;
231231
std::vector<uint32_t> cipherSuites{};
232232
if (wiphyAttributes[NL80211_ATTR_CIPHER_SUITES] != nullptr) {
233-
uint32_t *wiphyCipherSuites;
233+
uint32_t *wiphyCipherSuites = nullptr;
234234
wiphyNumCipherSuites = static_cast<std::size_t>(nla_len(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES])) / sizeof(*wiphyCipherSuites);
235235
wiphyCipherSuites = static_cast<uint32_t *>(nla_data(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES]));
236-
cipherSuites = std::vector<uint32_t>(wiphyCipherSuites, wiphyCipherSuites + wiphyNumCipherSuites);
236+
cipherSuites = std::vector<uint32_t>(wiphyCipherSuites, wiphyCipherSuites + wiphyNumCipherSuites); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
237237
}
238238

239239
// Process supported interface types.
240240
std::vector<nl80211_iftype> supportedInterfaceTypes{};
241241
if (wiphyAttributes[NL80211_ATTR_SUPPORTED_IFTYPES] != nullptr) {
242-
int remainingSupportedInterfaceTypes;
243-
struct nlattr *supportedInterfaceType;
242+
int remainingSupportedInterfaceTypes = 0;
243+
struct nlattr *supportedInterfaceType = nullptr;
244244
nla_for_each_nested(supportedInterfaceType, wiphyAttributes[NL80211_ATTR_SUPPORTED_IFTYPES], remainingSupportedInterfaceTypes)
245245
{
246246
auto interfaceType = static_cast<nl80211_iftype>(supportedInterfaceType->nla_type);

src/linux/libnl-helpers/include/microsoft/net/netlink/nl80211/Netlink80211Wiphy.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private:
9292
* @return std::optional<Nl80211Wiphy>
9393
*/
9494
static std::optional<Nl80211Wiphy>
95-
FromId(std::function<void(Microsoft::Net::Netlink::NetlinkMessage&)> addWiphyIdentifier);
95+
FromId(const std::function<void(Microsoft::Net::Netlink::NetlinkMessage&)>& addWiphyIdentifier);
9696
};
9797

9898
} // namespace Microsoft::Net::Netlink::Nl80211

src/linux/tools/apmonitor/Main.cxx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
#include <csignal> // NOLINT(misc-include-cleaner)
2+
// NOLINTBEGIN(misc-include-cleaner, concurrency-mt-unsafe)
3+
// clang-tidy can't seem to figure out that sig/SIG* stuff is indirectly included by <csignal>. While we could include
4+
// the actual headers directly, this goes against the std library's convention of including the top-level header.
5+
6+
#include <csignal>
37
#include <format>
48
#include <memory>
59
#include <utility>
@@ -37,7 +41,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
3741
accessPointDiscoveryAgent->Start();
3842

3943
// Mask SIGTERM and SIGINT so they can be explicitly waited on from the main thread.
40-
int signal;
44+
int signal = 0;
4145
sigset_t mask;
4246
sigemptyset(&mask);
4347
sigaddset(&mask, SIGTERM);
@@ -49,11 +53,14 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
4953
}
5054

5155
// Wait for the process to be signaled to exit.
52-
while (sigwait(&mask, &signal) != 0)
56+
while (sigwait(&mask, &signal) != 0) {
5357
;
58+
}
5459

5560
// Received interrupt or terminate signal, so shut down.
5661
accessPointDiscoveryAgent->Stop();
5762

5863
return 0;
5964
}
65+
66+
// NOLINTEND(misc-include-cleaner, concurrency-mt-unsafe)

0 commit comments

Comments
 (0)