diff --git a/ctrtool/oschar.c b/ctrtool/oschar.c index b712ff2..ac8ddcc 100644 --- a/ctrtool/oschar.c +++ b/ctrtool/oschar.c @@ -152,10 +152,11 @@ char* strcopy_UTF16toUTF8(const utf16char_t *src) return NULL; src_len = utf16_strlen(src); - dst_len = src_len * 2; + // UTF-8 can use up to 3 bytes per UTF-16 code unit, or four for a surrogate pair + dst_len = src_len * 3; // Allocate memory for string - dst = calloc(dst_len, sizeof(char)); // twice the size, as UTF-8 will use up to two bytes for converted UTF16 chars afaik + dst = calloc(dst_len, sizeof(char)); if (!dst) return NULL; @@ -206,4 +207,4 @@ oschar_t* os_AppendUTF16StrToPath(const oschar_t *src, const utf16char_t *add) free(_add); return new_path; -} \ No newline at end of file +} diff --git a/makerom/oschar.c b/makerom/oschar.c index b712ff2..ac8ddcc 100644 --- a/makerom/oschar.c +++ b/makerom/oschar.c @@ -152,10 +152,11 @@ char* strcopy_UTF16toUTF8(const utf16char_t *src) return NULL; src_len = utf16_strlen(src); - dst_len = src_len * 2; + // UTF-8 can use up to 3 bytes per UTF-16 code unit, or four for a surrogate pair + dst_len = src_len * 3; // Allocate memory for string - dst = calloc(dst_len, sizeof(char)); // twice the size, as UTF-8 will use up to two bytes for converted UTF16 chars afaik + dst = calloc(dst_len, sizeof(char)); if (!dst) return NULL; @@ -206,4 +207,4 @@ oschar_t* os_AppendUTF16StrToPath(const oschar_t *src, const utf16char_t *add) free(_add); return new_path; -} \ No newline at end of file +}