From b7e122a4fae83bcdf2e14af8067c35f52e81b79e Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 20 Jun 2023 17:56:45 +0200 Subject: [PATCH] Replace more strlcat calls --- gfx/video_shader_parse.c | 9 +++------ menu/cbs/menu_cbs_sublabel.c | 30 ++++++++++++++++-------------- menu/menu_setting.c | 16 +++++++++------- retroarch.c | 17 +++++++---------- runloop.c | 7 ++++--- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 32269b1ae1..ef4f845adb 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -1168,17 +1168,14 @@ static bool video_shader_write_root_preset(const struct video_shader *shader, if (shader->luts) { char textures[4096]; - - textures[0] = '\0'; - /* Names of the textures */ - strlcpy(textures, shader->lut[0].id, sizeof(textures)); + size_t _len = strlcpy(textures, shader->lut[0].id, sizeof(textures)); for (i = 1; i < shader->luts; i++) { /* O(n^2), but number of textures is very limited. */ - strlcat(textures, ";", sizeof(textures)); - strlcat(textures, shader->lut[i].id, sizeof(textures)); + _len += strlcpy(textures + _len, ";", sizeof(textures) - _len); + _len += strlcpy(textures + _len, shader->lut[i].id, sizeof(textures) - _len); } config_set_string(conf, "textures", textures); diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index dbff673a1c..ab4267dd5c 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -1635,34 +1635,36 @@ static int action_bind_sublabel_netplay_room(file_list_t *list, ": %s (%s)\n" "%s: %s (%s)\n" "%s: %s ", - !string_is_empty(room->retroarch_version) ? room->retroarch_version : - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), + !string_is_empty(room->retroarch_version) + ? room->retroarch_version + : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), (!string_is_empty(room->frontend) && - !string_is_equal_case_insensitive(room->frontend, "N/A")) ? - room->frontend : - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), + !string_is_equal_case_insensitive(room->frontend, "N/A")) + ? room->frontend + : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CONTENT_INFO_CORE_NAME), room->corename, room->coreversion, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CONTENT), (!string_is_empty(room->gamename) && - !string_is_equal_case_insensitive(room->gamename, "N/A")) ? - room->gamename : - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)); + !string_is_equal_case_insensitive(room->gamename, "N/A")) + ? room->gamename + : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)); if ( string_is_empty(room->subsystem_name) || string_is_equal_case_insensitive(room->subsystem_name, "N/A")) - snprintf(buf, sizeof(buf), "(%08lX)", - (unsigned long)(unsigned)room->gamecrc); + _len = snprintf(buf, sizeof(buf), "(%08lX)", + (unsigned long)(unsigned)room->gamecrc); else { - buf[0 ] = '('; - buf[1 ] = '\0'; - _len = strlcat(buf, room->subsystem_name, sizeof(buf)); + _len = 0; + buf[ _len] = '('; + buf[++_len] = '\0'; + _len += strlcpy(buf + _len, room->subsystem_name, sizeof(buf) - _len); buf[ _len] = ')'; buf[++_len] = '\0'; } - strlcat(s, buf, len); + strlcpy(s + _len, buf, len - _len); return 0; } diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 682bca5f3c..61182e19d5 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -9143,8 +9143,8 @@ static bool setting_append_list_input_player_options( { char label[NAME_MAX_LENGTH]; char name[NAME_MAX_LENGTH]; - - i = (j < RARCH_ANALOG_BIND_LIST_END) + size_t _len = 0; + i = (j < RARCH_ANALOG_BIND_LIST_END) ? input_config_bind_order[j] : j; @@ -9155,7 +9155,7 @@ static bool setting_append_list_input_player_options( if (!string_is_empty(buffer[user])) { - size_t _len = strlcpy(label, buffer[user], sizeof(label)); + _len = strlcpy(label, buffer[user], sizeof(label)); label[ _len] = ' '; label[++_len] = '\0'; } @@ -9170,18 +9170,20 @@ static bool setting_append_list_input_player_options( ) { if (system->input_desc_btn[user][i]) - strlcat(label, + strlcpy(label + _len, system->input_desc_btn[user][i], - sizeof(label)); + sizeof(label) - _len); else { - strlcat(label, value_na, sizeof(label)); + strlcpy(label + _len, value_na, sizeof(label) - _len); if (settings->bools.input_descriptor_hide_unbound) continue; } } else - strlcat(label, input_config_bind_map_get_desc(i), sizeof(label)); + strlcpy(label + _len, + input_config_bind_map_get_desc(i), + sizeof(label) - _len); snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(i)); diff --git a/retroarch.c b/retroarch.c index deb43ec657..c9de06e7eb 100644 --- a/retroarch.c +++ b/retroarch.c @@ -6342,22 +6342,19 @@ bool retroarch_main_init(int argc, char *argv[]) { { char str_output[256]; - const char *cpu_model = NULL; - str_output[0] = '\0'; - - cpu_model = frontend_driver_get_cpu_model_name(); - - strlcpy(str_output, + const char *cpu_model = frontend_driver_get_cpu_model_name(); + size_t _len = strlcpy(str_output, "=== Build =======================================\n", sizeof(str_output)); if (!string_is_empty(cpu_model)) { - size_t _len; /* TODO/FIXME - localize */ - strlcat(str_output, FILE_PATH_LOG_INFO " CPU Model Name: ", - sizeof(str_output)); - _len = strlcat(str_output, cpu_model, sizeof(str_output)); + _len += strlcpy(str_output + _len, + FILE_PATH_LOG_INFO " CPU Model Name: ", + sizeof(str_output) - _len); + _len += strlcpy(str_output + _len, cpu_model, + sizeof(str_output) - _len); str_output[ _len] = '\n'; str_output[++_len] = '\0'; } diff --git a/runloop.c b/runloop.c index 4133da7ebb..4603c60cc8 100644 --- a/runloop.c +++ b/runloop.c @@ -4064,12 +4064,13 @@ static bool runloop_path_init_subsystem(runloop_state_t *runloop_st) union string_list_elem_attr attr; char savename[PATH_MAX_LENGTH]; char path[PATH_MAX_LENGTH]; + size_t _len = 0; const struct retro_subsystem_memory_info *mem = (const struct retro_subsystem_memory_info*) &info->roms[i].memory[j]; - ext[0] = '.'; - ext[1] = '\0'; - strlcat(ext, mem->extension, sizeof(ext)); + ext[ _len] = '.'; + ext[++_len] = '\0'; + strlcpy(ext + _len, mem->extension, sizeof(ext) - _len); strlcpy(savename, runloop_st->subsystem_fullpaths->elems[i].data, sizeof(savename));