From f64a4e9931428de0f308f6ed0a0144edb8ce9619 Mon Sep 17 00:00:00 2001 From: Martin Herkt Date: Sat, 28 Apr 2012 17:37:01 +0200 Subject: [PATCH] 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. --- path.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/path.c b/path.c index 785c48eec9..e51c4c9c34 100644 --- a/path.c +++ b/path.c @@ -55,6 +55,9 @@ char *get_path(const char *filename){ static char *config_dir = "/mplayer"; #else static char *config_dir = "/.mplayer"; +#endif +#if defined(__MINGW32__) || defined(__CYGWIN__) + char exedir[260]; #endif int len; #ifdef CONFIG_MACOSX_BUNDLE @@ -73,9 +76,8 @@ char *get_path(const char *filename){ /* Hack to get fonts etc. loaded outside of Cygwin environment. */ { int i,imax=0; - char exedir[260]; - GetModuleFileNameA(NULL, exedir, 260); - for (i=0; i< strlen(exedir); i++) + len = (int)GetModuleFileNameA(NULL, exedir, 260); + for (i=0; i < len; i++) if (exedir[i] =='\\') {exedir[i]='/'; imax=i;} exedir[imax]='\0';