summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common/Socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/common/Socket.cpp')
-rw-r--r--lldb/source/Host/common/Socket.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp
index 0732565f0d8..9ce36d014f6 100644
--- a/lldb/source/Host/common/Socket.cpp
+++ b/lldb/source/Host/common/Socket.cpp
@@ -282,27 +282,25 @@ bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
int32_t &port, Status *error_ptr) {
static RegularExpression g_regex(
llvm::StringRef("([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)"));
- RegularExpression::Match regex_match(2);
- if (g_regex.Execute(host_and_port, &regex_match)) {
- if (regex_match.GetMatchAtIndex(host_and_port, 1, host_str) &&
- regex_match.GetMatchAtIndex(host_and_port, 2, port_str)) {
- // IPv6 addresses are wrapped in [] when specified with ports
- if (host_str.front() == '[' && host_str.back() == ']')
- host_str = host_str.substr(1, host_str.size() - 2);
- bool ok = false;
- port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
- if (ok && port <= UINT16_MAX) {
- if (error_ptr)
- error_ptr->Clear();
- return true;
- }
- // port is too large
+ llvm::SmallVector<llvm::StringRef, 3> matches;
+ if (g_regex.Execute(host_and_port, &matches)) {
+ host_str = matches[1].str();
+ port_str = matches[2].str();
+ // IPv6 addresses are wrapped in [] when specified with ports
+ if (host_str.front() == '[' && host_str.back() == ']')
+ host_str = host_str.substr(1, host_str.size() - 2);
+ bool ok = false;
+ port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
+ if (ok && port <= UINT16_MAX) {
if (error_ptr)
- error_ptr->SetErrorStringWithFormat(
- "invalid host:port specification: '%s'",
- host_and_port.str().c_str());
- return false;
+ error_ptr->Clear();
+ return true;
}
+ // port is too large
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat(
+ "invalid host:port specification: '%s'", host_and_port.str().c_str());
+ return false;
}
// If this was unsuccessful, then check if it's simply a signed 32-bit
OpenPOWER on IntegriCloud