Skip to content

Commit bbc0683

Browse files
melvinhepniedzielski678098
authored
Fix 'Wconversion' warns: casting ints and check tcp endpoints (#216)
Signed-off-by: Melvin He <[email protected]> Co-authored-by: Patrick M. Niedzielski <[email protected]> Co-authored-by: Evgeny Malygin <[email protected]>
1 parent 587b6fe commit bbc0683

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/groups/mwc/mwcio/mwcio_channel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool ChannelWatermarkType::fromAscii(ChannelWatermarkType::Enum* out,
6363
#define CHECKVALUE(M) \
6464
if (bdlb::String::areEqualCaseless(toAscii(ChannelWatermarkType::e_##M), \
6565
str.data(), \
66-
str.length())) { \
66+
static_cast<int>(str.length()))) { \
6767
*out = ChannelWatermarkType::e_##M; \
6868
return true; \
6969
}

src/groups/mwc/mwcio/mwcio_tcpendpoint.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ bool TCPEndpoint::fromUri(const bsl::string& uri)
9090
}
9191

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

95-
if (d_port == 0) {
95+
// For simplicity, do not accept ambiguous `port` value 0
96+
if (port <= 0 || port > 65535) {
9697
return false; // RETURN
9798
}
99+
d_port = static_cast<int>(port);
98100

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

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

114-
d_port = bsl::strtol(uri.c_str() + separator + 1, 0, 10);
116+
if (separator == bsl::string::npos) {
117+
return; // RETURN
118+
}
119+
120+
const long port = bsl::strtol(uri.c_str() + separator + 1, 0, 10);
121+
122+
// For simplicity, do not accept ambiguous `port` value 0
123+
if (port <= 0 || port > 65535) {
124+
return; // RETURN
125+
}
126+
127+
d_port = static_cast<int>(port);
115128
d_host.assign(uri, k_SCHEME_LEN, separator - k_SCHEME_LEN);
116129
}
117130

0 commit comments

Comments
 (0)