diff --git a/infra/util/BoundedString.hpp b/infra/util/BoundedString.hpp index 3b4755f33..22d8f906f 100644 --- a/infra/util/BoundedString.hpp +++ b/infra/util/BoundedString.hpp @@ -1081,7 +1081,8 @@ namespace infra template typename BoundedStringBase::size_type BoundedStringBase::copy(char* dest, size_type count, size_type pos) { - assert(pos + count <= length); + assert(pos <= length); + count = std::min(count, length - pos); std::copy(begin() + pos, begin() + pos + count, dest); return count; } diff --git a/infra/util/test/TestBoundedString.cpp b/infra/util/test/TestBoundedString.cpp index ebf976709..9f8392660 100644 --- a/infra/util/test/TestBoundedString.cpp +++ b/infra/util/test/TestBoundedString.cpp @@ -587,6 +587,9 @@ TEST(BoundedStringTest, TestCopy) infra::BoundedString::WithStorage<5> string("abcde"); EXPECT_EQ(3, string.copy(buffer, 3, 1)); EXPECT_EQ('b', buffer[0]); + + EXPECT_EQ(2, string.copy(buffer, 5, 3)); + EXPECT_EQ('d', buffer[0]); } TEST(BoundedStringTest, TestResize)