snprintf - if no formatting is required then use strlcpy

This commit is contained in:
libretroadmin 2024-06-13 06:48:50 +02:00
parent 5d62510388
commit 3e2e53ba7f
2 changed files with 15 additions and 13 deletions

View File

@ -53,18 +53,17 @@ bool rcheevos_menu_get_state(unsigned menu_offset, char* buffer, size_t buffer_s
if (cheevo)
{
if (cheevo->state != RC_CLIENT_ACHIEVEMENT_STATE_ACTIVE)
{
strlcpy(buffer, msg_hash_to_str(menuitem->state_label_idx), buffer_size);
}
else
{
const char* missable = cheevo->type == RC_CLIENT_ACHIEVEMENT_TYPE_MISSABLE ? "[m] " : "";
size_t _len = strlcpy(buffer, missable, buffer_size);
_len += strlcpy(buffer + _len, msg_hash_to_str(menuitem->state_label_idx), buffer_size - _len);
if (cheevo->measured_progress[0])
snprintf(buffer, buffer_size, "%s%s - %s", missable,
msg_hash_to_str(menuitem->state_label_idx), cheevo->measured_progress);
else
snprintf(buffer, buffer_size, "%s%s", missable,
msg_hash_to_str(menuitem->state_label_idx));
{
_len += strlcpy(buffer + _len, " - ", buffer_size - _len);
strlcpy(buffer + _len, cheevo->measured_progress, buffer_size - _len);
}
}
return true;
}
@ -429,10 +428,8 @@ void rcheevos_menu_populate(void* data)
msg_hash_to_str(menuitem->state_label_idx));
}
else
{
snprintf(buffer, sizeof(buffer), "----- %s -----",
msg_hash_to_str(menuitem->state_label_idx));
}
menu_entries_append(info->list, buffer, "",
MENU_ENUM_LABEL_CHEEVOS_LOCKED_ENTRY,
@ -518,6 +515,7 @@ void rcheevos_menu_populate(void* data)
uintptr_t rcheevos_get_badge_texture(const char* badge, bool locked, bool download_if_missing)
{
size_t _len;
char badge_file[24];
char fullpath[PATH_MAX_LENGTH];
uintptr_t tex = 0;
@ -535,8 +533,9 @@ uintptr_t rcheevos_get_badge_texture(const char* badge, bool locked, bool downlo
return 0;
#endif
snprintf(badge_file, sizeof(badge_file), "%s%s%s", badge,
locked ? "_lock" : "", FILE_PATH_PNG_EXTENSION);
_len = strlcpy(badge_file, badge, sizeof(badge_file));
_len += strlcpy(badge_file + _len, locked ? "_lock" : "", sizeof(badge_file) - _len);
strlcpy(badge_file + _len, FILE_PATH_PNG_EXTENSION, sizeof(badge_file) - _len);
fill_pathname_application_special(fullpath, sizeof(fullpath),
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES);

View File

@ -3755,8 +3755,11 @@ void input_config_get_bind_string_joykey(
fill_pathname_join_delim(buf,
bind->joykey_label, suffix, ' ', size);
else
snprintf(buf, size, "%s%u",
"Button ", (unsigned)bind->joykey);
{
size_t _len = strlcpy(buf, "Button ", size);
snprintf(buf + _len, size - _len, "%u",
(unsigned)bind->joykey);
}
}
}