Commit 9e8afc94ffae6f7ab9ba77308a9ab53aaf10335e
Committed by
Greg Kroah-Hartman
1 parent
9168b9b4cd
Exists in
smarct4x-processor-sdk-linux-03.00.00.04
and in
2 other branches
lib/ucs2_string: Correct ucs2 -> utf8 conversion
commit a68075908a37850918ad96b056acc9ac4ce1bd90 upstream. The comparisons should be >= since 0x800 and 0x80 require an additional bit to store. For the 3 byte case, the existing shift would drop off 2 more bits than intended. For the 2 byte case, there should be 5 bits bits in byte 1, and 6 bits in byte 2. Signed-off-by: Jason Andryuk <jandryuk@gmail.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Cc: Peter Jones <pjones@redhat.com> Cc: Matthew Garrett <mjg59@coreos.com> Cc: "Lee, Chun-Yi" <jlee@suse.com> Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 7 additions and 7 deletions Side-by-side Diff
lib/ucs2_string.c
... | ... | @@ -59,9 +59,9 @@ |
59 | 59 | for (i = 0; i < ucs2_strlen(src); i++) { |
60 | 60 | u16 c = src[i]; |
61 | 61 | |
62 | - if (c > 0x800) | |
62 | + if (c >= 0x800) | |
63 | 63 | j += 3; |
64 | - else if (c > 0x80) | |
64 | + else if (c >= 0x80) | |
65 | 65 | j += 2; |
66 | 66 | else |
67 | 67 | j += 1; |
68 | 68 | |
69 | 69 | |
70 | 70 | |
... | ... | @@ -88,19 +88,19 @@ |
88 | 88 | for (i = 0; maxlength && i < limit; i++) { |
89 | 89 | u16 c = src[i]; |
90 | 90 | |
91 | - if (c > 0x800) { | |
91 | + if (c >= 0x800) { | |
92 | 92 | if (maxlength < 3) |
93 | 93 | break; |
94 | 94 | maxlength -= 3; |
95 | 95 | dest[j++] = 0xe0 | (c & 0xf000) >> 12; |
96 | - dest[j++] = 0x80 | (c & 0x0fc0) >> 8; | |
96 | + dest[j++] = 0x80 | (c & 0x0fc0) >> 6; | |
97 | 97 | dest[j++] = 0x80 | (c & 0x003f); |
98 | - } else if (c > 0x80) { | |
98 | + } else if (c >= 0x80) { | |
99 | 99 | if (maxlength < 2) |
100 | 100 | break; |
101 | 101 | maxlength -= 2; |
102 | - dest[j++] = 0xc0 | (c & 0xfe0) >> 5; | |
103 | - dest[j++] = 0x80 | (c & 0x01f); | |
102 | + dest[j++] = 0xc0 | (c & 0x7c0) >> 6; | |
103 | + dest[j++] = 0x80 | (c & 0x03f); | |
104 | 104 | } else { |
105 | 105 | maxlength -= 1; |
106 | 106 | dest[j++] = c & 0x7f; |