Skip to content

Commit b02694c

Browse files
committed
fix(network): initialize all fields
Some fields were previously uninitialized (e.g. carrier), which could lead to UB.
1 parent 2dfbaab commit b02694c

File tree

2 files changed

+23
-41
lines changed

2 files changed

+23
-41
lines changed

include/modules/network.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class Network : public ALabel {
2727
auto update() -> void override;
2828

2929
private:
30-
static const uint8_t MAX_RETRY = 5;
31-
static const uint8_t EPOLL_MAX = 200;
30+
static const uint8_t MAX_RETRY{5};
31+
static const uint8_t EPOLL_MAX{200};
3232

3333
static int handleEvents(struct nl_msg*, void*);
3434
static int handleEventsDone(struct nl_msg*, void*);
@@ -51,37 +51,37 @@ class Network : public ALabel {
5151
bool wildcardMatch(const std::string& pattern, const std::string& text) const;
5252
std::optional<std::pair<unsigned long long, unsigned long long>> readBandwidthUsage();
5353

54-
int ifid_;
55-
ip_addr_pref addr_pref_;
56-
struct sockaddr_nl nladdr_ = {0};
57-
struct nl_sock* sock_ = nullptr;
58-
struct nl_sock* ev_sock_ = nullptr;
59-
int efd_;
60-
int ev_fd_;
61-
int nl80211_id_;
54+
int ifid_{-1};
55+
ip_addr_pref addr_pref_{ip_addr_pref::IPV4};
56+
struct sockaddr_nl nladdr_{0};
57+
struct nl_sock* sock_{nullptr};
58+
struct nl_sock* ev_sock_{nullptr};
59+
int efd_{-1};
60+
int ev_fd_{-1};
61+
int nl80211_id_{-1};
6262
std::mutex mutex_;
6363

64-
bool want_route_dump_;
65-
bool want_link_dump_;
66-
bool want_addr_dump_;
67-
bool dump_in_progress_;
68-
bool is_p2p_;
64+
bool want_route_dump_{false};
65+
bool want_link_dump_{false};
66+
bool want_addr_dump_{false};
67+
bool dump_in_progress_{false};
68+
bool is_p2p_{false};
6969

70-
unsigned long long bandwidth_down_total_;
71-
unsigned long long bandwidth_up_total_;
70+
unsigned long long bandwidth_down_total_{0};
71+
unsigned long long bandwidth_up_total_{0};
7272

7373
std::string state_;
7474
std::string essid_;
7575
std::string bssid_;
76-
bool carrier_;
76+
bool carrier_{false};
7777
std::string ifname_;
7878
std::string ipaddr_;
7979
std::string ipaddr6_;
8080
std::string gwaddr_;
8181
std::string netmask_;
8282
std::string netmask6_;
83-
int cidr_;
84-
int cidr6_;
83+
int cidr_{0};
84+
int cidr6_{0};
8585
int32_t signal_strength_dbm_;
8686
uint8_t signal_strength_;
8787
std::string signal_strength_app_;
@@ -90,9 +90,9 @@ class Network : public ALabel {
9090
util::SleeperThread thread_;
9191
util::SleeperThread thread_timer_;
9292
#ifdef WANT_RFKILL
93-
util::Rfkill rfkill_;
93+
util::Rfkill rfkill_{RFKILL_TYPE_WLAN};
9494
#endif
95-
float frequency_;
95+
float frequency_{0};
9696
};
9797

9898
} // namespace waybar::modules

src/modules/network.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,7 @@ waybar::modules::Network::readBandwidthUsage() {
7878
}
7979

8080
waybar::modules::Network::Network(const std::string &id, const Json::Value &config)
81-
: ALabel(config, "network", id, DEFAULT_FORMAT, 60),
82-
ifid_(-1),
83-
addr_pref_(IPV4),
84-
efd_(-1),
85-
ev_fd_(-1),
86-
want_route_dump_(false),
87-
want_link_dump_(false),
88-
want_addr_dump_(false),
89-
dump_in_progress_(false),
90-
is_p2p_(false),
91-
cidr_(0),
92-
cidr6_(0),
93-
signal_strength_dbm_(0),
94-
signal_strength_(0),
95-
#ifdef WANT_RFKILL
96-
rfkill_{RFKILL_TYPE_WLAN},
97-
#endif
98-
frequency_(0.0) {
99-
81+
: ALabel(config, "network", id, DEFAULT_FORMAT, 60) {
10082
// Start with some "text" in the module's label_. update() will then
10183
// update it. Since the text should be different, update() will be able
10284
// to show or hide the event_box_. This is to work around the case where

0 commit comments

Comments
 (0)