(task_save.c) Simplification in control flow

(snprintf) Try to reduce or simplify snprintf calls, only tend to
use it for processing integers/numbers and avoid it for regular
string concatenation (NOTE: we try to be a bit safer about it to
address earlier cited criticism, although we don't consider concatenating
3 or 4 characters at the end to be insecure)
(msg_hash_to_str) Try to avoid duplicate calls to the same localized
string when we can just cache the results once instead locally
This commit is contained in:
LibretroAdmin 2022-08-27 07:52:31 +02:00
parent 45b05ea3db
commit 61e24132bf
12 changed files with 250 additions and 160 deletions

View file

@ -1363,13 +1363,13 @@ static void load_timezone(char *setting)
char *start = strstr(haystack, needle);
if (start != NULL)
if (start)
snprintf(setting, TIMEZONE_LENGTH, "%s", start + needle_len);
else
snprintf(setting, TIMEZONE_LENGTH, "%s", DEFAULT_TIMEZONE);
strlcpy(setting, DEFAULT_TIMEZONE, TIMEZONE_LENGTH);
}
else
snprintf(setting, TIMEZONE_LENGTH, "%s", DEFAULT_TIMEZONE);
strlcpy(setting, DEFAULT_TIMEZONE, TIMEZONE_LENGTH);
config_set_timezone(setting);
}
@ -4697,16 +4697,26 @@ bool config_save_file(const char *path)
for (i = 0; i < MAX_USERS; i++)
{
char cfg[64];
char formatted_number[4];
cfg[0] = '\0';
cfg[0] = formatted_number[0] = '\0';
snprintf(cfg, sizeof(cfg), "input_device_p%u", i + 1);
snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1);
strlcpy(cfg, "input_device_p", sizeof(cfg));
strlcat(cfg, formatted_number, sizeof(cfg));
config_set_int(conf, cfg, settings->uints.input_device[i]);
snprintf(cfg, sizeof(cfg), "input_player%u_joypad_index", i + 1);
strlcpy(cfg, "input_player", sizeof(cfg));
strlcat(cfg, formatted_number, sizeof(cfg));
strlcat(cfg, "_joypad_index", sizeof(cfg));
config_set_int(conf, cfg, settings->uints.input_joypad_index[i]);
snprintf(cfg, sizeof(cfg), "input_player%u_analog_dpad_mode", i + 1);
strlcpy(cfg, "input_player", sizeof(cfg));
strlcat(cfg, formatted_number, sizeof(cfg));
strlcat(cfg, "_analog_dpad_mode", sizeof(cfg));
config_set_int(conf, cfg, settings->uints.input_analog_dpad_mode[i]);
snprintf(cfg, sizeof(cfg), "input_player%u_mouse_index", i + 1);
strlcpy(cfg, "input_player", sizeof(cfg));
strlcat(cfg, formatted_number, sizeof(cfg));
strlcat(cfg, "_mouse_index", sizeof(cfg));
config_set_int(conf, cfg, settings->uints.input_mouse_index[i]);
}
@ -4964,19 +4974,25 @@ bool config_save_overrides(enum override_type type, void *data)
for (i = 0; i < MAX_USERS; i++)
{
char cfg[64];
char formatted_number[4];
cfg[0] = formatted_number[0] = '\0';
snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1);
cfg[0] = '\0';
if (settings->uints.input_device[i]
!= overrides->uints.input_device[i])
{
snprintf(cfg, sizeof(cfg), "input_device_p%u", i + 1);
strlcpy(cfg, "input_device_p", sizeof(cfg));
strlcat(cfg, formatted_number, sizeof(cfg));
config_set_int(conf, cfg, overrides->uints.input_device[i]);
}
if (settings->uints.input_joypad_index[i]
!= overrides->uints.input_joypad_index[i])
{
snprintf(cfg, sizeof(cfg), "input_player%u_joypad_index", i + 1);
strlcpy(cfg, "input_player", sizeof(cfg));
strlcat(cfg, formatted_number, sizeof(cfg));
strlcpy(cfg, "_joypad_index", sizeof(cfg));
config_set_int(conf, cfg, overrides->uints.input_joypad_index[i]);
}
}
@ -5117,13 +5133,17 @@ bool input_remapping_load_file(void *data, const char *path)
size_t _len;
char prefix[16];
char s1[32], s2[32], s3[32];
char formatted_number[4];
prefix[0] = '\0';
s1[0] = '\0';
s2[0] = '\0';
s3[0] = '\0';
formatted_number[0] = '\0';
snprintf(prefix, sizeof(prefix), "input_player%u", i + 1);
snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1);
strlcpy(prefix, "input_player", sizeof(prefix));
strlcat(prefix, formatted_number, sizeof(prefix));
_len = strlcpy(s1, prefix, sizeof(s1));
s1[_len ] = '_';
s1[_len+1] = 'b';
@ -5204,13 +5224,17 @@ bool input_remapping_load_file(void *data, const char *path)
}
}
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
strlcpy(s1, "input_player", sizeof(s1));
strlcat(s1, formatted_number, sizeof(s1));
strlcat(s1, "_analog_dpad_mode", sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_analog_dpad_mode[i], s1);
snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
strlcpy(s1, "input_libretro_device_p", sizeof(s1));
strlcat(s1, formatted_number, sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_libretro_device[i], s1);
snprintf(s1, sizeof(s1), "input_remap_port_p%u", i + 1);
strlcpy(s1, "input_remap_port_p", sizeof(s1));
strlcat(s1, formatted_number, sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_remap_ports[i], s1);
}
@ -5267,11 +5291,13 @@ bool input_remapping_save_file(const char *path)
{
size_t _len;
bool skip_port = true;
char formatted_number[4];
char prefix[16];
char s1[32];
char s2[32];
char s3[32];
formatted_number[4] = '\0';
prefix[0] = '\0';
s1[0] = '\0';
s2[0] = '\0';
@ -5298,7 +5324,9 @@ bool input_remapping_save_file(const char *path)
if (skip_port)
continue;
snprintf(prefix, sizeof(prefix), "input_player%u", i + 1);
snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1);
strlcpy(prefix, "input_player", sizeof(prefix));
strlcat(prefix, formatted_number, sizeof(prefix));
_len = strlcpy(s1, prefix, sizeof(s1));
s1[_len ] = '_';
s1[_len+1] = 'b';
@ -5384,13 +5412,17 @@ bool input_remapping_save_file(const char *path)
settings->uints.input_keymapper_ids[i][j]);
}
snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1);
strlcpy(s1, "input_libretro_device_p", sizeof(s1));
strlcat(s1, formatted_number, sizeof(s1));
config_set_int(conf, s1, input_config_get_device(i));
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
strlcpy(s1, "input_player", sizeof(s1));
strlcat(s1, formatted_number, sizeof(s1));
strlcat(s1, "_analog_dpad_mode", sizeof(s1));
config_set_int(conf, s1, settings->uints.input_analog_dpad_mode[i]);
snprintf(s1, sizeof(s1), "input_remap_port_p%u", i + 1);
strlcpy(s1, "input_remap_port_p", sizeof(s1));
strlcat(s1, formatted_number, sizeof(s1));
config_set_int(conf, s1, settings->uints.input_remap_ports[i]);
}

View file

@ -1612,19 +1612,22 @@ static void core_info_resolve_firmware(
for (i = 0; i < firmware_count; i++)
{
char prefix[12];
char path_key[64];
char desc_key[64];
char opt_key[64];
struct config_entry_list *entry = NULL;
bool tmp_bool = false;
path_key[0] = '\0';
desc_key[0] = '\0';
opt_key[0] = '\0';
prefix[0] = '\0';
snprintf(path_key, sizeof(path_key), "firmware%u_path", i);
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", i);
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", i);
snprintf(prefix, sizeof(prefix), "firmware%u_", i);
strlcpy(path_key, prefix, sizeof(path_key));
strlcat(path_key, "path", sizeof(path_key));
strlcpy(desc_key, prefix, sizeof(desc_key));
strlcat(desc_key, "desc", sizeof(desc_key));
strlcpy(opt_key, prefix, sizeof(opt_key));
strlcat(opt_key, "opt", sizeof(opt_key));
entry = config_get_entry(conf, path_key);

View file

@ -1998,8 +1998,13 @@ static void win32_localize_menu(HMENU menu)
if (new_label_text)
{
size_t _len;
new_label2 = new_label_text;
snprintf(new_label_text, buf_size, "%s\t%s", new_label, meta_key_name);
_len = strlcpy(new_label_text, new_label,
buf_size);
new_label_text[_len ] = '\t';
new_label_text[_len+1] = '\0';
strlcat(new_label_text, meta_key_name, buf_size);
/* Make first character of shortcut name uppercase */
new_label_text[len1 + 1] = toupper(new_label_text[len1 + 1]);
}

View file

@ -682,9 +682,9 @@ bool slang_reflect(
{
char buf[64];
buf[0] = '\0';
snprintf(buf, sizeof(buf),
"[slang]:\n%s [slang]: Parameters:\n", FILE_PATH_LOG_INFO);
strlcpy(buf, "[slang]:\n", sizeof(buf));
strlcat(buf, FILE_PATH_LOG_INFO, sizeof(buf));
strlcat(buf, " [slang]: Parameters:\n", sizeof(buf));
RARCH_LOG(buf);
}

View file

@ -982,11 +982,11 @@ void recording_dump_frame(
if ( vp.width != record_st->gpu_width ||
vp.height != record_st->gpu_height)
{
RARCH_WARN("[Recording]: %s\n",
msg_hash_to_str(MSG_RECORDING_TERMINATED_DUE_TO_RESIZE));
const char *recording_failed_str =
msg_hash_to_str(MSG_RECORDING_TERMINATED_DUE_TO_RESIZE);
RARCH_WARN("[Recording]: %s\n", recording_failed_str);
runloop_msg_queue_push(
msg_hash_to_str(MSG_RECORDING_TERMINATED_DUE_TO_RESIZE),
runloop_msg_queue_push(recording_failed_str,
1, 180, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
command_event(CMD_EVENT_RECORD_DEINIT, NULL);

View file

@ -2531,17 +2531,22 @@ bool apply_shader(
if (message)
{
/* Display message */
const char *msg_shader = msg_hash_to_str(MSG_SHADER);
size_t _len = strlcpy(msg, msg_shader, sizeof(msg));
msg[_len ] = ':';
msg[_len+1] = ' ';
msg[_len+2] = '\0';
if (preset_file)
snprintf(msg, sizeof(msg),
"%s: \"%s\"",
msg_hash_to_str(MSG_SHADER),
preset_file);
{
msg[_len+2] = '"';
msg[_len+3] = '\0';
_len = strlcat(msg, preset_file, sizeof(msg));
msg[_len ] = '"';
msg[_len+1] = '\0';
}
else
snprintf(msg, sizeof(msg),
"%s: %s",
msg_hash_to_str(MSG_SHADER),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NONE)
);
strlcat(msg, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NONE), sizeof(msg));
#ifdef HAVE_GFX_WIDGETS
if (dispwidget_get_ptr()->active)
gfx_widget_set_generic_message(msg, 2000);

View file

@ -2234,28 +2234,32 @@ void input_config_get_bind_string_joykey(
}
else
{
const char *dir = "?";
const char *na_str =
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
switch (GET_HAT_DIR(bind->joykey))
{
case HAT_UP_MASK:
dir = "up";
snprintf(buf, size, "%sHat #%u up (%s)", prefix,
(unsigned)GET_HAT(bind->joykey), na_str);
break;
case HAT_DOWN_MASK:
dir = "down";
snprintf(buf, size, "%sHat #%u down (%s)", prefix,
(unsigned)GET_HAT(bind->joykey), na_str);
break;
case HAT_LEFT_MASK:
dir = "left";
snprintf(buf, size, "%sHat #%u left (%s)", prefix,
(unsigned)GET_HAT(bind->joykey), na_str);
break;
case HAT_RIGHT_MASK:
dir = "right";
snprintf(buf, size, "%sHat #%u right (%s)", prefix,
(unsigned)GET_HAT(bind->joykey), na_str);
break;
default:
snprintf(buf, size, "%sHat #%u ? (%s)", prefix,
(unsigned)GET_HAT(bind->joykey), na_str);
break;
}
snprintf(buf, size, "%sHat #%u %s (%s)", prefix,
(unsigned)GET_HAT(bind->joykey), dir,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
}
}
else
@ -2302,20 +2306,18 @@ void input_config_get_bind_string_joyaxis(
}
else
{
unsigned axis = 0;
char dir = '\0';
const char *na_str =
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '-';
axis = AXIS_NEG_GET(bind->joyaxis);
unsigned axis = AXIS_NEG_GET(bind->joyaxis);
snprintf(buf, size, "%s-%u (%s)", prefix, axis, na_str);
}
else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '+';
axis = AXIS_POS_GET(bind->joyaxis);
unsigned axis = AXIS_POS_GET(bind->joyaxis);
snprintf(buf, size, "%s+%u (%s)", prefix, axis, na_str);
}
snprintf(buf, size, "%s%c%u (%s)", prefix, dir, axis,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
}
}
@ -4668,23 +4670,16 @@ static bool runloop_check_movie_init(input_driver_state_t *input_st,
configuration_set_uint(settings, settings->uints.rewind_granularity, 1);
strlcpy(path,
input_st->bsv_movie_state.movie_path, sizeof(path));
if (state_slot > 0)
{
path[0] = '\0';
snprintf(path, sizeof(path), "%s%d.bsv",
input_st->bsv_movie_state.movie_path,
state_slot);
}
else
{
size_t _len = strlcpy(path,
input_st->bsv_movie_state.movie_path, sizeof(path));
path[_len ] = '.';
path[_len+1] = 'b';
path[_len+2] = 's';
path[_len+3] = 'v';
path[_len+4] = '\0';
char formatted_number[4];
formatted_number[0] = '\0';
snprintf(formatted_number, sizeof(formatted_number), "%d", state_slot);
strlcat(path, formatted_number, sizeof(path));
}
strlcat(path, ".bsv", sizeof(path));
snprintf(msg, sizeof(msg), "%s \"%s\".",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
@ -4772,6 +4767,7 @@ bool bsv_movie_init(input_driver_state_t *input_st)
bsv_movie_t *state = NULL;
if (input_st->bsv_movie_state.movie_start_playback)
{
const char *starting_movie_str = NULL;
if (!(state = bsv_movie_init_internal(
input_st->bsv_movie_state.movie_start_path,
RARCH_MOVIE_PLAYBACK)))
@ -4782,41 +4778,43 @@ bool bsv_movie_init(input_driver_state_t *input_st)
return false;
}
input_st->bsv_movie_state_handle = state;
input_st->bsv_movie_state_handle = state;
input_st->bsv_movie_state.movie_playback = true;
runloop_msg_queue_push(msg_hash_to_str(MSG_STARTING_MOVIE_PLAYBACK),
starting_movie_str =
msg_hash_to_str(MSG_STARTING_MOVIE_PLAYBACK);
runloop_msg_queue_push(starting_movie_str,
2, 180, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_LOG("%s.\n", msg_hash_to_str(MSG_STARTING_MOVIE_PLAYBACK));
RARCH_LOG("%s.\n", starting_movie_str);
return true;
}
else if (input_st->bsv_movie_state.movie_start_recording)
{
char msg[8192];
const char *movie_rec_str = msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO);
if (!(state = bsv_movie_init_internal(
input_st->bsv_movie_state.movie_start_path,
RARCH_MOVIE_RECORD)))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD),
const char *movie_rec_fail_str =
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD);
runloop_msg_queue_push(movie_rec_fail_str,
1, 180, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_ERR("%s.\n",
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD));
RARCH_ERR("%s.\n", movie_rec_fail_str);
return false;
}
input_st->bsv_movie_state_handle = state;
snprintf(msg, sizeof(msg),
"%s \"%s\".",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
"%s \"%s\".", movie_rec_str,
input_st->bsv_movie_state.movie_start_path);
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
RARCH_LOG("%s \"%s\".\n", movie_rec_str,
input_st->bsv_movie_state.movie_start_path);
return true;
@ -4835,18 +4833,21 @@ void bsv_movie_deinit(input_driver_state_t *input_st)
bool bsv_movie_check(input_driver_state_t *input_st,
settings_t *settings)
{
const char *movie_rec_stopped_str = NULL;
if (!input_st->bsv_movie_state_handle)
return runloop_check_movie_init(input_st, settings);
if (input_st->bsv_movie_state.movie_playback)
{
const char *movie_playback_end_str = NULL;
/* Checks if movie is being played back. */
if (!input_st->bsv_movie_state.movie_end)
return false;
movie_playback_end_str = msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED);
runloop_msg_queue_push(
msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED), 2, 180, false,
movie_playback_end_str, 2, 180, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED));
RARCH_LOG("%s\n", movie_playback_end_str);
bsv_movie_deinit(input_st);
@ -4860,10 +4861,11 @@ bool bsv_movie_check(input_driver_state_t *input_st,
if (!input_st->bsv_movie_state_handle)
return false;
runloop_msg_queue_push(
msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED), 2, 180, true,
movie_rec_stopped_str = msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED);
runloop_msg_queue_push(movie_rec_stopped_str,
2, 180, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED));
RARCH_LOG("%s\n", movie_rec_stopped_str);
bsv_movie_deinit(input_st);

View file

@ -3810,6 +3810,7 @@ static void ozone_update_content_metadata(ozone_handle_t *ozone)
if ((playlist && (ozone->is_playlist || (ozone->is_quick_menu && !menu_is_running_quick_menu()))) ||
(ozone->is_db_manager_list && ozone->depth == 4))
{
size_t _len;
const char *core_label = NULL;
const struct playlist_entry *entry = NULL;
size_t list_size = menu_entries_get_size();
@ -3875,8 +3876,13 @@ static void ozone_update_content_metadata(ozone_handle_t *ozone)
core_label = core_name;
}
snprintf(ozone->selection_core_name, sizeof(ozone->selection_core_name),
"%s %s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE), core_label);
_len = strlcpy(ozone->selection_core_name,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE),
sizeof(ozone->selection_core_name));
ozone->selection_core_name[_len ] = ' ';
ozone->selection_core_name[_len+1] = '\0';
strlcat(ozone->selection_core_name, core_label,
sizeof(ozone->selection_core_name));
if (!scroll_content_metadata)
linebreak_after_colon(&ozone->selection_core_name);
@ -3917,13 +3923,27 @@ static void ozone_update_content_metadata(ozone_handle_t *ozone)
}
else
{
snprintf(ozone->selection_playtime, sizeof(ozone->selection_playtime), "%s %s",
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_RUNTIME),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISABLED));
const char *disabled_str =
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISABLED);
size_t _len =
strlcpy(ozone->selection_playtime,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_RUNTIME),
sizeof(ozone->selection_playtime));
ozone->selection_playtime[_len ] = ' ';
ozone->selection_playtime[_len+1] = '\0';
strlcat(ozone->selection_playtime, disabled_str,
sizeof(ozone->selection_playtime));
snprintf(ozone->selection_lastplayed, sizeof(ozone->selection_lastplayed), "%s %s",
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISABLED));
_len =
strlcpy(ozone->selection_lastplayed,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_LAST_PLAYED),
sizeof(ozone->selection_lastplayed));
ozone->selection_lastplayed[_len ] = ' ';
ozone->selection_lastplayed[_len+1] = '\0';
strlcat(ozone->selection_lastplayed, disabled_str,
sizeof(ozone->selection_lastplayed));
}
if (!scroll_content_metadata)

View file

@ -2224,6 +2224,7 @@ bool command_event(enum event_command cmd, void *data)
case CMD_EVENT_HISTORY_INIT:
{
playlist_config_t playlist_config;
const char *_msg = NULL;
bool history_list_enable = settings->bools.history_list_enable;
const char *path_content_history = settings->paths.path_content_history;
const char *path_content_music_history = settings->paths.path_content_music_history;
@ -2245,18 +2246,18 @@ bool command_event(enum event_command cmd, void *data)
if (!history_list_enable)
return false;
_msg = msg_hash_to_str(MSG_LOADING_HISTORY_FILE);
/* Note: Sorting is disabled by default for
* all content history playlists */
RARCH_LOG("[Playlist]: %s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_HISTORY_FILE),
RARCH_LOG("[Playlist]: %s: \"%s\".\n", _msg,
path_content_history);
playlist_config_set_path(&playlist_config, path_content_history);
g_defaults.content_history = playlist_init(&playlist_config);
playlist_set_sort_mode(
g_defaults.content_history, PLAYLIST_SORT_MODE_OFF);
RARCH_LOG("[Playlist]: %s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_HISTORY_FILE),
RARCH_LOG("[Playlist]: %s: \"%s\".\n", _msg,
path_content_music_history);
playlist_config_set_path(&playlist_config, path_content_music_history);
g_defaults.music_history = playlist_init(&playlist_config);
@ -2264,8 +2265,7 @@ bool command_event(enum event_command cmd, void *data)
g_defaults.music_history, PLAYLIST_SORT_MODE_OFF);
#if defined(HAVE_FFMPEG) || defined(HAVE_MPV)
RARCH_LOG("[Playlist]: %s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_HISTORY_FILE),
RARCH_LOG("[Playlist]: %s: \"%s\".\n", _msg,
path_content_video_history);
playlist_config_set_path(&playlist_config, path_content_video_history);
g_defaults.video_history = playlist_init(&playlist_config);
@ -2274,8 +2274,7 @@ bool command_event(enum event_command cmd, void *data)
#endif
#ifdef HAVE_IMAGEVIEWER
RARCH_LOG("[Playlist]: %s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_HISTORY_FILE),
RARCH_LOG("[Playlist]: %s: \"%s\".\n", _msg,
path_content_image_history);
playlist_config_set_path(&playlist_config, path_content_image_history);
g_defaults.image_history = playlist_init(&playlist_config);

View file

@ -3445,10 +3445,11 @@ static bool init_libretro_symbols_custom(
path_get_realsize(RARCH_PATH_CORE)
)))
{
RARCH_ERR("%s: \"%s\"\nError(s): %s\n",
msg_hash_to_str(MSG_FAILED_TO_OPEN_LIBRETRO_CORE),
const char *failed_open_str =
msg_hash_to_str(MSG_FAILED_TO_OPEN_LIBRETRO_CORE);
RARCH_ERR("%s: \"%s\"\nError(s): %s\n", failed_open_str,
path, dylib_error());
runloop_msg_queue_push(msg_hash_to_str(MSG_FAILED_TO_OPEN_LIBRETRO_CORE),
runloop_msg_queue_push(failed_open_str,
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
return false;
}
@ -4771,9 +4772,11 @@ static void do_runahead(
if (!runahead_create(runloop_st))
{
const char *runahead_failed_str =
msg_hash_to_str(MSG_RUNAHEAD_CORE_DOES_NOT_SUPPORT_SAVESTATES);
if (!runahead_hide_warnings)
runloop_msg_queue_push(msg_hash_to_str(MSG_RUNAHEAD_CORE_DOES_NOT_SUPPORT_SAVESTATES), 0, 2 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", msg_hash_to_str(MSG_RUNAHEAD_CORE_DOES_NOT_SUPPORT_SAVESTATES));
runloop_msg_queue_push(runahead_failed_str, 0, 2 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", runahead_failed_str);
goto force_input_dirty;
}
}
@ -4817,8 +4820,10 @@ static void do_runahead(
{
if (!runahead_save_state(runloop_st))
{
runloop_msg_queue_push(msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_SAVE_STATE), 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_SAVE_STATE));
const char *runahead_failed_str =
msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_SAVE_STATE);
runloop_msg_queue_push(runahead_failed_str, 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", runahead_failed_str);
return;
}
}
@ -4827,8 +4832,10 @@ static void do_runahead(
{
if (!runahead_load_state(runloop_st))
{
runloop_msg_queue_push(msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_LOAD_STATE), 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_LOAD_STATE));
const char *runahead_failed_str =
msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_LOAD_STATE);
runloop_msg_queue_push(runahead_failed_str, 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", runahead_failed_str);
return;
}
}
@ -4839,10 +4846,12 @@ static void do_runahead(
#if HAVE_DYNAMIC
if (!secondary_core_ensure_exists(config_get_ptr()))
{
const char *runahead_failed_str =
msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_CREATE_SECONDARY_INSTANCE);
runloop_secondary_core_destroy();
runloop_st->runahead_secondary_core_available = false;
runloop_msg_queue_push(msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_CREATE_SECONDARY_INSTANCE), 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_CREATE_SECONDARY_INSTANCE));
runloop_msg_queue_push(runahead_failed_str, 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", runahead_failed_str);
goto force_input_dirty;
}
@ -4858,15 +4867,19 @@ static void do_runahead(
if (!runahead_save_state(runloop_st))
{
runloop_msg_queue_push(msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_SAVE_STATE), 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_SAVE_STATE));
const char *runahead_failed_str =
msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_SAVE_STATE);
runloop_msg_queue_push(runahead_failed_str, 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", runahead_failed_str);
return;
}
if (!runahead_load_state_secondary())
{
runloop_msg_queue_push(msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_LOAD_STATE), 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_LOAD_STATE));
const char *runahead_failed_str =
msg_hash_to_str(MSG_RUNAHEAD_FAILED_TO_LOAD_STATE);
runloop_msg_queue_push(runahead_failed_str, 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_WARN("[Run-Ahead]: %s\n", runahead_failed_str);
return;
}
@ -8127,7 +8140,8 @@ bool retroarch_get_entry_state_path(char *path, size_t len, unsigned slot)
if (string_is_empty(name_savestate))
return false;
snprintf(path, len, "%s%d%s", name_savestate, slot, ".entry");
snprintf(path, len, "%s%d", name_savestate, slot);
strlcat(path, ".entry", len);
return true;
}

View file

@ -687,6 +687,8 @@ static bool runtime_last_played_human(runtime_log_t *runtime_log,
float periods[6] = {60.0f, 60.0f, 24.0f, 7.0f, 4.35f, 12.0f};
tmp[0] = '\0';
if (!runtime_log)
return false;
@ -703,10 +705,13 @@ static bool runtime_last_played_human(runtime_log_t *runtime_log,
delta /= periods[i];
/* Generate string */
snprintf(tmp, sizeof(tmp), "%u %s",
(int)delta, msg_hash_to_str((delta == 1)
? (enum msg_hash_enums)units[i][0]
: (enum msg_hash_enums)units[i][1]));
snprintf(tmp, sizeof(tmp), "%u ", (int)delta);
if (delta == 1)
strlcat(tmp, msg_hash_to_str((enum msg_hash_enums)units[i][0]),
sizeof(tmp));
else
strlcat(tmp, msg_hash_to_str((enum msg_hash_enums)units[i][1]),
sizeof(tmp));
strlcat(str, tmp, len);
strlcat(str, " ", len);
strlcat(str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_TIME_UNIT_AGO), len);

View file

@ -783,18 +783,22 @@ static void task_save_handler(retro_task_t *task)
if (state->undo_save)
{
RARCH_ERR("[State]: %s \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE),
const char *failed_undo_str = msg_hash_to_str(
MSG_FAILED_TO_UNDO_SAVE_STATE);
RARCH_ERR("[State]: %s \"%s\".\n", failed_undo_str,
undo_save_buf.path);
snprintf(err, err_size - 1, "%s \"%s\".",
msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE),
"RAM");
snprintf(err, err_size - 1, "%s \"RAM\".", failed_undo_str);
}
else
snprintf(err, err_size - 1,
"%s %s",
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO), state->path);
{
size_t _len = strlcpy(err,
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
err_size - 1);
err[_len ] = ' ';
err[_len+1] = '\0';
strlcat(err, state->path, err_size - 1);
}
task_set_error(task, strdup(err));
free(err);
@ -817,7 +821,8 @@ static void task_save_handler(retro_task_t *task)
char new_msg[128];
new_msg[0] = '\0';
snprintf(new_msg, sizeof(new_msg), msg_hash_to_str(MSG_SAVED_STATE_TO_SLOT),
snprintf(new_msg, sizeof(new_msg),
msg_hash_to_str(MSG_SAVED_STATE_TO_SLOT),
state->state_slot);
msg = strdup(new_msg);
}
@ -1878,8 +1883,8 @@ static bool dump_to_file_desperate(const void *data,
bool content_load_state_from_ram(void)
{
size_t temp_data_size;
bool ret = false;
void* temp_data = NULL;
bool ret = false;
void* temp_data = NULL;
if (!core_info_current_supports_savestate())
{
@ -1897,19 +1902,19 @@ bool content_load_state_from_ram(void)
msg_hash_to_str(MSG_BYTES));
/* We need to make a temporary copy of the buffer, to allow the swap below */
temp_data = malloc(ram_buf.state_buf.size);
temp_data_size = ram_buf.state_buf.size;
temp_data = malloc(ram_buf.state_buf.size);
temp_data_size = ram_buf.state_buf.size;
memcpy(temp_data, ram_buf.state_buf.data, ram_buf.state_buf.size);
/* Swap the current state with the backup state. This way, we can undo
what we're undoing */
content_save_state("RAM", false, false);
ret = content_deserialize_state(temp_data, temp_data_size);
ret = content_deserialize_state(temp_data, temp_data_size);
/* Clean up the temporary copy */
free(temp_data);
temp_data = NULL;
temp_data = NULL;
if (!ret)
{
@ -1922,9 +1927,9 @@ bool content_load_state_from_ram(void)
/**
* content_save_state_from_ram:
* Save a state to ram.
* Save a state to RAM.
*
* Returns: true if successful, false otherwise.
* @return true if successful, false otherwise.
**/
bool content_save_state_to_ram(void)
{
@ -1947,9 +1952,7 @@ bool content_save_state_to_ram(void)
if (!save_state_in_background)
{
data = content_get_serialized_data(&serial_size);
if (!data)
if (!(data = content_get_serialized_data(&serial_size)))
{
RARCH_ERR("[State]: %s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
@ -1962,14 +1965,14 @@ bool content_save_state_to_ram(void)
msg_hash_to_str(MSG_BYTES));
}
if (!data)
data = content_get_serialized_data(&serial_size);
if (!data)
{
RARCH_ERR("[State]: %s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
return false;
if (!(data = content_get_serialized_data(&serial_size)))
{
RARCH_ERR("[State]: %s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
return false;
}
}
/* If we were holding onto an old state already, clean it up first */
@ -1979,8 +1982,7 @@ bool content_save_state_to_ram(void)
ram_buf.state_buf.data = NULL;
}
ram_buf.state_buf.data = malloc(serial_size);
if (!ram_buf.state_buf.data)
if (!(ram_buf.state_buf.data = malloc(serial_size)))
{
free(data);
return false;
@ -1989,7 +1991,7 @@ bool content_save_state_to_ram(void)
memcpy(ram_buf.state_buf.data, data, serial_size);
free(data);
ram_buf.state_buf.size = serial_size;
ram_buf.to_write_file = true;
ram_buf.to_write_file = true;
return true;
}
@ -1997,19 +1999,19 @@ bool content_save_state_to_ram(void)
/**
* content_ram_state_to_file:
* @path : path of ram state that shall be written to.
* Save a ram state from memory to disk.
* Save a RAM state from memory to disk.
*
* Returns: true if successful, false otherwise.
* @return true if successful, false otherwise.
**/
bool content_ram_state_to_file(const char *path)
{
settings_t *settings = config_get_ptr();
settings_t *settings = config_get_ptr();
#if defined(HAVE_ZLIB)
bool compress_files = settings->bools.save_file_compression;
bool compress_files = settings->bools.save_file_compression;
#else
bool compress_files = false;
bool compress_files = false;
#endif
bool write_success;
bool write_success = false;
if (!path)
return false;
@ -2030,9 +2032,12 @@ bool content_ram_state_to_file(const char *path)
path, ram_buf.state_buf.data, ram_buf.state_buf.size);
if (write_success)
{
ram_buf.to_write_file = false;
return true;
}
return write_success;
return false;
}
/**