Skip to content

Commit 5eb0464

Browse files
authored
Merge pull request #1744 from evoskuil/master
Clean up exception trapping in address utils.
2 parents 550255f + c507428 commit 5eb0464

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

include/bitcoin/system/impl/radix/base_16.ipp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ constexpr uint8_t encode_octet(
9595

9696
constexpr std::string encode_base16(const data_slice& data) NOEXCEPT
9797
{
98-
std::string out;
98+
std::string out{};
9999
out.resize(data.size() * octet_width);
100100
auto digit = out.begin();
101101

@@ -111,7 +111,7 @@ constexpr std::string encode_base16(const data_slice& data) NOEXCEPT
111111
// std::string is constexpr
112112
constexpr std::string encode_hash(const data_slice& hash) NOEXCEPT
113113
{
114-
std::string out;
114+
std::string out{};
115115
out.resize(hash.size() * octet_width);
116116
auto digit = out.begin();
117117

@@ -194,11 +194,11 @@ constexpr bool decode_hash(data_array<Size>& out,
194194
}
195195

196196
template <size_t Size>
197-
constexpr data_array<Size> decode_hash(const std::string_view& in) NOEXCEPT
197+
constexpr data_array<Size> decode_hash(const std::string_view& in) THROWS
198198
{
199199
data_array<Size> out{};
200200
if (!decode_hash(out, in))
201-
return {};
201+
throw istream_exception{ "decode_hash" };
202202

203203
return out;
204204
}
@@ -215,7 +215,7 @@ constexpr std::string base16_string(const char(&string)[Size]) NOEXCEPT
215215
template <size_t Size, if_odd<Size>>
216216
data_chunk base16_chunk(const char(&string)[Size]) NOEXCEPT
217217
{
218-
data_chunk out;
218+
data_chunk out{};
219219
decode_base16(out, string);
220220
return out;
221221
}

include/bitcoin/system/radix/base_16.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ template <size_t Size>
6969
constexpr bool decode_hash(data_array<Size>& out,
7070
const std::string_view& in) NOEXCEPT;
7171

72-
/// Returns null_hash on error.
72+
/// Throws istream_exception on input error.
7373
template <size_t Size>
74-
constexpr data_array<Size> decode_hash(const std::string_view& in) NOEXCEPT;
74+
constexpr data_array<Size> decode_hash(const std::string_view& in) THROWS;
7575

7676
/// Literal decodings of hex string, errors reflected as zero-filled data.
7777
/// ---------------------------------------------------------------------------

src/config/utilities.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ inline bool make_address(asio::address& ip, const std::string& host) NOEXCEPT
5959
ip = boost::asio::ip::make_address(trim_copy(host, { "[", "]" }));
6060
return true;
6161
}
62-
catch (const std::exception&)
62+
catch (...)
6363
{
6464
return false;
6565
}
@@ -160,7 +160,10 @@ inline asio::address to_v4(const boost::asio::ip::address_v6& ip6) THROWS
160160
{
161161
// Required for equivalence with boost 1.86.
162162
if (!ip6.is_v4_mapped())
163-
throw std::exception{};
163+
{
164+
using namespace boost::asio::detail;
165+
throw_exception(boost::asio::ip::bad_address_cast{});
166+
}
164167

165168
const auto bytes = ip6.to_bytes();
166169
return
@@ -187,7 +190,7 @@ asio::address denormalize(const asio::address& ip) NOEXCEPT
187190
{
188191
return { to_v4(ip.to_v6()) };
189192
}
190-
catch (const std::exception&)
193+
catch (...)
191194
{
192195
return ip;
193196
}
@@ -207,7 +210,7 @@ inline std::string to_host(const boost::asio::ip::address_v6& ip6) NOEXCEPT
207210
return ip6.is_v4_mapped() ? to_host(to_v4(ip6)) : ip6.to_string();
208211
BC_POP_WARNING()
209212
}
210-
catch (const std::exception&)
213+
catch (...)
211214
{
212215
return { "::" };
213216
}
@@ -219,7 +222,7 @@ inline std::string to_host(const boost::asio::ip::address_v4& ip4) NOEXCEPT
219222
{
220223
return ip4.to_string();
221224
}
222-
catch (const std::exception&)
225+
catch (...)
223226
{
224227
return { "0.0.0.0" };
225228
}
@@ -235,7 +238,7 @@ std::string to_host(const asio::address& ip) NOEXCEPT
235238
return host.is_v4() ? to_host(host.to_v4()) : to_host(host.to_v6());
236239
BC_POP_WARNING()
237240
}
238-
catch (const std::exception&)
241+
catch (...)
239242
{
240243
return { "0.0.0.0" };
241244
}
@@ -287,7 +290,7 @@ bool is_member(const asio::address& ip, const asio::address& subnet,
287290
if (ip.is_v6() && subnet.is_v6())
288291
return is_member_v6(ip.to_v6(), subnet.to_v6(), cidr);
289292
}
290-
catch (const std::exception&)
293+
catch (...)
291294
{
292295
}
293296

0 commit comments

Comments
 (0)