diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index c352b4f26e..9b7def5796 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -512,7 +512,7 @@ size_t fill_pathname_parent_dir_name(char *s, const char *in_dir, size_t len) * If the path was already at the root directory, * @s will be an empty string. **/ -void fill_pathname_parent_dir(char *s, +size_t fill_pathname_parent_dir(char *s, const char *in_dir, size_t len) { size_t _len = 0; @@ -520,7 +520,7 @@ void fill_pathname_parent_dir(char *s, _len = strlen(s); else _len = strlcpy(s, in_dir, len); - path_parent_dir(s, _len); + return path_parent_dir(s, _len); } /** diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index e507e53138..708bdb5170 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -431,8 +431,10 @@ size_t fill_pathname_parent_dir_name(char *s, * - Can call strlcpy if (@out_dir != @in_dir) * - Calls strlen if (@out_dir == @in_dir) * - Calls path_parent_dir() + * + * @return Length of the string copied into @s **/ -void fill_pathname_parent_dir(char *s, +size_t fill_pathname_parent_dir(char *s, const char *in_dir, size_t len); /** diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index ac29c72607..d4c0a8b8a3 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1559,6 +1559,7 @@ int generic_action_ok_displaylist_push( #endif } + /* TODO/FIXME - do we need the recursive calls here? */ fill_pathname_parent_dir(parent_dir, tmp, sizeof(parent_dir)); fill_pathname_parent_dir(parent_dir, @@ -5063,16 +5064,18 @@ finish: STRLEN_CONST(FILE_PATH_INDEX_DIRS_URL) )) { + size_t _len; char parent_dir_encoded[DIR_MAX_LENGTH]; file_transfer_t *transf = (file_transfer_t*)malloc(sizeof(*transf)); parent_dir_encoded[0] = '\0'; transf->enum_idx = MSG_UNKNOWN; - fill_pathname_parent_dir(transf->path, + _len = fill_pathname_parent_dir(transf->path, state->path, sizeof(transf->path)); - strlcat(transf->path, FILE_PATH_INDEX_DIRS_URL, - sizeof(transf->path)); + strlcpy(transf->path + _len, + FILE_PATH_INDEX_DIRS_URL, + sizeof(transf->path) - _len); net_http_urlencode_full(parent_dir_encoded, transf->path, sizeof(parent_dir_encoded)); diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 0ea0d10184..4bc5318aa4 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -241,7 +241,7 @@ struct key_desc key_descriptors[RARCH_MAX_KEYS] = {RETROK_BREAK, "Break"}, {RETROK_MENU, "Menu"}, {RETROK_POWER, "Power"}, - {RETROK_EURO, {-30, -126, -84, 0}}, /* "�" */ + {RETROK_EURO, {-30, -126, -84, 0}}, /* " " */ {RETROK_UNDO, "Undo"}, {RETROK_OEM_102, "OEM-102"}, @@ -4007,21 +4007,22 @@ void menu_entries_search_append_terms_string(char *s, size_t len) && (search->size > 0) && s) { - size_t current_len = strlen_size(s, len); + size_t curr_len = strlen_size(s, len); size_t i; /* If buffer is already 'full', nothing * further can be added */ - if (current_len >= len) + if (curr_len >= len) return; - s += current_len; - len -= current_len; + s += curr_len; + len -= curr_len; + curr_len = 0; for (i = 0; i < search->size; i++) { - strlcat(s, " > ", len); - strlcat(s, search->terms[i], len); + curr_len += strlcpy(s + curr_len, " > ", len - curr_len); + curr_len += strlcpy(s + curr_len, search->terms[i], len - curr_len); } } } diff --git a/retroarch.c b/retroarch.c index a930b50e49..9542a9dd5e 100644 --- a/retroarch.c +++ b/retroarch.c @@ -4664,18 +4664,14 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_MENU_SAVE_AS_CONFIG: { - char as_path[PATH_MAX_LENGTH]; char conf_path[PATH_MAX_LENGTH]; - - snprintf(as_path, sizeof(as_path), "%s", (char *)data); - - /* Prepend '.cfg' extension if missing */ - if (!string_ends_with(as_path, FILE_PATH_CONFIG_EXTENSION)) - strlcat(as_path, FILE_PATH_CONFIG_EXTENSION, sizeof(as_path)); - - fill_pathname_join(conf_path, + size_t _len = fill_pathname_join(conf_path, settings->paths.directory_menu_config, - as_path, sizeof(conf_path)); + (char*)data, sizeof(conf_path)); + + /* Append '.cfg' extension if missing */ + if (!string_ends_with(conf_path, FILE_PATH_CONFIG_EXTENSION)) + strlcpy(conf_path + _len, FILE_PATH_CONFIG_EXTENSION, sizeof(conf_path) - _len); if (!string_is_empty(conf_path)) path_set(RARCH_PATH_CONFIG, conf_path); diff --git a/runtime_file.c b/runtime_file.c index 6a202a9316..dc43f7a946 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -993,7 +993,7 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log, s[ _len] = ' '; s[++_len] = '\0'; if ((runtime_last_played_human(runtime_log, s + _len, len - _len - 2)) == 0) - strlcat(s + _len, + strlcpy(s + _len, msg_hash_to_str( MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER), len - _len - 2);