File tree Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Original file line number Diff line number Diff line change 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
10261025HostPort SplitHostPort (const std::string& arg,
Original file line number Diff line number Diff 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_ ;
You can’t perform that action at this time.
0 commit comments