Skip to content

Commit

Permalink
feat: changed BoundedString::copy to copy up to length-pos charac…
Browse files Browse the repository at this point in the history
…ters (#779)

* feat: changed BoundedVector::copy to copy up to `length-pos` characters

aligned with standard library behaviour

* chore: removed accidental include of ReallyAssert
  • Loading branch information
daantimmer authored Dec 5, 2024
1 parent 6c84af5 commit 6659905
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion infra/util/BoundedString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,8 @@ namespace infra
template<class T>
typename BoundedStringBase<T>::size_type BoundedStringBase<T>::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;
}
Expand Down
3 changes: 3 additions & 0 deletions infra/util/test/TestBoundedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6659905

Please sign in to comment.