Skip to content

Commit

Permalink
Increase the temporal buffer size for Unicode support
Browse files Browse the repository at this point in the history
Although the maximum size of one character in UTF-16 is 4bytes,
sizeof(wchar_t) is 2bytes on Windows.
Also, non-ASCII characters requires 2bytes in ANSI code page.
The existing buffer size is insufficient.
  • Loading branch information
chikuzen authored and astrataro committed Jul 11, 2014
1 parent e88e2d5 commit 94e98cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions common/osdep.c
Expand Up @@ -143,7 +143,7 @@ void x264_intel_cpu_indicator_init( void )
/* Functions for dealing with Unicode on Windows. */
FILE *x264_fopen( const char *filename, const char *mode )
{
wchar_t filename_utf16[MAX_PATH];
wchar_t filename_utf16[MAX_PATH * 2];
wchar_t mode_utf16[16];
if( utf8_to_utf16( filename, filename_utf16 ) && utf8_to_utf16( mode, mode_utf16 ) )
return _wfopen( filename_utf16, mode_utf16 );
Expand All @@ -152,8 +152,8 @@ FILE *x264_fopen( const char *filename, const char *mode )

int x264_rename( const char *oldname, const char *newname )
{
wchar_t oldname_utf16[MAX_PATH];
wchar_t newname_utf16[MAX_PATH];
wchar_t oldname_utf16[MAX_PATH * 2];
wchar_t newname_utf16[MAX_PATH * 2];
if( utf8_to_utf16( oldname, oldname_utf16 ) && utf8_to_utf16( newname, newname_utf16 ) )
{
/* POSIX says that rename() removes the destination, but Win32 doesn't. */
Expand All @@ -165,7 +165,7 @@ int x264_rename( const char *oldname, const char *newname )

int x264_stat( const char *path, x264_struct_stat *buf )
{
wchar_t path_utf16[MAX_PATH];
wchar_t path_utf16[MAX_PATH * 2];
if( utf8_to_utf16( path, path_utf16 ) )
return _wstati64( path_utf16, buf );
return -1;
Expand Down
4 changes: 2 additions & 2 deletions input/avs.c
Expand Up @@ -213,8 +213,8 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c

#ifdef _WIN32
/* Avisynth doesn't support Unicode filenames. */
char ansi_filename[MAX_PATH];
FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 0 ), "invalid ansi filename\n" );
char ansi_filename[MAX_PATH * 2];
FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH * 2, 0 ), "invalid ansi filename\n" );
AVS_Value arg = avs_new_value_string( ansi_filename );
#else
AVS_Value arg = avs_new_value_string( psz_filename );
Expand Down
8 changes: 4 additions & 4 deletions input/ffms.c
Expand Up @@ -94,11 +94,11 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
#ifdef __MINGW32__
/* FFMS supports UTF-8 filenames, but it uses std::fstream internally which is broken with Unicode in MinGW. */
FFMS_Init( 0, 0 );
char src_filename[MAX_PATH];
char idx_filename[MAX_PATH];
FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, src_filename, MAX_PATH, 0 ), "invalid ansi filename\n" );
char src_filename[MAX_PATH * 2];
char idx_filename[MAX_PATH * 2];
FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, src_filename, MAX_PATH * 2, 0 ), "invalid ansi filename\n" );
if( opt->index_file )
FAIL_IF_ERROR( !x264_ansi_filename( opt->index_file, idx_filename, MAX_PATH, 1 ), "invalid ansi filename\n" );
FAIL_IF_ERROR( !x264_ansi_filename( opt->index_file, idx_filename, MAX_PATH * 2, 1 ), "invalid ansi filename\n" );
#else
FFMS_Init( 0, 1 );
char *src_filename = psz_filename;
Expand Down
4 changes: 2 additions & 2 deletions output/mp4.c
Expand Up @@ -181,8 +181,8 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt

#ifdef _WIN32
/* GPAC doesn't support Unicode filenames. */
char ansi_filename[MAX_PATH];
FAIL_IF_ERR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 1 ), "mp4", "invalid ansi filename\n" )
char ansi_filename[MAX_PATH * 2];
FAIL_IF_ERR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH * 2, 1 ), "mp4", "invalid ansi filename\n" )
p_mp4->p_file = gf_isom_open( ansi_filename, GF_ISOM_OPEN_WRITE, NULL );
#else
p_mp4->p_file = gf_isom_open( psz_filename, GF_ISOM_OPEN_WRITE, NULL );
Expand Down

0 comments on commit 94e98cb

Please sign in to comment.