Transform grub_fat_label() function to use grub_utf16_to_utf8_alloc() helper function to convert volume label from UTF-16 to UTF-8.
Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmic...@rtsoft.de> --- grub-core/fs/fat.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 24d0b629b..64e9be80d 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -1157,23 +1157,19 @@ grub_fat_label (grub_device_t device, char **label) /* Volume label. */ if (dir.entry_type == 0x83) { + grub_uint8_t *p; grub_size_t chc; - grub_uint16_t t[ARRAY_SIZE (dir.type_specific.volume_label.str)]; - grub_size_t i; - *label = grub_malloc (ARRAY_SIZE (dir.type_specific.volume_label.str) - * GRUB_MAX_UTF8_PER_UTF16 + 1); - if (!*label) + + chc = grub_min(dir.type_specific.volume_label.character_count, + ARRAY_SIZE (dir.type_specific.volume_label.str)); + p = grub_utf16_to_utf8_alloc (dir.type_specific.volume_label.str, + chc, UTF16_LE); + if (!p) { grub_free (root.data); return grub_errno; } - chc = dir.type_specific.volume_label.character_count; - if (chc > ARRAY_SIZE (dir.type_specific.volume_label.str)) - chc = ARRAY_SIZE (dir.type_specific.volume_label.str); - for (i = 0; i < chc; i++) - t[i] = grub_le_to_cpu16 (dir.type_specific.volume_label.str[i]); - *grub_utf16_to_utf8 ((grub_uint8_t *) *label, t, - chc, UTF16_CPU) = '\0'; + *label = (char *) p; } } -- 2.34.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel