Skip to content

Commit f10e1aa

Browse files
committed
fixup! src: set port in node_options to uint16_t
1 parent 404a7b3 commit f10e1aa

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/node_options.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
#include "openssl/opensslv.h"
1111
#endif
1212

13-
#include <errno.h>
1413
#include <algorithm>
15-
#include <cstdlib> // strtoul, errno
14+
#include <charconv>
1615
#include <limits>
1716
#include <sstream>
1817
#include <string_view>
@@ -1010,17 +1009,17 @@ inline std::string RemoveBrackets(const std::string& host) {
10101009
return host;
10111010
}
10121011

1013-
inline int ParseAndValidatePort(const std::string& port,
1014-
std::vector<std::string>* errors) {
1015-
char* endptr;
1016-
errno = 0;
1017-
const unsigned long result = // NOLINT(runtime/int)
1018-
strtoul(port.c_str(), &endptr, 10);
1019-
if (errno != 0 || *endptr != '\0'||
1020-
(result != 0 && result < 1024) || result > 65535) {
1012+
inline uint16_t ParseAndValidatePort(const std::string_view port,
1013+
std::vector<std::string>* errors) {
1014+
uint16_t result{};
1015+
auto r = std::from_chars(port.data(), port.data() + port.size(), result);
1016+
1017+
if (r.ec == std::errc::result_out_of_range ||
1018+
(result != 0 && result < 1024)) {
10211019
errors->push_back(" must be 0 or in range 1024 to 65535.");
10221020
}
1023-
return static_cast<int>(result);
1021+
1022+
return result;
10241023
}
10251024

10261025
HostPort SplitHostPort(const std::string& arg,

src/node_options.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class HostPort {
3232

3333
const std::string& host() const { return host_name_; }
3434

35-
uint16_t port() const {
36-
CHECK_GE(port_, 0);
37-
return port_;
38-
}
35+
uint16_t port() const { return port_; }
3936

4037
void Update(const HostPort& other) {
4138
if (!other.host_name_.empty()) host_name_ = other.host_name_;

0 commit comments

Comments
 (0)