Skip to content

Commit f963383

Browse files
committed
fix: url_view memcpy with null source when size is zero
1 parent d42c748 commit f963383

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

include/boost/url/impl/url_view.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ persist() const
6767
auto p = std::allocate_shared<T>(
6868
detail::over_allocator<T, Alloc>(
6969
size(), a), url_view(impl()));
70-
std::memcpy(
71-
reinterpret_cast<char*>(
72-
p.get() + 1), data(), size());
70+
if(size())
71+
std::memcpy(
72+
reinterpret_cast<char*>(
73+
p.get() + 1), data(), size());
7374
return p;
7475
}
7576

test/unit/url_view.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ class url_view_test
217217
}
218218
}
219219

220+
// persist() with null data() and zero size()
221+
{
222+
url_view u;
223+
BOOST_TEST(u.empty());
224+
auto sp = u.persist();
225+
BOOST_TEST(sp->empty());
226+
BOOST_TEST_EQ(sp->size(), 0u);
227+
BOOST_TEST_EQ(sp->buffer(), "");
228+
}
229+
220230
// operator core::string_view()
221231
{
222232
auto const f = []( core::string_view ) {};

0 commit comments

Comments
 (0)