Skip to content

Commit

Permalink
Fix 'Wconversion' warns: casting ints and check tcp endpoints (bloomb…
Browse files Browse the repository at this point in the history
…erg#216)


Signed-off-by: Melvin He <[email protected]>
Co-authored-by: Patrick M. Niedzielski <[email protected]>
Co-authored-by: Evgeny Malygin <[email protected]>
  • Loading branch information
3 people authored and syuzvinsky committed Apr 4, 2024
1 parent eff2e6a commit 69e82c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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
}

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

0 comments on commit 69e82c5

Please sign in to comment.