Skip to content

Commit b25c5e9

Browse files
committed
fixup! src: set port in node_options to uint16_t
1 parent 3dafabd commit b25c5e9

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/node_options.cc

+10-11
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>
@@ -1004,17 +1003,17 @@ inline std::string RemoveBrackets(const std::string& host) {
10041003
return host;
10051004
}
10061005

1007-
inline int ParseAndValidatePort(const std::string& port,
1008-
std::vector<std::string>* errors) {
1009-
char* endptr;
1010-
errno = 0;
1011-
const unsigned long result = // NOLINT(runtime/int)
1012-
strtoul(port.c_str(), &endptr, 10);
1013-
if (errno != 0 || *endptr != '\0'||
1014-
(result != 0 && result < 1024) || result > 65535) {
1006+
inline uint16_t ParseAndValidatePort(const std::string_view port,
1007+
std::vector<std::string>* errors) {
1008+
uint16_t result{};
1009+
auto r = std::from_chars(port.data(), port.data() + port.size(), result);
1010+
1011+
if (r.ec == std::errc::result_out_of_range ||
1012+
(result != 0 && result < 1024)) {
10151013
errors->push_back(" must be 0 or in range 1024 to 65535.");
10161014
}
1017-
return static_cast<int>(result);
1015+
1016+
return result;
10181017
}
10191018

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

src/node_options.h

+1-4
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)