macOS: properly handle buffer in zh locale canonicalization

This commit is contained in:
Aaron Ruan
2025-08-05 22:56:28 +08:00
parent f0272e5fec
commit c1060d56b3

View File

@@ -133,7 +133,12 @@ pub fn canonicalizeLocale(
locale: []const u8,
) error{NoSpaceLeft}![:0]const u8 {
// Fix zh locales for macOS
if (fixZhLocale(locale)) |fixed| return fixed;
if (fixZhLocale(locale)) |fixed| {
if (buf.len < fixed.len + 1) return error.NoSpaceLeft;
@memcpy(buf[0..fixed.len], fixed);
buf[fixed.len] = 0;
return buf[0..fixed.len :0];
}
// Buffer must be 16 or at least as long as the locale and null term
if (buf.len < @max(16, locale.len + 1)) return error.NoSpaceLeft;