fix(libc): terminate truncated wcsxfrm results

This commit is contained in:
QRMOE 2026-10-12 19:03:18 +02:00 committed by GitHub
parent 2a5eca11cd
commit 22d03d497f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -499,7 +499,11 @@ int APS5_VABI wcscoll_nid_postfix(const char16_t* first, const char16_t* second)
size_t APS5_VABI wcsxfrm_nid_postfix(char16_t* destination, const char16_t* source, size_t count) {
const size_t length = Length(source);
if (length < count) std::memcpy(destination, source, (length + 1) * sizeof(char16_t));
if (count != 0) {
const size_t copied = length < count ? length : count - 1;
std::memcpy(destination, source, copied * sizeof(char16_t));
destination[copied] = 0;
}
return length;
}