Commit 71e6138b authored by Jean-Paul Saman's avatar Jean-Paul Saman

Backport of rev [19271]

parent 86287891
......@@ -92,7 +92,6 @@ char *vlc_strndup( const char *string, size_t n )
len = __MIN( len, n );
psz = (char*)malloc( len + 1 );
if( psz != NULL )
{
memcpy( (void*)psz, (const void*)string, len );
......@@ -250,10 +249,12 @@ int vlc_asprintf( char **strp, const char *fmt, ... )
double vlc_atof( const char *nptr )
{
double f_result;
wchar_t *psz_tmp;
wchar_t *psz_tmp = NULL;
int i_len = strlen( nptr ) + 1;
psz_tmp = malloc( i_len * sizeof(wchar_t) );
if( !psz_tmp )
return NULL;
MultiByteToWideChar( CP_ACP, 0, nptr, -1, psz_tmp, i_len );
f_result = wcstod( psz_tmp, NULL );
free( psz_tmp );
......@@ -403,14 +404,16 @@ typedef struct vlc_DIR
void *vlc_opendir_wrapper( const char *psz_path )
{
vlc_DIR *p_dir;
DIR *p_real_dir;
vlc_DIR *p_dir = NULL;
DIR *p_real_dir = NULL;
if ( psz_path == NULL || psz_path[0] == '\0'
|| (psz_path[0] == '\\' && psz_path[1] == '\0') )
{
/* Special mode to list drive letters */
p_dir = malloc( sizeof(vlc_DIR) );
if( !p_dir )
return NULL;
p_dir->p_real_dir = NULL;
p_dir->i_drives = GetLogicalDrives();
return (void *)p_dir;
......@@ -421,6 +424,11 @@ void *vlc_opendir_wrapper( const char *psz_path )
return NULL;
p_dir = malloc( sizeof(vlc_DIR) );
if( !p_dir )
{
_wclosedir( p_real_dir );
return NULL;
}
p_dir->p_real_dir = p_real_dir;
p_dir->b_insert_back = ( psz_path[1] == ':' && psz_path[2] == '\\'
&& psz_path[3] =='\0' );
......@@ -526,8 +534,19 @@ int vlc_scandir( const char *name, struct dirent ***namelist,
pp_list = realloc( pp_list, ( ret + 1 ) * sizeof( struct dirent * ) );
size = sizeof( struct dirent ) + strlen( p_content->d_name ) + 1;
pp_list[ret] = malloc( size );
memcpy( pp_list[ret], p_content, size );
ret++;
if( pp_list[ret] )
{
memcpy( pp_list[ret], p_content, size );
ret++;
}
else
{
/* Continuing is useless when no more memory can be allocted,
* so better return what we have found.
*/
ret = -1;
break;
}
}
vlc_closedir_wrapper( p_dir );
......@@ -912,7 +931,12 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
close( pi_stdin[0] );
*pi_data = 0;
if( *pp_data )
free( *pp_data );
*pp_data = NULL;
*pp_data = malloc( 1025 ); /* +1 for \0 */
if( !*pp_data )
return -1;
while ( !p_object->b_die )
{
......@@ -996,7 +1020,7 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
BOOL bFuncRetn = FALSE;
HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr;
DWORD i_status;
char *psz_cmd, *p_env, *p;
char *psz_cmd = NULL, *p_env = NULL, *p = NULL;
char **ppsz_parser;
int i_size;
......@@ -1039,6 +1063,8 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
/* Set up the command line. */
psz_cmd = malloc(32768);
if( !psz_cmd )
return -1;
psz_cmd[0] = '\0';
i_size = 32768;
ppsz_parser = &ppsz_argv[0];
......@@ -1066,6 +1092,12 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
/* Set up the environment. */
p = p_env = malloc(32768);
if( !p )
{
free( psz_cmd );
return -1;
}
i_size = 32768;
ppsz_parser = &ppsz_env[0];
while ( *ppsz_parser != NULL && i_size > 0 )
......@@ -1118,6 +1150,9 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
/* Read output from the child process. */
*pi_data = 0;
if( *pp_data )
free( pp_data );
*pp_data = NULL;
*pp_data = malloc( 1025 ); /* +1 for \0 */
while ( !p_object->b_die )
......@@ -1151,6 +1186,5 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
#endif
(*pp_data)[*pi_data] = '\0';
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment