Skip to content

Commit a415b0a

Browse files
committed
refactor: replace call to the size()/length() with empty()
Signed-off-by: Leonard Ossa <leonard.ossa@openvpn.com>
1 parent 51842a2 commit a415b0a

40 files changed

+72
-72
lines changed

openvpn/client/cliemuexr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class EmulateExcludeRouteImpl : public EmulateExcludeRoute
4747

4848
bool enabled(const IPVerFlags &ipv) const override
4949
{
50-
return exclude.size() && (ipv.rgv4() || ipv.rgv6());
50+
return !exclude.empty() && (ipv.rgv4() || ipv.rgv6());
5151
}
5252

5353
void emulate(TunBuilderBase *tb, IPVerFlags &ipv, const IP::Addr &server_addr) const override

openvpn/client/clihalt.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ class ClientHalt
101101

102102
static bool is_halt(const StringList &sl)
103103
{
104-
return sl.size() >= 1 && sl[0] == "HALT";
104+
return !sl.empty() && sl[0] == "HALT";
105105
}
106106

107107
static bool is_restart(const StringList &sl)
108108
{
109-
return sl.size() >= 1 && sl[0] == "RESTART";
109+
return !sl.empty() && sl[0] == "RESTART";
110110
}
111111

112112
bool restart_ = false;

openvpn/client/cliopthelper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ParseClientConfig
147147
// userlocked username/password via <auth-user-pass>
148148
std::vector<std::string> user_pass;
149149
const bool auth_user_pass = parse_auth_user_pass(options, &user_pass);
150-
if (auth_user_pass && user_pass.size() >= 1)
150+
if (auth_user_pass && !user_pass.empty())
151151
{
152152
userlockedUsername_ = user_pass[0];
153153
if (user_pass.size() >= 2)
@@ -569,7 +569,7 @@ class ParseClientConfig
569569
print_pem(os, "cert", sslConfig->extract_cert());
570570

571571
std::vector<std::string> extra_certs = sslConfig->extract_extra_certs();
572-
if (extra_certs.size() > 0)
572+
if (!extra_certs.empty())
573573
{
574574
os << "<extra-certs>" << std::endl;
575575
for (auto &cert : extra_certs)

openvpn/client/cliproto.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class Session : ProtoContextCallbackInterface,
376376
{
377377
// data packet
378378
proto_context.data_decrypt(pt, buf);
379-
if (buf.size())
379+
if (!buf.empty())
380380
{
381381
#ifdef OPENVPN_PACKET_LOG
382382
log_packet(buf, false);
@@ -454,7 +454,7 @@ class Session : ProtoContextCallbackInterface,
454454
}
455455

456456
// encrypt packet
457-
if (buf.size())
457+
if (!buf.empty())
458458
{
459459
const ProtoContext::ProtoConfig &c = proto_context.conf();
460460

@@ -479,7 +479,7 @@ class Session : ProtoContextCallbackInterface,
479479
else
480480
{
481481
proto_context.data_encrypt(buf);
482-
if (buf.size())
482+
if (!buf.empty())
483483
{
484484
// send packet via transport to destination
485485
OPENVPN_LOG_CLIPROTO("Transport SEND " << server_endpoint_render() << ' ' << proto_context.dump_packet(buf));
@@ -815,7 +815,7 @@ class Session : ProtoContextCallbackInterface,
815815
key_words = msg.substr(strlen("AUTH_PENDING,"));
816816
auto opts = OptionList::parse_from_csv_static(key_words, nullptr);
817817
std::string timeout_str = opts.get_optional("timeout", 1, 20);
818-
if (timeout_str != "")
818+
if (!timeout_str.empty())
819819
{
820820
try
821821
{

openvpn/client/dns.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ struct DnsOptionsParser : public DnsOptions
266266
search_domains.insert(search_domains.begin(), DnsDomain(std::move(adapter_domain_suffix)));
267267
}
268268

269-
if (!ignore_values && servers.size() && servers[0].addresses.empty())
269+
if (!ignore_values && !servers.empty() && servers[0].addresses.empty())
270270
{
271271
parse_errors += "\n";
272272
parse_errors += "dns server does not have an address assigned";

openvpn/client/optfilt.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ class PushedOptionsFilter : public OptionList::FilterBase
144144
FilterAction route_nopull_filter_(const Option &opt)
145145
{
146146
FilterAction action = Accept;
147-
if (opt.size() >= 1)
147+
if (!opt.empty())
148148
{
149149
const std::string &directive = opt.ref(0);
150-
if (directive.length() >= 1)
150+
if (!directive.empty())
151151
{
152152
switch (directive[0])
153153
{

openvpn/client/remotelist.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class RemoteList : public RC<thread_unsafe_refcount>
131131

132132
bool res_addr_list_defined() const
133133
{
134-
return res_addr_list && res_addr_list->size() > 0;
134+
return res_addr_list && !res_addr_list->empty();
135135
}
136136

137137
std::string actual_host() const
@@ -231,7 +231,7 @@ class RemoteList : public RC<thread_unsafe_refcount>
231231
struct Directives
232232
{
233233
explicit Directives(const std::string &conn_tag = "")
234-
: connection(conn_tag.length() ? conn_tag : "connection")
234+
: connection(!conn_tag.empty() ? conn_tag : "connection")
235235
{
236236
}
237237

@@ -685,7 +685,7 @@ class RemoteList : public RC<thread_unsafe_refcount>
685685
// return true if object has at least one connection entry
686686
bool defined() const
687687
{
688-
return list.size() > 0;
688+
return !list.empty();
689689
}
690690

691691
// return remote list size

openvpn/common/hostport.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ inline bool is_valid_host_char(const char c)
6363

6464
inline bool is_valid_host(const std::string &host)
6565
{
66-
if (!host.length() || host.length() > 256)
66+
if (host.empty() || host.length() > 256)
6767
return false;
6868
for (const auto &c : host)
6969
{
@@ -80,7 +80,7 @@ inline bool is_valid_unix_sock_char(const unsigned char c)
8080

8181
inline bool is_valid_unix_sock(const std::string &host)
8282
{
83-
if (!host.length() || host.length() > 256)
83+
if (host.empty() || host.length() > 256)
8484
return false;
8585
for (const auto &c : host)
8686
{

openvpn/common/options.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Option
173173
{
174174
try
175175
{
176-
if (data.size() > 0)
176+
if (!data.empty())
177177
return Unicode::utf8_printable(data[0], 32);
178178
else
179179
return "";
@@ -425,7 +425,7 @@ class Option
425425
std::string err_ref() const
426426
{
427427
std::string ret = "option";
428-
if (data.size())
428+
if (!data.empty())
429429
{
430430
ret += " '";
431431
ret += printable_directive();
@@ -893,7 +893,7 @@ class OptionList : public std::vector<Option>, public RCCopyable<thread_unsafe_r
893893
for (std::vector<std::string>::const_iterator i = list.begin(); i != list.end(); ++i)
894894
{
895895
const Option opt = Split::by_space<Option, Lex, SpaceMatch, Limits>(*i, lim);
896-
if (opt.size())
896+
if (!opt.empty())
897897
{
898898
if (lim)
899899
{
@@ -940,7 +940,7 @@ class OptionList : public std::vector<Option>, public RCCopyable<thread_unsafe_r
940940
Option opt;
941941
opt.reserve(2);
942942
Split::by_char_void<Option, NullLex, Limits>(opt, line, '=', 0, 1, lim);
943-
if (opt.size())
943+
if (!opt.empty())
944944
{
945945
if (lim)
946946
{
@@ -1019,7 +1019,7 @@ class OptionList : public std::vector<Option>, public RCCopyable<thread_unsafe_r
10191019
else if (!ignore_line(line))
10201020
{
10211021
Option opt = parse_option_from_line(line, lim);
1022-
if (opt.size())
1022+
if (!opt.empty())
10231023
{
10241024
if (is_open_tag(opt.ref(0)))
10251025
{
@@ -1087,7 +1087,7 @@ class OptionList : public std::vector<Option>, public RCCopyable<thread_unsafe_r
10871087
else if (line.starts_with(prefix))
10881088
{
10891089
Option opt = Split::by_char<Option, NullLex, Limits>(std::string(line, prefix.length()), '=', 0, 1, lim);
1090-
if (opt.size())
1090+
if (!opt.empty())
10911091
{
10921092
if (is_open_meta_tag(opt.ref(0)))
10931093
{

openvpn/common/path.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ inline bool win_dev(const std::string &path, const bool fully_qualified)
6060
// true if path is fully qualified
6161
inline bool is_fully_qualified(const std::string &path)
6262
{
63-
return win_dev(path, true) || (path.length() > 0 && is_dirsep(path[0]));
63+
return win_dev(path, true) || (!path.empty() && is_dirsep(path[0]));
6464
}
6565

6666
// does path refer to regular file without directory traversal
6767
inline bool is_flat(const std::string &path)
6868
{
69-
return path.length() > 0
69+
return !path.empty()
7070
&& path != "."
7171
&& path != ".."
7272
&& path.find_first_of(dirsep) == std::string::npos

0 commit comments

Comments
 (0)