From 935c7d0e2c7936a11d9e84fbb6fb1094778d0108 Mon Sep 17 00:00:00 2001 From: toshixm Date: Sun, 30 May 2021 09:17:06 +0900 Subject: [PATCH 1/2] use _wfullpath() instead of _fullpath() --- libretro-common/file/file_path.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index d8cbd5e5c0..127c71ebea 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -638,16 +638,31 @@ bool path_is_absolute(const char *path) char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks) { #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) - char tmp[PATH_MAX_LENGTH]; #ifdef _WIN32 - strlcpy(tmp, buf, sizeof(tmp)); - if (!_fullpath(buf, tmp, size)) + char *ret = NULL; + wchar_t *abs_path = (wchar_t *)malloc(PATH_MAX_LENGTH * sizeof(wchar_t)); + wchar_t *rel_path = utf8_to_utf16_string_alloc(buf); + + if (abs_path && rel_path && _wfullpath(abs_path, rel_path, PATH_MAX_LENGTH)) { - strlcpy(buf, tmp, size); - return NULL; + char *tmp = utf16_to_utf8_string_alloc(abs_path); + + if (tmp) + { + strlcpy(buf, tmp, size); + free(tmp); + ret = buf; + } } - return buf; + + if (rel_path) + free(rel_path); + if (abs_path) + free(abs_path); + + return ret; #else + char tmp[PATH_MAX_LENGTH]; size_t t; char *p; const char *next; From 1218aebfbfdab955230cdfe576cd7d87cf5cc050 Mon Sep 17 00:00:00 2001 From: toshixm Date: Thu, 3 Jun 2021 15:26:33 +0900 Subject: [PATCH 2/2] static allocation instead of malloc() --- libretro-common/file/file_path.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 127c71ebea..d582e9bd48 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -640,25 +640,25 @@ char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks) #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) #ifdef _WIN32 char *ret = NULL; - wchar_t *abs_path = (wchar_t *)malloc(PATH_MAX_LENGTH * sizeof(wchar_t)); + wchar_t abs_path[PATH_MAX_LENGTH]; wchar_t *rel_path = utf8_to_utf16_string_alloc(buf); - if (abs_path && rel_path && _wfullpath(abs_path, rel_path, PATH_MAX_LENGTH)) - { - char *tmp = utf16_to_utf8_string_alloc(abs_path); - - if (tmp) - { - strlcpy(buf, tmp, size); - free(tmp); - ret = buf; - } - } - if (rel_path) + { + if (_wfullpath(abs_path, rel_path, PATH_MAX_LENGTH)) + { + char *tmp = utf16_to_utf8_string_alloc(abs_path); + + if (tmp) + { + strlcpy(buf, tmp, size); + free(tmp); + ret = buf; + } + } + free(rel_path); - if (abs_path) - free(abs_path); + } return ret; #else