1 From a68075908a37850918ad96b056acc9ac4ce1bd90 Mon Sep 17 00:00:00 2001
2 From: Jason Andryuk <jandryuk@gmail.com>
3 Date: Fri, 12 Feb 2016 23:13:33 +0000
4 Subject: lib/ucs2_string: Correct ucs2 -> utf8 conversion
6 From: Jason Andryuk <jandryuk@gmail.com>
8 commit a68075908a37850918ad96b056acc9ac4ce1bd90 upstream.
10 The comparisons should be >= since 0x800 and 0x80 require an additional bit
13 For the 3 byte case, the existing shift would drop off 2 more bits than
16 For the 2 byte case, there should be 5 bits bits in byte 1, and 6 bits in
19 Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
20 Reviewed-by: Laszlo Ersek <lersek@redhat.com>
21 Cc: Peter Jones <pjones@redhat.com>
22 Cc: Matthew Garrett <mjg59@coreos.com>
23 Cc: "Lee, Chun-Yi" <jlee@suse.com>
24 Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 lib/ucs2_string.c | 14 +++++++-------
29 1 file changed, 7 insertions(+), 7 deletions(-)
31 --- a/lib/ucs2_string.c
32 +++ b/lib/ucs2_string.c
33 @@ -59,9 +59,9 @@ ucs2_utf8size(const ucs2_char_t *src)
34 for (i = 0; i < ucs2_strlen(src); i++) {
45 @@ -88,19 +88,19 @@ ucs2_as_utf8(u8 *dest, const ucs2_char_t
46 for (i = 0; maxlength && i < limit; i++) {
54 dest[j++] = 0xe0 | (c & 0xf000) >> 12;
55 - dest[j++] = 0x80 | (c & 0x0fc0) >> 8;
56 + dest[j++] = 0x80 | (c & 0x0fc0) >> 6;
57 dest[j++] = 0x80 | (c & 0x003f);
58 - } else if (c > 0x80) {
59 + } else if (c >= 0x80) {
63 - dest[j++] = 0xc0 | (c & 0xfe0) >> 5;
64 - dest[j++] = 0x80 | (c & 0x01f);
65 + dest[j++] = 0xc0 | (c & 0x7c0) >> 6;
66 + dest[j++] = 0x80 | (c & 0x03f);