Avoid more snprintf usage

This commit is contained in:
twinaphex 2019-09-17 06:34:00 +02:00
parent 65aa939296
commit 7d58bb9799
4 changed files with 43 additions and 20 deletions

View File

@ -978,14 +978,13 @@ static void menu_widgets_draw_task_msg(menu_widget_msg_t *msg, video_frame_info_
if (msg->task_finished)
{
if (msg->task_error)
snprintf(task_percentage, sizeof(task_percentage), "Task failed");
strlcpy(task_percentage, "Task failed", sizeof(task_percentage));
else
snprintf(task_percentage, sizeof(task_percentage), " ");
strlcpy(task_percentage, " ", sizeof(task_percentage));
}
else if (msg->task_progress >= 0 && msg->task_progress <= 100)
{
snprintf(task_percentage, sizeof(task_percentage), "%i%%", msg->task_progress);
}
snprintf(task_percentage, sizeof(task_percentage),
"%i%%", msg->task_progress);
rect_width = simple_widget_padding + msg->width + task_percentage_offset;
bar_width = rect_width * msg->task_progress/100.0f;
@ -2238,6 +2237,7 @@ static void menu_widgets_start_achievement_notification()
static void menu_widgets_get_badge_texture(menu_texture_item *tex, const char *badge)
{
char badge_file[16];
size_t written;
char fullpath[PATH_MAX_LENGTH];
if (!badge)
@ -2246,7 +2246,13 @@ static void menu_widgets_get_badge_texture(menu_texture_item *tex, const char *b
return;
}
snprintf(badge_file, sizeof(badge_file), "%s.png", badge);
written = strlcpy(badge_file, badge, sizeof(badge_file));
badge_file[written] = '.';
badge_file[written+1] = 'p';
badge_file[written+2] = 'n';
badge_file[written+3] = 'g';
badge_file[written+4] = '\0';
fill_pathname_application_special(fullpath,
PATH_MAX_LENGTH * sizeof(char),
@ -2290,7 +2296,7 @@ void menu_widgets_set_message(char *msg)
menu_animation_ctx_tag tag = (uintptr_t) &generic_message_timer;
menu_timer_ctx_entry_t timer;
snprintf(generic_message, GENERIC_MESSAGE_SIZE, "%s", msg);
strlcpy(generic_message, msg, GENERIC_MESSAGE_SIZE);
generic_message_alpha = DEFAULT_BACKDROP;
@ -2327,7 +2333,7 @@ void menu_widgets_set_libretro_message(const char *msg, unsigned duration)
menu_animation_ctx_tag tag = (uintptr_t) &libretro_message_timer;
menu_timer_ctx_entry_t timer;
snprintf(libretro_message, LIBRETRO_MESSAGE_SIZE, "%s", msg);
strlcpy(libretro_message, msg, LIBRETRO_MESSAGE_SIZE);
libretro_message_alpha = DEFAULT_BACKDROP;

View File

@ -4155,20 +4155,30 @@ static bool command_event_save_config(
if (path_exists && config_save_file(config_path))
{
size_t written;
snprintf(s, len, "%s \"%s\".",
msg_hash_to_str(MSG_SAVED_NEW_CONFIG_TO),
config_path);
snprintf(log, PATH_MAX_LENGTH, "[config] %s", s);
written = strlcpy(log, "[config] ", sizeof(log));
log[written] = '\0';
written = strlcat(log, s, sizeof(log));
RARCH_LOG("%s\n", log);
return true;
}
if (!string_is_empty(str))
{
size_t written;
snprintf(s, len, "%s \"%s\".",
msg_hash_to_str(MSG_FAILED_SAVING_CONFIG_TO),
str);
snprintf(log, PATH_MAX_LENGTH, "[config] %s", s);
written = strlcpy(log, "[config] ", sizeof(log));
log[written] = '\0';
written = strlcat(log, s, sizeof(log));
RARCH_ERR("%s\n", log);
}

View File

@ -776,9 +776,10 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
}
else
{
n = snprintf(str, len, "%s %s",
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER));
n = strlcpy(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED), len);
str[n ] = ' ';
str[n+1] = '\0';
n = strlcat(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_INLINE_CORE_DISPLAY_NEVER), len);
}
if ((n < 0) || (n >= 64))

View File

@ -233,10 +233,14 @@ static void input_autoconfigure_joypad_add(config_file_t *conf,
if (string_is_equal(device_type, "remote"))
{
static bool remote_is_bound = false;
const char *autoconfig_str = (string_is_empty(display_name) &&
!string_is_empty(params->name)) ? params->name : (!string_is_empty(display_name) ? display_name : "N/A");
size_t written = strlcpy(
msg, autoconfig_str, sizeof(msg));
snprintf(msg, sizeof(msg), "%s configured.",
(string_is_empty(display_name) &&
!string_is_empty(params->name)) ? params->name : (!string_is_empty(display_name) ? display_name : "N/A"));
msg[written ] = ' ';
msg[written+1] = '\0';
strlcat(msg, "configured.", sizeof(msg));
if (!remote_is_bound)
{
@ -249,11 +253,13 @@ static void input_autoconfigure_joypad_add(config_file_t *conf,
}
else
{
bool tmp = false;
snprintf(msg, sizeof(msg), "%s %s #%u.",
(string_is_empty(display_name) &&
bool tmp = false;
const char *autoconfig_str = (string_is_empty(display_name) &&
!string_is_empty(params->name))
? params->name : (!string_is_empty(display_name) ? display_name : "N/A"),
? params->name : (!string_is_empty(display_name) ? display_name : "N/A");
snprintf(msg, sizeof(msg), "%s %s #%u.",
autoconfig_str,
msg_hash_to_str(MSG_DEVICE_CONFIGURED_IN_PORT),
params->idx);