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 'Wconversion' warns: casting ints and check tcp endpoints #216

Merged
merged 11 commits into from
Apr 2, 2024
2 changes: 1 addition & 1 deletion src/groups/mwc/mwcio/mwcio_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool ChannelWatermarkType::fromAscii(ChannelWatermarkType::Enum* out,
#define CHECKVALUE(M) \
if (bdlb::String::areEqualCaseless(toAscii(ChannelWatermarkType::e_##M), \
str.data(), \
str.length())) { \
static_cast<int>(str.length()))) { \
*out = ChannelWatermarkType::e_##M; \
return true; \
}
Expand Down
19 changes: 16 additions & 3 deletions src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ bool TCPEndpoint::fromUri(const bsl::string& uri)
}

// Extract the port part: i.e. after the last ':'
d_port = bsl::strtol(uri.c_str() + colon + 1, 0, 10);
const long port = bsl::strtol(uri.c_str() + colon + 1, 0, 10);

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

// Extract the host part: i.e. between '/' and ':'
d_host.assign(uri, k_SCHEME_LEN, colon - k_SCHEME_LEN);
Expand All @@ -111,7 +113,18 @@ void TCPEndpoint::fromUriRaw(const bsl::string& uri)

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

d_port = bsl::strtol(uri.c_str() + separator + 1, 0, 10);
if (separator == bsl::string::npos) {
return; // RETURN
}
melvinhe marked this conversation as resolved.
Show resolved Hide resolved

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);
}

Expand Down
Loading