From 3e2e53ba7f195ea9df94585fff4771ed6275925f Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Thu, 13 Jun 2024 06:48:50 +0200 Subject: [PATCH] snprintf - if no formatting is required then use strlcpy --- cheevos/cheevos_menu.c | 21 ++++++++++----------- input/input_driver.c | 7 +++++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cheevos/cheevos_menu.c b/cheevos/cheevos_menu.c index 90e904fffe..baa213fcda 100644 --- a/cheevos/cheevos_menu.c +++ b/cheevos/cheevos_menu.c @@ -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); diff --git a/input/input_driver.c b/input/input_driver.c index 97b00561f7..b03517b735 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -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); + } } }