Fix some string appending

This commit is contained in:
LibretroAdmin 2025-02-11 23:08:55 +01:00
parent 9f5bc9c318
commit 65b9ea4e76
6 changed files with 42 additions and 58 deletions

View File

@ -439,10 +439,10 @@ struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
} }
/* Set desc and info strings */ /* Set desc and info strings */
option_v2_cats[i].desc = string_is_empty(local_desc) ? option_v2_cats[i].desc = string_is_empty(local_desc)
options_v2_us->categories[i].desc : local_desc; ? options_v2_us->categories[i].desc : local_desc;
option_v2_cats[i].info = string_is_empty(local_info) ? option_v2_cats[i].info = string_is_empty(local_info)
options_v2_us->categories[i].info : local_info; ? options_v2_us->categories[i].info : local_info;
} }
@ -854,12 +854,10 @@ core_option_manager_t *core_option_manager_new_vars(
{ {
if (core_option_manager_parse_variable(opt, _len, var, config_src)) if (core_option_manager_parse_variable(opt, _len, var, config_src))
{ {
size_t __len = 0;
/* If variable is read correctly, add it to /* If variable is read correctly, add it to
* the map */ * the map */
char address[256]; char address[256];
address[ __len] = '#'; size_t __len = strlcpy(address, "#", sizeof(address));
address[++__len] = '\0';
/* Address string is normally: /* Address string is normally:
* <category_key><delim><tag><option_key> * <category_key><delim><tag><option_key>
@ -1043,8 +1041,8 @@ static bool core_option_manager_parse_option(
const char *value = option->vals->elems[i].data; const char *value = option->vals->elems[i].data;
uint32_t value_hash = *((uint32_t*)option->vals->elems[i].userdata); uint32_t value_hash = *((uint32_t*)option->vals->elems[i].userdata);
if ((value_hash == entry_value_hash) && if ( (value_hash == entry_value_hash)
string_is_equal(value, entry->value)) && string_is_equal(value, entry->value))
{ {
option->index = i; option->index = i;
break; break;
@ -1128,8 +1126,8 @@ core_option_manager_t *core_option_manager_new(
if (categorized && option_cats) if (categorized && option_cats)
{ {
for (option_cat = option_cats; for (option_cat = option_cats;
!string_is_empty(option_cat->key) && !string_is_empty(option_cat->key)
!string_is_empty(option_cat->desc); && !string_is_empty(option_cat->desc);
option_cat++) option_cat++)
cats_size++; cats_size++;
} }
@ -1157,8 +1155,8 @@ core_option_manager_t *core_option_manager_new(
/* Parse each category /* Parse each category
* > Note: 'option_cat->info == NULL' is valid */ * > Note: 'option_cat->info == NULL' is valid */
for (option_cat = option_cats; for (option_cat = option_cats;
!string_is_empty(option_cat->key) && !string_is_empty(option_cat->key)
!string_is_empty(option_cat->desc); && !string_is_empty(option_cat->desc);
cats_size++, option_cat++) cats_size++, option_cat++)
{ {
opt->cats[cats_size].key = strdup(option_cat->key); opt->cats[cats_size].key = strdup(option_cat->key);
@ -1518,9 +1516,9 @@ bool core_option_manager_get_val_idx(core_option_manager_t *opt,
const char *option_val = option->vals->elems[i].data; const char *option_val = option->vals->elems[i].data;
uint32_t option_val_hash = *((uint32_t*)option->vals->elems[i].userdata); uint32_t option_val_hash = *((uint32_t*)option->vals->elems[i].userdata);
if ((val_hash == option_val_hash) && if ( (val_hash == option_val_hash)
!string_is_empty(option_val) && && !string_is_empty(option_val)
string_is_equal(val, option_val)) && string_is_equal(val, option_val))
{ {
*val_idx = i; *val_idx = i;
return true; return true;
@ -1724,8 +1722,8 @@ void core_option_manager_set_val(core_option_manager_t *opt,
/* Refresh menu (if required) if core option /* Refresh menu (if required) if core option
* visibility has changed as a result of modifying * visibility has changed as a result of modifying
* the current option value */ * the current option value */
if (retroarch_ctl(RARCH_CTL_CORE_OPTION_UPDATE_DISPLAY, NULL) && if ( retroarch_ctl(RARCH_CTL_CORE_OPTION_UPDATE_DISPLAY, NULL)
refresh_menu) && refresh_menu)
{ {
struct menu_state *menu_st = menu_state_get_ptr(); struct menu_state *menu_st = menu_state_get_ptr();
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
@ -1776,8 +1774,8 @@ void core_option_manager_adjust_val(core_option_manager_t* opt,
/* Refresh menu (if required) if core option /* Refresh menu (if required) if core option
* visibility has changed as a result of modifying * visibility has changed as a result of modifying
* the current option value */ * the current option value */
if (retroarch_ctl(RARCH_CTL_CORE_OPTION_UPDATE_DISPLAY, NULL) && if ( retroarch_ctl(RARCH_CTL_CORE_OPTION_UPDATE_DISPLAY, NULL)
refresh_menu) && refresh_menu)
{ {
struct menu_state *menu_st = menu_state_get_ptr(); struct menu_state *menu_st = menu_state_get_ptr();
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
@ -1822,8 +1820,8 @@ void core_option_manager_set_default(core_option_manager_t *opt,
/* Refresh menu (if required) if core option /* Refresh menu (if required) if core option
* visibility has changed as a result of modifying * visibility has changed as a result of modifying
* the current option value */ * the current option value */
if (retroarch_ctl(RARCH_CTL_CORE_OPTION_UPDATE_DISPLAY, NULL) && if ( retroarch_ctl(RARCH_CTL_CORE_OPTION_UPDATE_DISPLAY, NULL)
refresh_menu) && refresh_menu)
{ {
struct menu_state *menu_st = menu_state_get_ptr(); struct menu_state *menu_st = menu_state_get_ptr();
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
@ -1859,9 +1857,9 @@ void core_option_manager_set_visible(core_option_manager_t *opt,
{ {
struct core_option *option = &opt->opts[i]; struct core_option *option = &opt->opts[i];
if ((key_hash == option->key_hash) && if ( (key_hash == option->key_hash)
!string_is_empty(option->key) && && !string_is_empty(option->key)
string_is_equal(key, option->key)) && string_is_equal(key, option->key))
{ {
option->visible = visible; option->visible = visible;
return; return;

View File

@ -623,10 +623,8 @@ bool disk_control_append_image(
goto error; goto error;
/* Display log */ /* Display log */
_len = strlcpy(msg, msg_hash_to_str(MSG_APPENDED_DISK), sizeof(msg)); _len = strlcpy(msg, msg_hash_to_str(MSG_APPENDED_DISK), sizeof(msg));
msg[ _len] = ':'; _len += strlcpy(msg + _len, ": ", sizeof(msg) - _len);
msg[++_len] = ' ';
msg[++_len] = '\0';
_len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len); _len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
RARCH_LOG("[Disc]: %s\n", msg); RARCH_LOG("[Disc]: %s\n", msg);
@ -652,11 +650,9 @@ error:
if (!initial_disk_ejected) if (!initial_disk_ejected)
disk_control_set_eject_state(disk_control, false, false); disk_control_set_eject_state(disk_control, false, false);
_len = strlcpy(msg, _len = strlcpy(msg,
msg_hash_to_str(MSG_FAILED_TO_APPEND_DISK), sizeof(msg)); msg_hash_to_str(MSG_FAILED_TO_APPEND_DISK), sizeof(msg));
msg[ _len] = ':'; _len += strlcpy(msg + _len, ": ", sizeof(msg) - _len);
msg[++_len] = ' ';
msg[++_len] = '\0';
_len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len); _len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
runloop_msg_queue_push(msg, _len, 0, 180, true, NULL, runloop_msg_queue_push(msg, _len, 0, 180, true, NULL,

View File

@ -1006,10 +1006,7 @@ size_t fill_pathname_join_special(char *s,
{ {
/* Try to preserve slash type. */ /* Try to preserve slash type. */
if (last_slash != (s + _len - 1)) if (last_slash != (s + _len - 1))
{ _len += strlcpy(s + _len, &last_slash[0], len - _len);
s[ _len] = last_slash[0];
s[++_len] = '\0';
}
} }
else else
{ {
@ -1388,8 +1385,7 @@ size_t fill_pathname_application_path(char *s, size_t len)
if (realpath(s, resolved_bundle_dir_buf)) if (realpath(s, resolved_bundle_dir_buf))
{ {
size_t _len = strlcpy(s, resolved_bundle_dir_buf, len - 1); size_t _len = strlcpy(s, resolved_bundle_dir_buf, len - 1);
s[ _len] = '/'; _len += strlcpy(s + _len, "/", len - _len);
s[++_len] = '\0';
rv = _len; rv = _len;
} }
} }

View File

@ -3039,11 +3039,8 @@ static void rgui_update_dynamic_theme_path(
{ {
size_t _len = fill_pathname_join_special(rgui->theme_dynamic_path, theme_dir, size_t _len = fill_pathname_join_special(rgui->theme_dynamic_path, theme_dir,
rgui->menu_title, sizeof(rgui->theme_dynamic_path)); rgui->menu_title, sizeof(rgui->theme_dynamic_path));
rgui->theme_dynamic_path[ _len] = '.'; _len += strlcpy(rgui->theme_dynamic_path + _len, ".cfg",
rgui->theme_dynamic_path[++_len] = 'c'; sizeof(rgui->theme_dynamic_path) - _len);
rgui->theme_dynamic_path[++_len] = 'f';
rgui->theme_dynamic_path[++_len] = 'g';
rgui->theme_dynamic_path[++_len] = '\0';
use_playlist_theme = path_is_valid(rgui->theme_dynamic_path); use_playlist_theme = path_is_valid(rgui->theme_dynamic_path);
} }

View File

@ -5888,12 +5888,14 @@ static int menu_displaylist_parse_input_description_list(
sizeof(input_description)); sizeof(input_description));
if (i >= RARCH_FIRST_CUSTOM_BIND) if (i >= RARCH_FIRST_CUSTOM_BIND)
{ {
input_description [ _len] = ' '; _len += strlcpy(input_description + _len, " ",
sizeof(input_description) - _len);
if ((i % 2) == 0) if ((i % 2) == 0)
input_description[++_len] = '+'; _len += strlcpy(input_description + _len, "+",
sizeof(input_description) - _len);
else else
input_description[++_len] = '-'; _len += strlcpy(input_description + _len, "-",
input_description [++_len] = '\0'; sizeof(input_description) - _len);
} }
if (string_is_empty(input_description)) if (string_is_empty(input_description))
@ -8152,14 +8154,11 @@ unsigned menu_displaylist_build_list(
{ {
/* On/off key strings may be required, /* On/off key strings may be required,
* so populate them... */ * so populate them... */
on_string [ _len] = '.'; _len = strlcpy(on_string, ".", sizeof(on_string));
on_string [++_len] = '\0';
strlcpy(on_string + _len, strlcpy(on_string + _len,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON),
sizeof(on_string) - _len); sizeof(on_string) - _len);
_len = 0; _len = strlcpy(off_string, ".", sizeof(off_string));
off_string[ _len] = '.';
off_string[++_len] = '\0';
strlcpy(off_string + _len, strlcpy(off_string + _len,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF),
sizeof(off_string) - _len); sizeof(off_string) - _len);

View File

@ -866,11 +866,9 @@ static void content_file_get_path(
{ {
char info_path[PATH_MAX_LENGTH]; char info_path[PATH_MAX_LENGTH];
/* Build 'complete' archive file path */ /* Build 'complete' archive file path */
size_t _len = strlcpy(info_path, size_t _len = strlcpy(info_path, content_path, sizeof(info_path));
content_path, sizeof(info_path)); _len += strlcpy(info_path + _len, "#",
info_path[_len ] = '#'; sizeof(info_path) - _len);
info_path[_len+1] = '\0';
_len += 1;
strlcpy(info_path + _len, archive_file, sizeof(info_path) - _len); strlcpy(info_path + _len, archive_file, sizeof(info_path) - _len);
/* Update 'content' string_list */ /* Update 'content' string_list */