Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! src: set port in node_options to uint16_t
  • Loading branch information
anonrig committed Sep 27, 2023
commit f10e1aac52ab776820d7bb4609aabacba2a1ff8f
21 changes: 10 additions & 11 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
#include "openssl/opensslv.h"
#endif

#include <errno.h>
#include <algorithm>
#include <cstdlib> // strtoul, errno
#include <charconv>
#include <limits>
#include <sstream>
#include <string_view>
Expand Down Expand Up @@ -1010,17 +1009,17 @@ inline std::string RemoveBrackets(const std::string& host) {
return host;
}

inline int ParseAndValidatePort(const std::string& port,
std::vector<std::string>* errors) {
char* endptr;
errno = 0;
const unsigned long result = // NOLINT(runtime/int)
strtoul(port.c_str(), &endptr, 10);
if (errno != 0 || *endptr != '\0'||
(result != 0 && result < 1024) || result > 65535) {
inline uint16_t ParseAndValidatePort(const std::string_view port,
std::vector<std::string>* errors) {
uint16_t result{};
auto r = std::from_chars(port.data(), port.data() + port.size(), result);

if (r.ec == std::errc::result_out_of_range ||
(result != 0 && result < 1024)) {
errors->push_back(" must be 0 or in range 1024 to 65535.");
}
return static_cast<int>(result);

return result;
}

HostPort SplitHostPort(const std::string& arg,
Expand Down
5 changes: 1 addition & 4 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class HostPort {

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

uint16_t port() const {
CHECK_GE(port_, 0);
return port_;
}
uint16_t port() const { return port_; }

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