From 4b5c7856e69f4bcd57f86f5066a6c6585f25300c Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 19 Jul 2022 20:43:12 +0200 Subject: [PATCH] Remove some more explicit NULL-termination when we're calling a string function that calls strlcpy under the hood --- gfx/gfx_display.c | 2 -- gfx/video_shader_parse.c | 14 ++++++-------- libretro-common/file/config_file.c | 7 ------- menu/menu_driver.c | 12 ++++++++---- menu/menu_setting.c | 4 +++- runloop.c | 5 ++--- tasks/task_screenshot.c | 10 +++------- 7 files changed, 22 insertions(+), 32 deletions(-) diff --git a/gfx/gfx_display.c b/gfx/gfx_display.c index e220292e11..fbef83d9f7 100644 --- a/gfx/gfx_display.c +++ b/gfx/gfx_display.c @@ -1199,8 +1199,6 @@ bool gfx_display_reset_textures_list( char texpath[PATH_MAX_LENGTH]; struct texture_image ti; - texpath[0] = '\0'; - ti.width = 0; ti.height = 0; ti.pixels = NULL; diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 68421a1456..44854f8f0f 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -84,9 +84,6 @@ static void fill_pathname_expanded_and_absolute(char *out_path, const char *in_refpath, const char *in_path) { char expanded_path[PATH_MAX_LENGTH]; - - expanded_path[0] = '\0'; - /* Expand paths which start with :\ to an absolute path */ fill_pathname_expand_special(expanded_path, in_path, sizeof(expanded_path)); @@ -2276,8 +2273,6 @@ void dir_check_shader( if (shader && !string_is_empty(shader->loaded_preset_path)) { char last_shader_path[PATH_MAX_LENGTH]; - last_shader_path[0] = '\0'; - fill_pathname_join(last_shader_path, last_shader_preset_dir, last_shader_preset_file_name, sizeof(last_shader_path)); @@ -2386,8 +2381,6 @@ bool load_shader_preset(settings_t *settings, const char *core_name, shader_path[0] = '\0'; content_dir_name[0] = '\0'; - config_file_directory[0] = '\0'; - old_presets_directory[0] = '\0'; if (has_content) { @@ -2397,12 +2390,17 @@ bool load_shader_preset(settings_t *settings, const char *core_name, } if (!path_is_empty(RARCH_PATH_CONFIG)) - fill_pathname_basedir(config_file_directory, + { + strlcpy(config_file_directory, path_get(RARCH_PATH_CONFIG), sizeof(config_file_directory)); + path_basedir(config_file_directory); + } if (!string_is_empty(video_shader_directory)) fill_pathname_join(old_presets_directory, video_shader_directory, "presets", sizeof(old_presets_directory)); + else + old_presets_directory[0] = '\0'; dirs[0] = menu_config_directory; dirs[1] = config_file_directory; diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 36716a6d6e..b0633ebcb1 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -399,12 +399,8 @@ void config_file_add_reference(config_file_t *conf, char *path) { /* It is expected that the conf has it's path already set */ char short_path[PATH_MAX_LENGTH]; - - short_path[0] = '\0'; - if (!conf->references) conf->references = path_linked_list_new(); - fill_pathname_abbreviated_or_relative(short_path, conf->path, path, sizeof(short_path)); path_linked_list_add_path(conf->references, short_path); } @@ -540,7 +536,6 @@ static bool config_file_parse_line(config_file_t *conf, return false; } - real_path[0] = '\0'; config_file_add_sub_conf(conf, path, real_path, sizeof(real_path), cb); @@ -1232,8 +1227,6 @@ void config_set_path(config_file_t *conf, const char *entry, const char *val) config_set_string(conf, entry, val); #else char buf[PATH_MAX_LENGTH]; - - buf[0] = '\0'; fill_pathname_abbreviate_special(buf, val, sizeof(buf)); config_set_string(conf, entry, buf); #endif diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 83b179cc2b..09e93e1e37 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -2874,10 +2874,12 @@ bool menu_shader_manager_save_preset(const struct video_shader *shader, config_directory[0] = '\0'; if (!path_is_empty(RARCH_PATH_CONFIG)) - fill_pathname_basedir( - config_directory, + { + strlcpy(config_directory, path_get(RARCH_PATH_CONFIG), sizeof(config_directory)); + path_basedir(config_directory); + } preset_dirs[0] = dir_video_shader; preset_dirs[1] = dir_menu_config; @@ -3889,10 +3891,12 @@ bool menu_shader_manager_operate_auto_preset( return false; if (!path_is_empty(RARCH_PATH_CONFIG)) - fill_pathname_basedir( - config_directory, + { + strlcpy(config_directory, path_get(RARCH_PATH_CONFIG), sizeof(config_directory)); + path_basedir(config_directory); + } /* We are only including this directory for compatibility purposes with * versions 1.8.7 and older. */ diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 529cc12caf..a7497d56b7 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -8959,13 +8959,15 @@ static bool setting_append_list_input_player_options( if (input_config_bind_map_get_meta(i)) continue; - label[0] = name[0] = '\0'; + name[0] = '\0'; if (!string_is_empty(buffer[user])) { strlcpy(label, buffer[user], sizeof(label)); strlcat(label, " ", sizeof(label)); } + else + label[0] = '\0'; if ( settings->bools.input_descriptor_label_show diff --git a/runloop.c b/runloop.c index 7c3d4ac964..6afb0b6a33 100644 --- a/runloop.c +++ b/runloop.c @@ -1949,12 +1949,11 @@ bool runloop_environment_cb(unsigned cmd, void *data) if (!string_is_empty(fullpath)) { char tmp_path[PATH_MAX_LENGTH]; - tmp_path[0] = '\0'; - if (string_is_empty(dir_system)) RARCH_WARN("[Environ]: SYSTEM DIR is empty, assume CONTENT DIR %s\n", fullpath); - fill_pathname_basedir(tmp_path, fullpath, sizeof(tmp_path)); + strlcpy(tmp_path, fullpath, sizeof(tmp_path)); + path_basedir(tmp_path); dir_set(RARCH_DIR_SYSTEM, tmp_path); } diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index 8e2c5ef73b..0f1ddac4bb 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -330,15 +330,11 @@ static bool screenshot_dump( if ( string_is_empty(new_screenshot_dir) || settings->bools.screenshots_in_content_dir) - { fill_pathname_basedir(new_screenshot_dir, name_base, sizeof(new_screenshot_dir)); - fill_pathname_join(state->filename, new_screenshot_dir, - state->shotname, sizeof(state->filename)); - } - else - fill_pathname_join(state->filename, new_screenshot_dir, - state->shotname, sizeof(state->filename)); + + fill_pathname_join(state->filename, new_screenshot_dir, + state->shotname, sizeof(state->filename)); /* Create screenshot directory, if required */ if (!path_is_directory(new_screenshot_dir))