File tree 2 files changed +11
-15
lines changed
2 files changed +11
-15
lines changed Original file line number Diff line number Diff line change 10
10
#include " openssl/opensslv.h"
11
11
#endif
12
12
13
- #include < errno.h>
14
13
#include < algorithm>
15
- #include < cstdlib > // strtoul, errno
14
+ #include < charconv >
16
15
#include < limits>
17
16
#include < sstream>
18
17
#include < string_view>
@@ -1004,17 +1003,17 @@ inline std::string RemoveBrackets(const std::string& host) {
1004
1003
return host;
1005
1004
}
1006
1005
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 )) {
1015
1013
errors->push_back (" must be 0 or in range 1024 to 65535." );
1016
1014
}
1017
- return static_cast <int >(result);
1015
+
1016
+ return result;
1018
1017
}
1019
1018
1020
1019
HostPort SplitHostPort (const std::string& arg,
Original file line number Diff line number Diff line change @@ -32,10 +32,7 @@ class HostPort {
32
32
33
33
const std::string& host () const { return host_name_; }
34
34
35
- uint16_t port () const {
36
- CHECK_GE (port_, 0 );
37
- return port_;
38
- }
35
+ uint16_t port () const { return port_; }
39
36
40
37
void Update (const HostPort& other) {
41
38
if (!other.host_name_ .empty ()) host_name_ = other.host_name_ ;
You can’t perform that action at this time.
0 commit comments