[vlc-commits] text: fix decoding of 4-bytes UTF-8 sequences
Rémi Denis-Courmont
git at videolan.org
Mon Jun 13 19:58:04 CEST 2016
vlc/vlc-2.2 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 13 20:31:15 2016 +0300| [b6e93c1cdf2087aeba99b634235212a39bfa5952] | committer: Rémi Denis-Courmont
text: fix decoding of 4-bytes UTF-8 sequences
(cherry picked from commit 221462198b2e32c74cfcb0d0b5645042d7fb3c79)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=b6e93c1cdf2087aeba99b634235212a39bfa5952
---
src/text/unicode.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/text/unicode.c b/src/text/unicode.c
index 25215d7..64c8573 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -151,7 +151,7 @@ size_t vlc_towc (const char *str, uint32_t *restrict pwc)
break;
case 4:
- cp = (c & 0x07) << 16;
+ cp = (c & 0x07) << 18;
break;
default:
@@ -163,18 +163,18 @@ size_t vlc_towc (const char *str, uint32_t *restrict pwc)
{
case 4:
c = *++ptr;
- if (unlikely((c >> 6) != 2)) // not a continuation byte
+ if (unlikely((c & 0xC0) != 0x80)) // not a continuation byte
return -1;
- cp |= (c & 0x3f) << 12;
+ cp |= (c & 0x3F) << 12;
if (unlikely(cp >= 0x110000)) // beyond Unicode range
return -1;
/* fall through */
case 3:
c = *++ptr;
- if (unlikely((c >> 6) != 2)) // not a continuation byte
+ if (unlikely((c & 0xC0) != 0x80)) // not a continuation byte
return -1;
- cp |= (c & 0x3f) << 6;
+ cp |= (c & 0x3F) << 6;
if (unlikely(cp >= 0xD800 && cp < 0xE000)) // UTF-16 surrogate
return -1;
@@ -183,9 +183,9 @@ size_t vlc_towc (const char *str, uint32_t *restrict pwc)
/* fall through */
case 2:
c = *++ptr;
- if (unlikely((c >> 6) != 2)) // not a continuation byte
+ if (unlikely((c & 0xC0) != 0x80)) // not a continuation byte
return -1;
- cp |= (c & 0x3f);
+ cp |= (c & 0x3F);
break;
}
More information about the vlc-commits
mailing list