Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: enforce strict TCPEndpoint build #235

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 4 additions & 18 deletions src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,8 @@ bool TCPEndpoint::fromUri(const bsl::string& uri)

void TCPEndpoint::fromUriRaw(const bsl::string& uri)
{
d_uri = uri;

const size_t separator = uri.find_last_of(':');

if (separator == bsl::string::npos) {
return; // RETURN
}

const long port = bsl::strtol(uri.c_str() + separator + 1, 0, 10);

// For simplicity, do not accept ambiguous `port` value 0
if (port <= 0 || port > 65535) {
return; // RETURN
}

d_port = static_cast<int>(port);
d_host.assign(uri, k_SCHEME_LEN, separator - k_SCHEME_LEN);
const bool res = fromUri(uri);
BSLS_ASSERT(res);
}

TCPEndpoint& TCPEndpoint::assign(const bslstl::StringRef& host, int port)
Expand All @@ -134,7 +119,8 @@ TCPEndpoint& TCPEndpoint::assign(const bslstl::StringRef& host, int port)
mwcu::MemOutStream ss(&localAllocator);
ss << k_SCHEME << host << ":" << port;

fromUriRaw(ss.str());
const bool res = fromUri(ss.str());
BSLS_ASSERT_SAFE(res);

return *this;
}
Expand Down
1 change: 1 addition & 0 deletions src/groups/mwc/mwcio/mwcio_tcpendpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class TCPEndpoint {
/// false if the uri failed to parse.
bool fromUri(const bsl::string& uri);

/// DEPRECATED: use `fromUri` instead.
/// Set the uri of this endpoint to `uri`. Expects uri to be valid
/// format.
void fromUriRaw(const bsl::string& uri);
Expand Down
Loading