diff options
| author | Maxime Coste <mawww@kakoune.org> | 2022-08-21 17:52:51 +0200 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2022-08-21 17:52:51 +0200 |
| commit | d076c033e7fc9d5a5d4dacaab6a8d12b4000c1ab (patch) | |
| tree | dbb84914b90483a4c7d19c7c37901e362e2748f6 /src | |
| parent | efa45f8bddf5b5cc9e0a6ea9695db086b490d591 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/shared_string.cc | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/shared_string.cc b/src/shared_string.cc index d76e0ac3..752ac828 100644 --- a/src/shared_string.cc +++ b/src/shared_string.cc @@ -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(); } |
