[vlc-commits] codec: tx3g: fix cutting utf8 by char index

Francois Cartegnie git at videolan.org
Tue Aug 25 16:16:42 CEST 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Aug 25 14:26:40 2020 +0200| [452372d1e7a38e3c41ab6129651e315f8a9d4a51] | committer: Francois Cartegnie

codec: tx3g: fix cutting utf8 by char index

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

 modules/codec/substx3g.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/modules/codec/substx3g.c b/modules/codec/substx3g.c
index f7639b386c..8315f1e194 100644
--- a/modules/codec/substx3g.c
+++ b/modules/codec/substx3g.c
@@ -96,19 +96,22 @@ static size_t str8len( const char *psz_string )
 
 static char * str8indup( const char *psz_string, size_t i_skip, size_t n )
 {
-    while( i_skip && *psz_string )
+    for( size_t i = 0; i< i_skip && *psz_string; i++ )
     {
-        if ( (*psz_string & 0xC0) != 0x80 ) i_skip--;
-        psz_string++;
+        while( *(++psz_string) && (*psz_string & 0xC0) == 0x80 )
+        {};
     }
-    if ( ! *psz_string || i_skip ) return NULL;
+
+    if ( ! *psz_string )
+        return NULL;
 
     const char *psz_tmp = psz_string;
-    while( n && *psz_tmp )
+    for( size_t i = 0; i < n && *psz_tmp; i++ )
     {
-        if ( (*psz_tmp & 0xC0) != 0x80 ) n--;
-        psz_tmp++;
+        while( *(++psz_tmp) && (*psz_tmp & 0xC0) == 0x80 )
+        {};
     }
+
     return strndup( psz_string, psz_tmp - psz_string );
 }
 



More information about the vlc-commits mailing list