Replace more strlcat calls

This commit is contained in:
libretroadmin 2023-06-20 17:56:45 +02:00
parent 458fe7a761
commit b7e122a4fa
5 changed files with 39 additions and 40 deletions

View File

@ -1168,17 +1168,14 @@ static bool video_shader_write_root_preset(const struct video_shader *shader,
if (shader->luts) if (shader->luts)
{ {
char textures[4096]; char textures[4096];
textures[0] = '\0';
/* Names of the textures */ /* 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++) for (i = 1; i < shader->luts; i++)
{ {
/* O(n^2), but number of textures is very limited. */ /* O(n^2), but number of textures is very limited. */
strlcat(textures, ";", sizeof(textures)); _len += strlcpy(textures + _len, ";", sizeof(textures) - _len);
strlcat(textures, shader->lut[i].id, sizeof(textures)); _len += strlcpy(textures + _len, shader->lut[i].id, sizeof(textures) - _len);
} }
config_set_string(conf, "textures", textures); config_set_string(conf, "textures", textures);

View File

@ -1635,34 +1635,36 @@ static int action_bind_sublabel_netplay_room(file_list_t *list,
": %s (%s)\n" ": %s (%s)\n"
"%s: %s (%s)\n" "%s: %s (%s)\n"
"%s: %s ", "%s: %s ",
!string_is_empty(room->retroarch_version) ? room->retroarch_version : !string_is_empty(room->retroarch_version)
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), ? room->retroarch_version
: msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE),
(!string_is_empty(room->frontend) && (!string_is_empty(room->frontend) &&
!string_is_equal_case_insensitive(room->frontend, "N/A")) ? !string_is_equal_case_insensitive(room->frontend, "N/A"))
room->frontend : ? room->frontend
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CONTENT_INFO_CORE_NAME), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CONTENT_INFO_CORE_NAME),
room->corename, room->coreversion, room->corename, room->coreversion,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CONTENT), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CONTENT),
(!string_is_empty(room->gamename) && (!string_is_empty(room->gamename) &&
!string_is_equal_case_insensitive(room->gamename, "N/A")) ? !string_is_equal_case_insensitive(room->gamename, "N/A"))
room->gamename : ? room->gamename
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)); : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
if ( string_is_empty(room->subsystem_name) if ( string_is_empty(room->subsystem_name)
|| string_is_equal_case_insensitive(room->subsystem_name, "N/A")) || string_is_equal_case_insensitive(room->subsystem_name, "N/A"))
snprintf(buf, sizeof(buf), "(%08lX)", _len = snprintf(buf, sizeof(buf), "(%08lX)",
(unsigned long)(unsigned)room->gamecrc); (unsigned long)(unsigned)room->gamecrc);
else else
{ {
buf[0 ] = '('; _len = 0;
buf[1 ] = '\0'; buf[ _len] = '(';
_len = strlcat(buf, room->subsystem_name, sizeof(buf)); buf[++_len] = '\0';
_len += strlcpy(buf + _len, room->subsystem_name, sizeof(buf) - _len);
buf[ _len] = ')'; buf[ _len] = ')';
buf[++_len] = '\0'; buf[++_len] = '\0';
} }
strlcat(s, buf, len); strlcpy(s + _len, buf, len - _len);
return 0; return 0;
} }

View File

@ -9143,7 +9143,7 @@ static bool setting_append_list_input_player_options(
{ {
char label[NAME_MAX_LENGTH]; char label[NAME_MAX_LENGTH];
char name[NAME_MAX_LENGTH]; char name[NAME_MAX_LENGTH];
size_t _len = 0;
i = (j < RARCH_ANALOG_BIND_LIST_END) i = (j < RARCH_ANALOG_BIND_LIST_END)
? input_config_bind_order[j] ? input_config_bind_order[j]
: j; : j;
@ -9155,7 +9155,7 @@ static bool setting_append_list_input_player_options(
if (!string_is_empty(buffer[user])) 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] = ' ';
label[++_len] = '\0'; label[++_len] = '\0';
} }
@ -9170,18 +9170,20 @@ static bool setting_append_list_input_player_options(
) )
{ {
if (system->input_desc_btn[user][i]) if (system->input_desc_btn[user][i])
strlcat(label, strlcpy(label + _len,
system->input_desc_btn[user][i], system->input_desc_btn[user][i],
sizeof(label)); sizeof(label) - _len);
else else
{ {
strlcat(label, value_na, sizeof(label)); strlcpy(label + _len, value_na, sizeof(label) - _len);
if (settings->bools.input_descriptor_hide_unbound) if (settings->bools.input_descriptor_hide_unbound)
continue; continue;
} }
} }
else 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)); snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(i));

View File

@ -6342,22 +6342,19 @@ bool retroarch_main_init(int argc, char *argv[])
{ {
{ {
char str_output[256]; char str_output[256];
const char *cpu_model = NULL; const char *cpu_model = frontend_driver_get_cpu_model_name();
str_output[0] = '\0'; size_t _len = strlcpy(str_output,
cpu_model = frontend_driver_get_cpu_model_name();
strlcpy(str_output,
"=== Build =======================================\n", "=== Build =======================================\n",
sizeof(str_output)); sizeof(str_output));
if (!string_is_empty(cpu_model)) if (!string_is_empty(cpu_model))
{ {
size_t _len;
/* TODO/FIXME - localize */ /* TODO/FIXME - localize */
strlcat(str_output, FILE_PATH_LOG_INFO " CPU Model Name: ", _len += strlcpy(str_output + _len,
sizeof(str_output)); FILE_PATH_LOG_INFO " CPU Model Name: ",
_len = strlcat(str_output, cpu_model, sizeof(str_output)); sizeof(str_output) - _len);
_len += strlcpy(str_output + _len, cpu_model,
sizeof(str_output) - _len);
str_output[ _len] = '\n'; str_output[ _len] = '\n';
str_output[++_len] = '\0'; str_output[++_len] = '\0';
} }

View File

@ -4064,12 +4064,13 @@ static bool runloop_path_init_subsystem(runloop_state_t *runloop_st)
union string_list_elem_attr attr; union string_list_elem_attr attr;
char savename[PATH_MAX_LENGTH]; char savename[PATH_MAX_LENGTH];
char path[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 *mem =
(const struct retro_subsystem_memory_info*) (const struct retro_subsystem_memory_info*)
&info->roms[i].memory[j]; &info->roms[i].memory[j];
ext[0] = '.'; ext[ _len] = '.';
ext[1] = '\0'; ext[++_len] = '\0';
strlcat(ext, mem->extension, sizeof(ext)); strlcpy(ext + _len, mem->extension, sizeof(ext) - _len);
strlcpy(savename, strlcpy(savename,
runloop_st->subsystem_fullpaths->elems[i].data, runloop_st->subsystem_fullpaths->elems[i].data,
sizeof(savename)); sizeof(savename));