usb-mtp: fix utf16_to_str
commit6de02a13232a84261bd2d5e07013d6e6572cd60f
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 3 Dec 2018 10:10:44 +0000 (3 11:10 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 3 Dec 2018 18:39:04 +0000 (3 19:39 +0100)
treeae9180f0a0f5c575f45ffff859670b5534ed0f77
parent039d4e3df0049bdd8f93a2de735a816483b13954
usb-mtp: fix utf16_to_str

Make utf16_to_str return an allocated string.  Remove the assumtion that
the number of string bytes equals the number of utf16 chars (which is
only true for ascii chars).  Instead call wcstombs twice, once to figure
the storage size and once for the actual conversion (as suggested by the
wcstombs manpage).

FIXME: surrogate pairs are not working correctly.  Pre-existing bug,
fixing that is left for another day.

Reported-by: Michael Hanselmann <public@hansmi.ch>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-id: 20181203101045.27976-2-kraxel@redhat.com
hw/usb/dev-mtp.c