Throw when pos2 is out of range

This commit is contained in:
Krystian Stasiowski
2020-02-01 13:59:06 -05:00
parent 7d198aa043
commit c9910e30ee
2 changed files with 10 additions and 1 deletions

View File

@ -45,7 +45,7 @@ using smallest_width =
template<typename To>
void is_nothrow_convertible_helper(To) noexcept;
// MSVC is unable to parse this inline, so a helper is needed
// MSVC is unable to parse this as a single expression, so a helper is needed
template<typename From, typename To, typename =
decltype(is_nothrow_convertible_helper<To>(std::declval<From>()))>
struct is_nothrow_convertible_msvc_helper

View File

@ -953,6 +953,9 @@ public:
size_type index_str,
size_type count = npos) BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT
{
BOOST_STATIC_STRING_THROW_IF(
index_str > str.size(), std::out_of_range{"index_str > str.size()"}
);
return insert(index, str.data() + index_str, (std::min)(count, str.size() - index_str));
}
@ -1967,6 +1970,9 @@ public:
size_type pos2,
size_type n2 = npos) BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT
{
BOOST_STATIC_STRING_THROW_IF(
pos2 > str.size(), std::out_of_range{"pos2 > str.size()"}
);
return replace(pos1, n1, str.data() + pos2, (std::min)(n2, str.size() - pos2));
}
@ -2010,6 +2016,9 @@ public:
size_type pos2,
size_type n2 = npos) BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT
{
BOOST_STATIC_STRING_THROW_IF(
pos2 > str.size(), std::out_of_range{"pos2 > str.size()"}
);
return replace_unchecked(pos1, n1, str.data() + pos2, (std::min)(n2, str.size() - pos2));
}