Avoid calling memcpy from empty string views

ubsan is unhappy when passing a nullptr as the source pointer to
memcpy even if the length is 0.

Fixes #4720
This commit is contained in:
Maxime Coste 2022-08-21 17:52:51 +02:00
parent efa45f8bdd
commit d076c033e7

View File

@ -16,6 +16,8 @@ StringDataPtr StringData::create(ArrayView<const StringView> strs)
auto* data = reinterpret_cast<char*>(res + 1);
for (auto& str : strs)
{
if (str.length() == 0) // memccpy(..., nullptr, 0) is UB
continue;
memcpy(data, str.begin(), (size_t)str.length());
data += (int)str.length();
}