[vlc-commits] iso6937: avoid invalid cast

Rémi Denis-Courmont git at videolan.org
Wed Jun 21 20:03:44 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jun 21 20:55:13 2017 +0300| [f078d29c27d783c26c8e1a1cfa5cd9491ba4f407] | committer: Rémi Denis-Courmont

iso6937: avoid invalid cast

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

 src/extras/libc.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/extras/libc.c b/src/extras/libc.c
index 3389c57d07..cccb469128 100644
--- a/src/extras/libc.c
+++ b/src/extras/libc.c
@@ -229,7 +229,7 @@ static const uint16_t to_ucs4_comb[15][64] =
   }
 };
 
-static size_t ISO6937toUTF8( const unsigned char **inbuf, size_t *inbytesleft,
+static size_t ISO6937toUTF8( const char **inbuf, size_t *inbytesleft,
                              unsigned char **outbuf, size_t *outbytesleft )
 
 
@@ -237,16 +237,17 @@ static size_t ISO6937toUTF8( const unsigned char **inbuf, size_t *inbytesleft,
     if( !inbuf || !(*inbuf) )
         return (size_t)(0);    /* Reset state requested */
 
-    const unsigned char *iptr = *inbuf;
-    const unsigned char *iend = iptr + *inbytesleft;
+    const char *iptr = *inbuf;
+    const char *iend = iptr + *inbytesleft;
     unsigned char *optr = *outbuf;
     unsigned char *oend = optr + *outbytesleft;
-    uint16_t ch;
     int err = 0;
 
     while ( iptr < iend )
     {
-        if( *iptr < 0x80 )
+        unsigned char c1 = *iptr;
+
+        if( c1 < 0x80 )
         {
             if( optr >= oend )
             {
@@ -264,7 +265,7 @@ static size_t ISO6937toUTF8( const unsigned char **inbuf, size_t *inbytesleft,
             break;        /* No space in outbuf for multibyte char */
         }
 
-        ch = to_ucs4[*iptr - 0x80];
+        uint_fast16_t ch = to_ucs4[c1 - 0x80];
 
         if( ch == 0xffff )
         {
@@ -274,8 +275,10 @@ static size_t ISO6937toUTF8( const unsigned char **inbuf, size_t *inbytesleft,
                 err = EINVAL;
                 break;    /* No next character */
             }
-            if ( iptr[1] < 0x40 || iptr[1] >= 0x80 ||
-                 !(ch = to_ucs4_comb[iptr[0] - 0xc1][iptr[1] - 0x40]) )
+
+            unsigned char c2 = iptr[1];
+            if ( c2 < 0x40 || c2 >= 0x80 ||
+                 !(ch = to_ucs4_comb[c1 - 0xc1][c2 - 0x40]) )
             {
                 err = EILSEQ;
                 break;   /* Illegal combination */
@@ -381,7 +384,7 @@ size_t vlc_iconv( vlc_iconv_t cd, const char **inbuf, size_t *inbytesleft,
 {
 #ifndef __linux__
     if ( cd == (vlc_iconv_t)(-2) )
-        return ISO6937toUTF8( (const unsigned char **)inbuf, inbytesleft,
+        return ISO6937toUTF8( inbuf, inbytesleft,
                               (unsigned char **)outbuf, outbytesleft );
 #endif
 #if defined(HAVE_ICONV)



More information about the vlc-commits mailing list