From fa86223475353cc994cc2563ba5aecc406d00815 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 17 Dec 2024 22:31:38 +0100 Subject: [PATCH] refactor: Avoid passing span iterators when data pointers are expected For Span, iterators are just raw data pointers. However, for std::span they are not. This change makes it explicit where data pointers are expected. Otherwise, there could be a compile error later on: No known conversion from 'iterator' (aka '__normal_iterator>') to 'std::byte *'. --- src/script/miniscript.h | 8 ++++---- src/streams.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/script/miniscript.h b/src/script/miniscript.h index e739d8031f2..75f978457c5 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -1798,7 +1798,7 @@ inline NodeRef Parse(Span in, const Ctx& ctx) // Get threshold int next_comma = FindNextChar(in, ','); if (next_comma < 1) return false; - const auto k_to_integral{ToIntegral(std::string_view(in.begin(), next_comma))}; + const auto k_to_integral{ToIntegral(std::string_view(in.data(), next_comma))}; if (!k_to_integral.has_value()) return false; const int64_t k{k_to_integral.value()}; in = in.subspan(next_comma + 1); @@ -1954,7 +1954,7 @@ inline NodeRef Parse(Span in, const Ctx& ctx) } else if (Const("after(", in)) { int arg_size = FindNextChar(in, ')'); if (arg_size < 1) return {}; - const auto num{ToIntegral(std::string_view(in.begin(), arg_size))}; + const auto num{ToIntegral(std::string_view(in.data(), arg_size))}; if (!num.has_value() || *num < 1 || *num >= 0x80000000L) return {}; constructed.push_back(MakeNodeRef(internal::NoDupCheck{}, ctx.MsContext(), Fragment::AFTER, *num)); in = in.subspan(arg_size + 1); @@ -1962,7 +1962,7 @@ inline NodeRef Parse(Span in, const Ctx& ctx) } else if (Const("older(", in)) { int arg_size = FindNextChar(in, ')'); if (arg_size < 1) return {}; - const auto num{ToIntegral(std::string_view(in.begin(), arg_size))}; + const auto num{ToIntegral(std::string_view(in.data(), arg_size))}; if (!num.has_value() || *num < 1 || *num >= 0x80000000L) return {}; constructed.push_back(MakeNodeRef(internal::NoDupCheck{}, ctx.MsContext(), Fragment::OLDER, *num)); in = in.subspan(arg_size + 1); @@ -1974,7 +1974,7 @@ inline NodeRef Parse(Span in, const Ctx& ctx) } else if (Const("thresh(", in)) { int next_comma = FindNextChar(in, ','); if (next_comma < 1) return {}; - const auto k{ToIntegral(std::string_view(in.begin(), next_comma))}; + const auto k{ToIntegral(std::string_view(in.data(), next_comma))}; if (!k.has_value() || *k < 1) return {}; in = in.subspan(next_comma + 1); // n = 1 here because we read the first WRAPPED_EXPR before reaching THRESH diff --git a/src/streams.h b/src/streams.h index 64dbfbff145..e5316da7e70 100644 --- a/src/streams.h +++ b/src/streams.h @@ -79,7 +79,7 @@ public: memcpy(vchData.data() + nPos, src.data(), nOverwrite); } if (nOverwrite < src.size()) { - vchData.insert(vchData.end(), UCharCast(src.data()) + nOverwrite, UCharCast(src.end())); + vchData.insert(vchData.end(), UCharCast(src.data()) + nOverwrite, UCharCast(src.data() + src.size())); } nPos += src.size(); }