Skip to content

Commit f64a4e9

Browse files
Martin HerktUoti Urpala
Martin Herkt
authored and
Uoti Urpala
committed
win32: get_path(): fix undefined behavior
MSWindows-specific code in get_path() declared a stack array (exedir[]) in an inner scope, then kept a reference to the array beyond the end of the that scope. Fix. This caused visible breakage with GCC 4.7.
1 parent 66e0426 commit f64a4e9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

path.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ char *get_path(const char *filename){
5555
static char *config_dir = "/mplayer";
5656
#else
5757
static char *config_dir = "/.mplayer";
58+
#endif
59+
#if defined(__MINGW32__) || defined(__CYGWIN__)
60+
char exedir[260];
5861
#endif
5962
int len;
6063
#ifdef CONFIG_MACOSX_BUNDLE
@@ -73,9 +76,8 @@ char *get_path(const char *filename){
7376
/* Hack to get fonts etc. loaded outside of Cygwin environment. */
7477
{
7578
int i,imax=0;
76-
char exedir[260];
77-
GetModuleFileNameA(NULL, exedir, 260);
78-
for (i=0; i< strlen(exedir); i++)
79+
len = (int)GetModuleFileNameA(NULL, exedir, 260);
80+
for (i=0; i < len; i++)
7981
if (exedir[i] =='\\')
8082
{exedir[i]='/'; imax=i;}
8183
exedir[imax]='\0';

0 commit comments

Comments
 (0)