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
13 changes: 9 additions & 4 deletions src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ 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);

if (d_port == 0) {
long temp_port = bsl::strtol(uri.c_str() + colon + 1, 0, 10);
if (temp_port <= 0 || temp_port > INT_MAX) {
// Invalid value for port number
return false; // RETURN
}
d_port = static_cast<int>(temp_port);

// Extract the host part: i.e. between '/' and ':'
d_host.assign(uri, k_SCHEME_LEN, colon - k_SCHEME_LEN);
Expand All @@ -111,7 +112,11 @@ 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);
long temp_port = bsl::strtol(uri.c_str() + separator + 1, 0, 10);
if (temp_port > 0 && temp_port <= INT_MAX) {
// Maintaining strtol long value and casting if port in range
d_port = static_cast<int>(temp_port);
}
d_host.assign(uri, k_SCHEME_LEN, separator - k_SCHEME_LEN);
}

Expand Down
Loading