[vlc-commits] text: fix decoding of 4-bytes UTF-8 sequences

Rémi Denis-Courmont git at videolan.org
Mon Jun 13 19:31:58 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 13 20:31:15 2016 +0300| [221462198b2e32c74cfcb0d0b5645042d7fb3c79] | committer: Rémi Denis-Courmont

text: fix decoding of 4-bytes UTF-8 sequences

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=221462198b2e32c74cfcb0d0b5645042d7fb3c79
---

 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 2e06ae3..88eb6d2 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -142,7 +142,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:
@@ -154,18 +154,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;
@@ -174,9 +174,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