Godot Engine – Multi-platform 2D and 3D game engine
Fix String.append_utf32_unchecked undefined behavior with zero span size
Aaron Franke7f1f963fcfb1
diff --git a/core/string/ustring.cpp b/core/string/ustring.cppindex 58fc3022565..6707e72649c 100644--- a/core/string/ustring.cpp+++ b/core/string/ustring.cpp@@ -221,6 +221,10 @@ Error String::append_utf32(const Span<char32_t> &p_cstr) {}void String::append_utf32_unchecked(const Span<char32_t> &p_span) {+ if (unlikely(p_span.size() == 0)) {+ // Nothing to do when empty. Otherwise, calling `memcpy` with a nullptr would be UB.+ return;+ }const int prev_length = length();resize_uninitialized(prev_length + p_span.size() + 1); // + 1 for \0char32_t *dst = ptrw() + prev_length;