diff --git a/include/boost/fixed_string/impl/fixed_string.hpp b/include/boost/fixed_string/impl/fixed_string.hpp index d5d3bfb..dd2a17f 100644 --- a/include/boost/fixed_string/impl/fixed_string.hpp +++ b/include/boost/fixed_string/impl/fixed_string.hpp @@ -320,7 +320,7 @@ insert( BOOST_FIXED_STRING_THROW(std::length_error{ "size() + count > max_size()"}); const bool inside = s <= &s_[size()] && s >= &s_[0]; - if (!inside || (inside && (&s[count - 1] < &s_[index]))) + if (!inside || (inside && ((s - s_) + count <= index))) { Traits::move(&s_[index + count], &s_[index], size() - index + 1); Traits::copy(&s_[index], s, count); @@ -597,7 +597,7 @@ replace( const bool inside = s <= &s_[size()] && s >= &s_[0]; if (inside && (s - &s_[0]) == pos && n1 == n2) return *this; - if (!inside || (inside && (&s[n2 - 1] < &s_[pos]))) + if (!inside || (inside && ((s - s_) + n2 <= pos))) { // source outside Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1); diff --git a/test/fixed_string.cpp b/test/fixed_string.cpp index 65cfd2f..b0d05c3 100644 --- a/test/fixed_string.cpp +++ b/test/fixed_string.cpp @@ -23,7 +23,7 @@ testS(const S& s, typename S::size_type pos, typename S::size_type n) if (pos <= s.size()) { typename S::string_view_type str = s.substr(pos, n); - typename S::size_type rlen = std::min(n, s.size() - pos); + typename S::size_type rlen = (std::min)(n, s.size() - pos); return (S::traits_type::compare(s.data() + pos, str.data(), rlen) == 0); } else @@ -319,6 +319,10 @@ testAssignment() BOOST_TEST(fixed_string<3>{}.assign(fixed_string<5>{"abc"}) == "abc"); BOOST_TEST(fixed_string<3>{"*"}.assign(fixed_string<5>{"abc"}) == "abc"); BOOST_TEST(fixed_string<3>{"***"}.assign(fixed_string<5>{"abc"}) == "abc"); + { + fixed_string<3> s("***"); + BOOST_TEST(s.assign(s) == s); + } BOOST_TEST_THROWS(fixed_string<3>{}.assign(fixed_string<5>{"abcde"}), std::length_error); // assign(fixed_string const& s, size_type pos, size_type count = npos) @@ -5685,6 +5689,10 @@ testReplace() fixed_string<20> fs2 = "0123456789"; BOOST_TEST(fs2.replace(0, 10, fs2.data(), 5) == "01234"); } + { + fixed_string<20> fs1 = "helloworld"; + BOOST_TEST(fs1.replace(4, 3, fs1.data() + 1, 3) == "hellellrld"); + } // replace(size_type pos1, size_type n1, const basic_string& str); {