]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* commands/usbtest.c (grub_usb_get_string): Properly support UTF-16.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 23 May 2010 12:37:28 +0000 (14:37 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 23 May 2010 12:37:28 +0000 (14:37 +0200)
ChangeLog
commands/usbtest.c

index 39a658288f967b1001d4a40708f7af465efef98f..01d2dbf7c9ca114e671054153f0b7eb27c564cc3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-05-23  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * commands/usbtest.c (grub_usb_get_string): Properly support UTF-16.
+
 2010-05-23  Vladimir Serbinenko  <phcoder@gmail.com>
 
        cmostest support.
index b884a93f14a215794e81b8aa50dd9ab89ae7fd2c..191c4e4df599c9165bbab40bc581ad9b3e24681d 100644 (file)
@@ -83,15 +83,24 @@ grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid,
                              0x06, (3 << 8) | index,
                              langid, descstr.length, (char *) descstrp);
 
-  *string = grub_malloc (descstr.length / 2);
+  if (descstrp->length == 0)
+    {
+      grub_free (descstrp);
+      *string = grub_strdup ("");
+      if (! *string)
+       return GRUB_USB_ERR_INTERNAL;
+      return GRUB_USB_ERR_NONE;
+    }
+
+  *string = grub_malloc (descstr.length * 2 + 1);
   if (! *string)
     {
       grub_free (descstrp);
       return GRUB_USB_ERR_INTERNAL;
     }
 
-  grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str, descstrp->length / 2 - 1);
-  (*string)[descstr.length / 2 - 1] = '\0';
+  *grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str,
+                      descstrp->length / 2 - 1) = 0;
   grub_free (descstrp);
 
   return GRUB_USB_ERR_NONE;