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

Francois Cartegnie git at videolan.org
Wed Aug 26 10:41:23 CEST 2020


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Aug 25 14:26:40 2020 +0200| [80f916326c90748ffc50ccd2383a2e476bcaf938] | committer: Francois Cartegnie

codec: tx3g: fix cutting utf8 by char index

(cherry picked from commit 452372d1e7a38e3c41ab6129651e315f8a9d4a51)

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

 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 3f43e2f72c..59c1d5e32f 100644
--- a/modules/codec/substx3g.c
+++ b/modules/codec/substx3g.c
@@ -105,19 +105,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