From 0b329018eea4222895d1673590daf2be512dc8ed Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Thu, 16 Jan 2025 23:59:22 +0100 Subject: [PATCH] Less string buffers and less string copies --- cheat_manager.c | 21 +++------- command.c | 84 +++++++++++++++++++--------------------- command.h | 2 +- core_info.c | 25 ++++-------- disk_control_interface.c | 8 ++-- disk_control_interface.h | 4 +- menu/menu_displaylist.c | 61 ++++++++++++++++------------- playlist.c | 24 ++++++------ runloop.c | 12 +++--- runtime_file.c | 4 +- save.c | 2 - tasks/task_autodetect.c | 24 +++++------- 12 files changed, 122 insertions(+), 149 deletions(-) diff --git a/cheat_manager.c b/cheat_manager.c index 18256e0c5e77..240b0f9632e6 100644 --- a/cheat_manager.c +++ b/cheat_manager.c @@ -704,7 +704,7 @@ bool cheat_manager_get_code_state(unsigned i) return cheat_st->cheats[i].state; } -static bool cheat_manager_get_game_specific_filename( +static size_t cheat_manager_get_game_specific_filename( char *s, size_t len, const char *path_cheat_database, bool saving) @@ -714,32 +714,23 @@ static bool cheat_manager_get_game_specific_filename( runloop_state_t *runloop_st = runloop_state_get_ptr(); const char *core_name = NULL; const char *game_name = NULL; - if (!core_get_system_info(&sysinfo)) - return false; - + return 0; core_name = sysinfo.library_name; game_name = path_basename_nocompression(runloop_st->name.cheatfile); - if ( string_is_empty(path_cheat_database) || string_is_empty(core_name) || string_is_empty(game_name)) - return false; - - fill_pathname_join_special(s1, - path_cheat_database, core_name, + return 0; + fill_pathname_join_special(s1, path_cheat_database, core_name, sizeof(s1)); - if (saving) { /* Check if directory is valid, if not, create it */ if (!path_is_valid(s1)) path_mkdir(s1); } - - fill_pathname_join_special(s, s1, game_name, len); - - return true; + return fill_pathname_join_special(s, s1, game_name, len); } void cheat_manager_load_game_specific_cheats(const char *path_cheat_database) @@ -789,7 +780,7 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool w bool is_search_initialization = (setting != NULL); rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system; unsigned offset = 0; - cheat_manager_t *cheat_st = &cheat_manager_state; + cheat_manager_t *cheat_st = &cheat_manager_state; #ifdef HAVE_MENU struct menu_state *menu_st = menu_state_get_ptr(); #endif diff --git a/command.c b/command.c index d26ca11a1192..ff962d4d44dc 100644 --- a/command.c +++ b/command.c @@ -67,7 +67,7 @@ #include "version.h" #include "version_git.h" -#define CMD_BUF_SIZE 4096 +#define CMD_BUF_SIZE 4096 static void command_post_state_loaded(void) { @@ -160,8 +160,7 @@ static void command_parse_sub_msg(command_t *handle, const char *tok) RARCH_WARN(msg_hash_to_str(MSG_UNRECOGNIZED_COMMAND), tok); } -static void command_parse_msg( - command_t *handle, char *buf) +static void command_parse_msg(command_t *handle, char *buf) { char *save = NULL; const char *tok = strtok_r(buf, "\n", &save); @@ -235,8 +234,8 @@ command_t* command_network_new(uint16_t port) command_t *cmd = (command_t*)calloc(1, sizeof(*cmd)); command_network_t *netcmd = (command_network_t*)calloc( 1, sizeof(command_network_t)); - int fd = socket_init( - (void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM, AF_INET); + int fd = socket_init((void**)&res, port, NULL, + SOCKET_TYPE_DATAGRAM, AF_INET); RARCH_LOG("[NetCMD]: %s %hu.\n", msg_hash_to_str(MSG_BRINGING_UP_COMMAND_INTERFACE_ON_PORT), @@ -1255,25 +1254,22 @@ bool command_event_resize_windowed_scale(settings_t *settings, return true; } -bool command_event_save_auto_state(void) +size_t command_event_save_auto_state(void) { size_t _len; runloop_state_t *runloop_st = runloop_state_get_ptr(); char savestate_name_auto[PATH_MAX_LENGTH]; - if (runloop_st->entry_state_slot) - return false; + return 0; if (!core_info_current_supports_savestate()) - return false; + return 0; if (string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME)))) - return false; - + return 0; _len = strlcpy(savestate_name_auto, runloop_st->name.savestate, sizeof(savestate_name_auto)); - strlcpy(savestate_name_auto + _len, ".auto", - sizeof(savestate_name_auto) - _len); - + _len += strlcpy(savestate_name_auto + _len, ".auto", + sizeof(savestate_name_auto) - _len); if (content_auto_save_state((const char*)savestate_name_auto)) RARCH_LOG("[State]: %s \"%s\" %s.\n", msg_hash_to_str(MSG_AUTO_SAVE_STATE_TO), @@ -1282,8 +1278,7 @@ bool command_event_save_auto_state(void) RARCH_LOG("[State]: %s \"%s\" %s.\n", msg_hash_to_str(MSG_AUTO_SAVE_STATE_TO), savestate_name_auto, "failed"); - - return true; + return _len; } #ifdef HAVE_CHEATS @@ -1740,25 +1735,23 @@ void command_event_set_replay_garbage_collect( { /* TODO: debugme */ size_t i, cnt = 0; - char state_base[128]; - char state_dir[DIR_MAX_LENGTH]; + char tmp[DIR_MAX_LENGTH]; runloop_state_t *runloop_st = runloop_state_get_ptr(); - struct string_list *dir_list = NULL; unsigned min_idx = UINT_MAX; const char *oldest_save = NULL; /* Similar to command_event_set_replay_auto_index(), * this will find the lowest numbered replay */ - fill_pathname_basedir(state_dir, runloop_st->name.replay, - sizeof(state_dir)); + fill_pathname_basedir(tmp, runloop_st->name.replay, + sizeof(tmp)); - if (!(dir_list = dir_list_new_special(state_dir, + if (!(dir_list = dir_list_new_special(tmp, DIR_LIST_PLAIN, NULL, show_hidden_files))) return; - fill_pathname_base(state_base, runloop_st->name.replay, - sizeof(state_base)); + fill_pathname_base(tmp, runloop_st->name.replay, + sizeof(tmp)); for (i = 0; i < dir_list->size; i++) { @@ -1783,7 +1776,7 @@ void command_event_set_replay_garbage_collect( /* Check whether this file is associated with * the current content */ - if (!string_starts_with(elem_base, state_base)) + if (!string_starts_with(elem_base, tmp)) continue; /* This looks like a valid save */ @@ -1966,17 +1959,11 @@ void command_event_save_current_config(enum override_type type) else { if (runloop_st->flags & RUNLOOP_FLAG_OVERRIDES_ACTIVE) - { _len = strlcpy(msg, msg_hash_to_str(MSG_OVERRIDES_ACTIVE_NOT_SAVING), sizeof(msg)); - runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, - MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - } else - { _len = command_event_save_config(path_get(RARCH_PATH_CONFIG), msg, sizeof(msg)); - runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, - MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - } + runloop_msg_queue_push(msg, _len, 1, 180, true, NULL, + MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } } break; @@ -2061,7 +2048,7 @@ void command_event_remove_current_config(enum override_type type) bool command_event_main_state(unsigned cmd) { char msg[128]; - char state_path[16384]; + char state_path[16384]; /* TODO/FIXME - reduce this */ size_t _len = 0; settings_t *settings = config_get_ptr(); bool savestates_enabled = core_info_current_supports_savestate(); @@ -2081,8 +2068,13 @@ bool command_event_main_state(unsigned cmd) /* TODO: Load state should act in one of three ways: - [X] Not during recording or playback: normally - - [-] During playback: If the state is part of this replay, go back to that state and rewind the replay (not yet implemented); otherwise halt playback and go to that state normally. - - [-] During recording: If the state is part of this replay, go back to that state and rewind the replay, clobbering the stuff in between then and now (not yet implemented); if the state is not part of the replay, do nothing and log a warning. + - [-] During playback: If the state is part of this replay, go back to + that state and rewind the replay (not yet implemented); otherwise + halt playback and go to that state normally. + - [-] During recording: If the state is part of this replay, go back to + that state and rewind the replay, clobbering the stuff in between + then and now (not yet implemented); if the state is not part of + the replay, do nothing and log a warning. */ @@ -2093,7 +2085,8 @@ bool command_event_main_state(unsigned cmd) case CMD_EVENT_SAVE_STATE: case CMD_EVENT_SAVE_STATE_TO_RAM: { - /* TODO: Saving state during recording should associate the state with the replay. */ + /* TODO: Saving state during recording should associate + * the state with the replay. */ video_driver_state_t *video_st = video_state_get_ptr(); bool savestate_auto_index = @@ -2136,7 +2129,11 @@ bool command_event_main_state(unsigned cmd) break; case CMD_EVENT_UNDO_LOAD_STATE: { - /* TODO: To support this through re-recording would take some care around moving the replay recording forward to the time when the undo happened, which would need undo support for replays. For now, forbid it during recording and halt playback. */ + /* TODO: To support this through re-recording would take some + * care around moving the replay recording forward to the time + * when the undo happened, which would need undo support for + * replays. For now, forbid it during recording and halt + * playback. */ #ifdef HAVE_BSV_MOVIE input_driver_state_t *input_st = input_state_get_ptr(); if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_RECORDING) @@ -2179,8 +2176,8 @@ bool command_event_disk_control_append_image( { runloop_state_t *runloop_st = runloop_state_get_ptr(); rarch_system_info_t *sys_info = runloop_st ? (rarch_system_info_t*)&runloop_st->system : NULL; - if ( !sys_info || - !disk_control_append_image(&sys_info->disk_control, path)) + if ( !sys_info + || !disk_control_append_image(&sys_info->disk_control, path)) return false; #ifdef HAVE_THREADS @@ -2230,12 +2227,11 @@ void command_event_reinit(const int flags) video_driver_reinit(flags); /* Poll input to avoid possibly stale data to corrupt things. */ - if ( joypad && joypad->poll) + if (joypad && joypad->poll) joypad->poll(); - if ( sec_joypad && sec_joypad->poll) + if (sec_joypad && sec_joypad->poll) sec_joypad->poll(); - if ( input_st->current_driver && - input_st->current_driver->poll) + if (input_st->current_driver && input_st->current_driver->poll) input_st->current_driver->poll(input_st->current_data); command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, &game_focus_cmd); diff --git a/command.h b/command.h index 5beb361cc5e5..d032d5588225 100644 --- a/command.h +++ b/command.h @@ -341,7 +341,7 @@ void command_event_set_mixer_volume( bool command_event_resize_windowed_scale(settings_t *settings, unsigned window_scale); -bool command_event_save_auto_state(void); +size_t command_event_save_auto_state(void); /** * event_set_volume: diff --git a/core_info.c b/core_info.c index 1a8b6b2e46d7..b4d96d735a64 100644 --- a/core_info.c +++ b/core_info.c @@ -849,8 +849,7 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info sizeof(file_path)); #if defined(CORE_INFO_CACHE_COMPRESS) - file = intfstream_open_rzip_file(file_path, - RETRO_VFS_FILE_ACCESS_WRITE); + file = intfstream_open_rzip_file(file_path, RETRO_VFS_FILE_ACCESS_WRITE); #else file = intfstream_open_file(file_path, RETRO_VFS_FILE_ACCESS_WRITE, @@ -1255,10 +1254,8 @@ bool core_info_cache_force_refresh(const char *path_info) * if required */ if (!path_is_valid(file_path)) { - RFILE *refresh_file = filestream_open( - file_path, - RETRO_VFS_FILE_ACCESS_WRITE, - RETRO_VFS_FILE_ACCESS_HINT_NONE); + RFILE *refresh_file = filestream_open(file_path, + RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE); if (!refresh_file) return false; @@ -1402,8 +1399,7 @@ static core_path_list_t *core_info_path_list_new(const char *core_dir, /* Fetch core directory listing */ dir_list_ok = dir_list_append(path_list->dir_list, - core_dir, exts, false, show_hidden_files, - false, false); + core_dir, exts, false, show_hidden_files, false, false); #if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP { @@ -2196,19 +2192,15 @@ static bool core_info_does_support_file( const core_info_t *core, const char *path) { const char *basename, *ext; - if (!core || !core->supported_extensions_list) return false; if (string_is_empty(path)) return false; - basename = path_basename(path); - /* if a core has / in its list of supported extensions, the core supports loading of directories on the host file system */ if (string_is_empty(basename)) return string_list_find_elem(core->supported_extensions_list, "/"); - ext = strrchr(basename, '.'); return string_list_find_elem_prefix( core->supported_extensions_list, ".", (ext ? ext + 1 : "")); @@ -2226,12 +2218,11 @@ static int core_info_qsort_cmp(const void *a_, const void *b_) int support_b = core_info_does_support_file(b, p_coreinfo->tmp_path); #ifdef HAVE_COMPRESSION - support_a = support_a || - core_info_does_support_any_file(a, p_coreinfo->tmp_list); - support_b = support_b || - core_info_does_support_any_file(b, p_coreinfo->tmp_list); + support_a = support_a + || core_info_does_support_any_file(a, p_coreinfo->tmp_list); + support_b = support_b + || core_info_does_support_any_file(b, p_coreinfo->tmp_list); #endif - if (support_a != support_b) return support_b - support_a; return strcasecmp(a->display_name, b->display_name); diff --git a/disk_control_interface.c b/disk_control_interface.c index 19ae7c5c5b97..cec617fb9402 100644 --- a/disk_control_interface.c +++ b/disk_control_interface.c @@ -243,9 +243,9 @@ unsigned disk_control_get_image_index( **/ void disk_control_get_image_label( disk_control_interface_t *disk_control, - unsigned index, char *label, size_t len) + unsigned index, char *s, size_t len) { - if (!label || len < 1) + if (!s || len < 1) return; if (!disk_control) @@ -254,13 +254,13 @@ void disk_control_get_image_label( if (!disk_control->cb.get_image_label) goto error; - if (!disk_control->cb.get_image_label(index, label, len)) + if (!disk_control->cb.get_image_label(index, s, len)) goto error; return; error: - label[0] = '\0'; + s[0] = '\0'; } /***********/ diff --git a/disk_control_interface.h b/disk_control_interface.h index 1efb364d6573..b9bd9d0afa84 100644 --- a/disk_control_interface.h +++ b/disk_control_interface.h @@ -100,7 +100,7 @@ bool disk_control_append_enabled( * * Leaf function. * - * @return true if core supports image labels + * @return true if core supports image labels * - get_image_label **/ bool disk_control_image_label_enabled( @@ -155,7 +155,7 @@ unsigned disk_control_get_image_index( **/ void disk_control_get_image_label( disk_control_interface_t *disk_control, - unsigned index, char *label, size_t len); + unsigned index, char *s, size_t len); /***********/ /* Setters */ diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 9fb01dc3427b..a444676286d7 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -2093,8 +2093,12 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list) /* RetroRating Level */ if (frontend->get_rating) { - snprintf(entry, sizeof(entry), "%s: %d", - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_RETRORATING_LEVEL), + _len = strlcpy(entry, + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_RETRORATING_LEVEL), + sizeof(entry)); + _len += strlcpy(entry + _len, ": ", sizeof(entry) - _len); + snprintf(entry + _len, sizeof(entry) - _len, "%d", frontend->get_rating()); if (menu_entries_append(list, entry, "", MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, @@ -2170,11 +2174,15 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list) video_context_driver_get_ident(&ident_info); /* Video Context Driver */ - snprintf(entry, sizeof(entry), "%s: %s", + _len = strlcpy(entry, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_VIDEO_CONTEXT_DRIVER), + sizeof(entry)); + _len += strlcpy(entry + _len, ": ", sizeof(entry) - _len); + strlcpy(entry + _len, string_is_empty(ident_info.ident) ? msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE) - : ident_info.ident); + : ident_info.ident, + sizeof(entry) - _len); if (menu_entries_append(list, entry, "", MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_SETTINGS_CORE_INFO_NONE, 0, 0, NULL)) @@ -6560,14 +6568,16 @@ static int menu_displaylist_parse_disc_info(file_list_t *info_list, { char drive[2]; char drive_string[NAME_MAX_LENGTH] = {0}; - size_t pos = snprintf(drive_string, sizeof(drive_string), + size_t _len = snprintf(drive_string, sizeof(drive_string), msg_drive_number, i + 1); - pos += snprintf(drive_string + pos, - sizeof(drive_string) - pos, - ": %s", list->elems[i].data); + _len += strlcpy(drive_string + _len, ": ", + sizeof(drive_string) - _len); + strlcpy( drive_string + _len, + list->elems[i].data, + sizeof(drive_string) - _len); - drive[0] = list->elems[i].attr.i; - drive[1] = '\0'; + drive[0] = list->elems[i].attr.i; + drive[1] = '\0'; if (menu_entries_append(info_list, drive_string, drive, MSG_UNKNOWN, @@ -7219,6 +7229,7 @@ unsigned menu_displaylist_build_list( PARSE_ONLY_BOOL, false) == 0) count++; + /* TODO/FIXME - should we dehardcode this? */ if ( string_is_equal(current_input->ident, "android") || (string_is_equal(current_input->ident, "cocoa") && string_is_equal(os_ver, "iOS"))) @@ -13249,29 +13260,27 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, for (i = 0; i < pass_count; i++) { - size_t _len2; - char buf[128]; - snprintf(buf_tmp + _len, sizeof(buf_tmp) - _len, " #%u", i); + size_t _len3; + size_t _len2 = _len + snprintf(buf_tmp + _len, sizeof(buf_tmp) - _len, " #%u", i); if (menu_entries_append(info->list, buf_tmp, shdr_pass, MENU_ENUM_LABEL_VIDEO_SHADER_PASS, MENU_SETTINGS_SHADER_PASS_0 + i, 0, 0, NULL)) count++; - _len2 = strlcpy(buf, buf_tmp, sizeof(buf)); - buf[ _len2] = ' '; - buf[++_len2] = '\0'; - strlcpy(buf + _len2, val_filter, sizeof(buf) - _len2); - if (menu_entries_append(info->list, buf, shdr_filter_pass, + buf_tmp[ _len2] = ' '; + buf_tmp[++_len2] = '\0'; + + _len3 = _len2; + strlcpy(buf_tmp + _len3, val_filter, sizeof(buf_tmp) - _len3); + if (menu_entries_append(info->list, buf_tmp, shdr_filter_pass, MENU_ENUM_LABEL_VIDEO_SHADER_FILTER_PASS, MENU_SETTINGS_SHADER_PASS_FILTER_0 + i, 0, 0, NULL)) count++; - _len2 = strlcpy(buf, buf_tmp, sizeof(buf)); - buf[ _len2] = ' '; - buf[++_len2] = '\0'; - strlcpy(buf + _len2, val_scale, sizeof(buf) - _len2); - if (menu_entries_append(info->list, buf, shdr_scale_pass, + _len3 = _len2; + strlcpy(buf_tmp + _len3, val_scale, sizeof(buf_tmp) - _len3); + if (menu_entries_append(info->list, buf_tmp, shdr_scale_pass, MENU_ENUM_LABEL_VIDEO_SHADER_SCALE_PASS, MENU_SETTINGS_SHADER_PASS_SCALE_0 + i, 0, 0, NULL)) count++; @@ -15164,13 +15173,11 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, case DISPLAYLIST_USER_BINDS_LIST: menu_entries_clear(info->list); { - char lbl[NAME_MAX_LENGTH]; unsigned val = atoi(info->path); const char *temp_val = msg_hash_to_str( (enum msg_hash_enums)(MENU_ENUM_LABEL_INPUT_USER_1_BINDS + (val-1))); - strlcpy(lbl, temp_val, sizeof(lbl)); ret = MENU_DISPLAYLIST_PARSE_SETTINGS(info->list, - lbl, PARSE_NONE, true, MENU_SETTINGS_INPUT_BEGIN); + temp_val, PARSE_NONE, true, MENU_SETTINGS_INPUT_BEGIN); info->flags |= MD_FLAG_NEED_REFRESH | MD_FLAG_NEED_PUSH; } @@ -15284,7 +15291,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, } if (!string_is_empty(info->exts)) free(info->exts); - info->exts = strdup(new_exts); + info->exts = strdup(new_exts); use_filebrowser = true; } #endif diff --git a/playlist.c b/playlist.c index ab5e582ce3d6..7b029219ae22 100644 --- a/playlist.c +++ b/playlist.c @@ -194,43 +194,40 @@ playlist_config_t *playlist_get_config(playlist_t *playlist) { if (!playlist) return NULL; - return &playlist->config; } static void path_replace_base_path_and_convert_to_local_file_system( - char *out_path, + char *s, const char *in_path, - const char *in_oldrefpath, - const char *in_refpath, - size_t size) + const char *in_oldrefpath, const char *in_refpath, + size_t len) { size_t in_oldrefpath_length = strlen(in_oldrefpath); - /* If entry path is inside playlist base path, * replace it with new base content directory */ if (string_starts_with_size(in_path, in_oldrefpath, in_oldrefpath_length)) { size_t in_refpath_length = strlen(in_refpath); - memcpy(out_path, in_refpath, in_refpath_length); + memcpy(s, in_refpath, in_refpath_length); memcpy( - out_path + in_refpath_length, - in_path + in_oldrefpath_length, + s + in_refpath_length, + in_path + in_oldrefpath_length, strlen(in_path) - in_oldrefpath_length + 1); #ifdef _WIN32 /* If we are running under a Windows filesystem, * '/' characters are not allowed anywhere. * We replace with '\' and hope for the best... */ - string_replace_all_chars(out_path, + string_replace_all_chars(s, POSIX_PATH_DELIMITER, WINDOWS_PATH_DELIMITER); #else /* Under POSIX filesystem, we replace '\' characters with '/' */ - string_replace_all_chars(out_path, + string_replace_all_chars(s, WINDOWS_PATH_DELIMITER, POSIX_PATH_DELIMITER); #endif } else - strlcpy(out_path, in_path, size); + strlcpy(s, in_path, len); } /* Generates a case insensitive hash for the @@ -2980,7 +2977,8 @@ playlist_t *playlist_init(const playlist_config_t *config) tmp_entry_path[0] = '\0'; path_replace_base_path_and_convert_to_local_file_system( tmp_entry_path, entry->path, - playlist->base_content_directory, playlist->config.base_content_directory, + playlist->base_content_directory, + playlist->config.base_content_directory, sizeof(tmp_entry_path)); free(entry->path); diff --git a/runloop.c b/runloop.c index cf7878eace0b..9a6dc93aecf6 100644 --- a/runloop.c +++ b/runloop.c @@ -1192,8 +1192,8 @@ static bool validate_folder_specific_options(char *s, size_t len) **/ static void runloop_init_core_options_path( settings_t *settings, - char *s, size_t len, - char *src_path, size_t src_len) + char *s, size_t len, + char *s2, size_t len2) { runloop_state_t *runloop_st = &runloop_state; bool game_specific_options = settings->bools.game_specific_options; @@ -1250,11 +1250,9 @@ static void runloop_init_core_options_path( if ( !per_core_options || !per_core_options_exist) { - const char *options_path = path_core_options; - - if (!string_is_empty(options_path)) + if (!string_is_empty(path_core_options)) strlcpy(global_options_path, - options_path, sizeof(global_options_path)); + path_core_options, sizeof(global_options_path)); else if (!path_is_empty(RARCH_PATH_CONFIG)) fill_pathname_resolve_relative( global_options_path, path_get(RARCH_PATH_CONFIG), @@ -1266,7 +1264,7 @@ static void runloop_init_core_options_path( { strlcpy(s, per_core_options_path, len); if (!per_core_options_exist) - strlcpy(src_path, global_options_path, src_len); + strlcpy(s2, global_options_path, len2); } else strlcpy(s, global_options_path, len); diff --git a/runtime_file.c b/runtime_file.c index 94ddd01b27f0..6a202a931690 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -324,9 +324,7 @@ runtime_log_t *runtime_log_init( * content has the same name... */ else if (string_is_equal(core_name, "TyrQuake")) { - const char *slash = strrchr(content_path, '/'); - const char *backslash = strrchr(content_path, '\\'); - const char *last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; + char *last_slash = find_last_slash(content_path); if (last_slash) { size_t path_length = last_slash + 1 - content_path; diff --git a/save.c b/save.c index 41e10084fe6c..f282369985e9 100644 --- a/save.c +++ b/save.c @@ -522,9 +522,7 @@ bool event_save_files(bool is_sram_used) return false; for (i = 0; i < task_save_files->size; i++) - { content_save_ram_file(i, compress_files); - } return true; } diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index 1d5086c79faf..daaee066ce4b 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -202,10 +202,9 @@ static void input_autoconfigure_set_config_file( autoconfig_handle_t *autoconfig_handle, config_file_t *config, unsigned alternative) { - struct config_entry_list *entry = NULL; - char config_key[32] = {0}; - char config_key_postfix[7] = {0}; size_t _len; + char config_key[32]; + struct config_entry_list *entry = NULL; /* Attach config file */ autoconfig_handle->autoconfig_file = config; @@ -220,16 +219,13 @@ static void input_autoconfigure_set_config_file( sizeof(autoconfig_handle->device_info.config_name)); } - /* Read device display name */ - if (alternative > 0) - snprintf(config_key_postfix, sizeof(config_key_postfix), - "_alt%d",alternative); - /* Parse config file */ _len = strlcpy(config_key, "input_device_display_name", sizeof(config_key)); - _len += strlcpy(config_key + _len, config_key_postfix, - sizeof(config_key) - _len); + /* Read device display name */ + if (alternative > 0) + _len += snprintf(config_key + _len, sizeof(config_key) - _len, + "_alt%d",alternative); if ( (entry = config_get_entry(config, config_key)) && !string_is_empty(entry->value)) @@ -483,12 +479,12 @@ static void reallocate_port_if_needed(unsigned detected_port, int vendor_id, strlcpy(settings_value_device_name, settings_value, sizeof(settings_value_device_name)); device_has_reserved_slot = - string_is_equal(device_name, settings_value_device_name) || - string_is_equal(device_display_name, settings_value_device_name); + string_is_equal(device_name, settings_value_device_name) + || string_is_equal(device_display_name, settings_value_device_name); } else - device_has_reserved_slot = (vendor_id == settings_value_vendor_id && - product_id == settings_value_product_id); + device_has_reserved_slot = ( vendor_id == settings_value_vendor_id + && product_id == settings_value_product_id); if (device_has_reserved_slot) {