grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 16/16] fs/ntfs: Simplify to use grub_utf16_to_utf8_alloc()


From: Vladimir 'phcoder' Serbinenko
Subject: Re: [PATCH v5 16/16] fs/ntfs: Simplify to use grub_utf16_to_utf8_alloc()
Date: Tue, 22 Aug 2023 23:48:08 +0200

Would it be easier to change all call sites to use utf16_to_utf8_alloc?

Le mar. 22 août 2023, 23:40, Vitaly Kuzmichev <vitaly.kuzmichev@rtsoft.de> a écrit :
Transform get_utf8() function to use grub_utf16_to_utf8_alloc()
helper function to convert strings from UTF-16 to UTF-8.

Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmichev@rtsoft.de>
---
 grub-core/fs/ntfs.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c
index 1bee35e87..9258ea835 100644
--- a/grub-core/fs/ntfs.c
+++ b/grub-core/fs/ntfs.c
@@ -552,23 +552,7 @@ free_file (struct grub_ntfs_file *mft)
 static char *
 get_utf8 (grub_uint8_t *in, grub_size_t len)
 {
-  grub_uint8_t *buf;
-  grub_uint16_t *tmp;
-  grub_size_t i;
-
-  buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1);
-  tmp = grub_calloc (len, sizeof (tmp[0]));
-  if (!buf || !tmp)
-    {
-      grub_free (buf);
-      grub_free (tmp);
-      return NULL;
-    }
-  for (i = 0; i < len; i++)
-    tmp[i] = grub_le_to_cpu16 (grub_get_unaligned16 (in + 2 * i));
-  *grub_utf16_to_utf8 (buf, tmp, len, UTF16_CPU) = '\0';
-  grub_free (tmp);
-  return (char *) buf;
+  return (char *) grub_utf16_to_utf8_alloc (in, len, UTF16_LE);
 }

 static int
--
2.34.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]