From c9910e30ee46cce759c031fbddb38e730be266fd Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Sat, 1 Feb 2020 13:59:06 -0500 Subject: [PATCH] Throw when pos2 is out of range --- include/boost/static_string/detail/static_string.hpp | 2 +- include/boost/static_string/static_string.hpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/static_string/detail/static_string.hpp b/include/boost/static_string/detail/static_string.hpp index 9bd4b1f..ed54831 100644 --- a/include/boost/static_string/detail/static_string.hpp +++ b/include/boost/static_string/detail/static_string.hpp @@ -45,7 +45,7 @@ using smallest_width = template 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(std::declval()))> struct is_nothrow_convertible_msvc_helper diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index b555542..037ac15 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -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)); }