]> git.sesse.net Git - vlc/commitdiff
mp4: use strndup() where applicable
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 5 May 2012 17:21:42 +0000 (20:21 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 5 May 2012 17:23:01 +0000 (20:23 +0300)
As a side note, this fixes a valgrind heap read overflow, but I do not
see why. I suspect a conflict between valgrind and some optimization in
libc or gcc here.

modules/demux/mp4/libmp4.c

index 2d478c6a3f43f2254a606e3c733fb85446b96643..ec734a611ef447539830782cb9e198840be833c0 100644 (file)
@@ -3609,11 +3609,9 @@ static void get_token( char **ppsz_path, char **ppsz_token, int *pi_number )
     {
         i_len = 1;
     }
-    *ppsz_token = xmalloc( i_len + 1 );
-
-    memcpy( *ppsz_token, *ppsz_path, i_len );
-
-    (*ppsz_token)[i_len] = '\0';
+    *ppsz_token = strndup( *ppsz_path, i_len );
+    if( unlikely(!*ppsz_token) )
+        abort();
 
     *ppsz_path += i_len;