From 36edb15c5bf4ffd75a50fd141a55596d5412a712 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Sun, 31 Jul 2022 12:31:55 +0200 Subject: [PATCH] path_parent_dir - don't do implicit strlen inside --- configuration.c | 2 +- frontend/drivers/platform_ps2.c | 5 +++-- libretro-common/file/file_path.c | 14 +++++++------- libretro-common/file/file_path_io.c | 2 +- libretro-common/include/file/file_path.h | 3 ++- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/configuration.c b/configuration.c index 8a8b995d92..2245ba120e 100644 --- a/configuration.c +++ b/configuration.c @@ -5207,7 +5207,7 @@ bool input_remapping_save_file(const char *path) /* Create output directory, if required */ strlcpy(remap_file_dir, path, sizeof(remap_file_dir)); - path_parent_dir(remap_file_dir); + path_parent_dir(remap_file_dir, strlen(remap_file_dir)); if (!string_is_empty(remap_file_dir) && !path_is_directory(remap_file_dir) && diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 2a6a7ead00..61a8b46bb8 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -370,8 +370,9 @@ static void frontend_ps2_init(void *data) getcwd(cwd, sizeof(cwd)); #if !defined(IS_SALAMANDER) && !defined(DEBUG) - // If it is not salamander we need to go one level up for set the CWD. - path_parent_dir(cwd); + /* If it is not Salamander, we need to go one level + * up for setting the CWD. */ + path_parent_dir(cwd, strlen(cwd)); #endif if (pfsModuleLoaded) hddMounted = mount_hdd_partition(); diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 727cf2875b..ab3183a16c 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -449,9 +449,12 @@ bool fill_pathname_parent_dir_name(char *out_dir, void fill_pathname_parent_dir(char *out_dir, const char *in_dir, size_t size) { + size_t len = 0; if (out_dir != in_dir) - strlcpy(out_dir, in_dir, size); - path_parent_dir(out_dir); + len = strlcpy(out_dir, in_dir, size); + else + len = strlen(out_dir); + path_parent_dir(out_dir, len); } /** @@ -538,20 +541,17 @@ void path_basedir(char *path) /** * path_parent_dir: * @path : path + * @len : length of @path * * Extracts parent directory by mutating path. * Assumes that path is a directory. Keeps trailing '/'. * If the path was already at the root directory, returns empty string **/ -void path_parent_dir(char *path) +void path_parent_dir(char *path, size_t len) { - size_t len = 0; - if (!path) return; - len = strlen(path); - if (len && PATH_CHAR_IS_SLASH(path[len - 1])) { bool path_was_absolute = path_is_absolute(path); diff --git a/libretro-common/file/file_path_io.c b/libretro-common/file/file_path_io.c index f7e77e1749..fec16ebf2c 100644 --- a/libretro-common/file/file_path_io.c +++ b/libretro-common/file/file_path_io.c @@ -121,7 +121,7 @@ bool path_mkdir(const char *dir) if (!(basedir = strdup(dir))) return false; - path_parent_dir(basedir); + path_parent_dir(basedir, strlen(basedir)); if (!*basedir || !strcmp(basedir, dir)) { diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 431cfcac99..f77cfb2b60 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -161,12 +161,13 @@ void path_basedir(char *path); /** * path_parent_dir: * @path : path + * @len : length of @path * * Extracts parent directory by mutating path. * Assumes that path is a directory. Keeps trailing '/'. * If the path was already at the root directory, returns empty string **/ -void path_parent_dir(char *path); +void path_parent_dir(char *path, size_t len); /** * path_resolve_realpath: