Skip to content

Commit

Permalink
Replace more strlcat calls with strlcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jun 18, 2023
1 parent c723710 commit edecf0c
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 184 deletions.
3 changes: 2 additions & 1 deletion gfx/common/win32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,8 @@ static void win32_localize_menu(HMENU menu)
buf_size);
new_label_text[_len ] = '\t';
new_label_text[_len+1] = '\0';
strlcat(new_label_text, meta_key_name, buf_size);
_len += 1;
strlcpy(new_label_text + _len, meta_key_name, buf_size - _len);
/* Make first character of shortcut name uppercase */
new_label_text[len1 + 1] = toupper(new_label_text[len1 + 1]);
}
Expand Down
12 changes: 6 additions & 6 deletions libretro-common/cdrom/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,9 @@ struct string_list* cdrom_get_available_drives(void)
if (string_starts_with_size(dir_list->elems[i].data, "/dev/sg",
STRLEN_CONST("/dev/sg")))
{
char drive_string[33];
libretro_vfs_implementation_file *stream;
char drive_model[32] = {0};
char drive_string[33] = {0};
union string_list_elem_attr attr = {0};
int dev_index = 0;
RFILE *file = filestream_open(
Expand Down Expand Up @@ -1380,9 +1380,9 @@ struct string_list* cdrom_get_available_drives(void)
attr.i = dev_index;

if (!string_is_empty(drive_model))
strlcat(drive_string, drive_model, sizeof(drive_string));
strlcpy(drive_string, drive_model, sizeof(drive_string));
else
strlcat(drive_string, "Unknown Drive", sizeof(drive_string));
strlcpy(drive_string, "Unknown Drive", sizeof(drive_string));

string_list_append(list, drive_string, attr);
}
Expand Down Expand Up @@ -1462,10 +1462,10 @@ struct string_list* cdrom_get_available_drives(void)
continue;

{
char drive_string[33];
libretro_vfs_implementation_file *stream;
bool is_cdrom = false;
char drive_model[32] = {0};
char drive_string[33] = {0};
union string_list_elem_attr attr = {0};
RFILE *file = filestream_open(cdrom_path, RETRO_VFS_FILE_ACCESS_READ, 0);
if (!file)
Expand All @@ -1481,9 +1481,9 @@ struct string_list* cdrom_get_available_drives(void)
attr.i = path[0];

if (!string_is_empty(drive_model))
strlcat(drive_string, drive_model, sizeof(drive_string));
strlcpy(drive_string, drive_model, sizeof(drive_string));
else
strlcat(drive_string, "Unknown Drive", sizeof(drive_string));
strlcpy(drive_string, "Unknown Drive", sizeof(drive_string));

string_list_append(list, drive_string, attr);
}
Expand Down
4 changes: 2 additions & 2 deletions libretro-common/file/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ static void config_file_get_realpath(char *s, size_t len,
const char *home = getenv("HOME");
if (home)
{
strlcpy(s, home, len);
strlcat(s, path + 1, len);
size_t _len = strlcpy(s, home, len);
strlcpy(s + _len, path + 1, len - _len);
}
else
strlcpy(s, path + 1, len);
Expand Down
3 changes: 2 additions & 1 deletion libretro-common/net/net_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ void net_http_urlencode_full(char *dest,
buf_pos = strlcpy(dest, url_domain, size);
dest[buf_pos] = '/';
dest[buf_pos+1] = '\0';
strlcat(dest, tmp, size);
buf_pos += 1;
strlcpy(dest + buf_pos, tmp, size - buf_pos);
free (tmp);
}

Expand Down
8 changes: 2 additions & 6 deletions menu/cbs/menu_cbs_deferred_push.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,15 @@ static int general_push(menu_displaylist_info_t *info,
{
/* Need to use the scratch buffer here */
char tmp_str[PATH_MAX_LENGTH];
char tmp_str2[PATH_MAX_LENGTH];
fill_pathname_join_special(tmp_str, menu->scratch2_buf,
menu->scratch_buf, sizeof(tmp_str));
fill_pathname_join_special(tmp_str2, menu->scratch2_buf,
menu->scratch_buf, sizeof(tmp_str2));

if (!string_is_empty(info->path))
free(info->path);
info->path = strdup(tmp_str);
if (!string_is_empty(info->label))
free(info->label);

info->path = strdup(tmp_str);
info->label = strdup(tmp_str2);
info->label = strdup(tmp_str);
}

info->type_default = FILE_TYPE_PLAIN;
Expand Down
52 changes: 23 additions & 29 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -3856,6 +3856,7 @@ static int action_ok_path_manual_scan_directory(const char *path,
static int action_ok_core_deferred_set(const char *new_core_path,
const char *content_label, unsigned type, size_t idx, size_t entry_idx)
{
size_t _len;
char msg[PATH_MAX_LENGTH];
char resolved_core_path[PATH_MAX_LENGTH];
struct menu_state *menu_st = menu_state_get_ptr();
Expand Down Expand Up @@ -3891,8 +3892,8 @@ static int action_ok_core_deferred_set(const char *new_core_path,
&entry);

/* Provide visual feedback */
strlcpy(msg, msg_hash_to_str(MSG_SET_CORE_ASSOCIATION), sizeof(msg));
strlcat(msg, core_display_name, sizeof(msg));
_len = strlcpy(msg, msg_hash_to_str(MSG_SET_CORE_ASSOCIATION), sizeof(msg));
strlcpy(msg + _len, core_display_name, sizeof(msg) - _len);
runloop_msg_queue_push(msg, 1, 100, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);

menu_entries_pop_stack(&selection, 0, 1);
Expand Down Expand Up @@ -3947,18 +3948,18 @@ static int action_ok_set_switch_cpu_profile(const char *path,
#endif

#ifdef HAVE_LAKKA_SWITCH

static int action_ok_set_switch_gpu_profile(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
size_t _len;
char command[PATH_MAX_LENGTH];
char *profile_name = SWITCH_GPU_PROFILES[entry_idx];
size_t _len = strlcpy(command, "gpu-profile set ", sizeof(command));
snprintf(command + _len, sizeof(command) - _len, "'%s'", profile_name);
system(command);
/* TODO/FIXME - localize */
strlcpy(command, "Current profile set to ", sizeof(command));
strlcat(command, profile_name, sizeof(command));
_len = strlcpy(command, "Current profile set to ", sizeof(command));
strlcpy(command + _len, profile_name, sizeof(command) - _len);
runloop_msg_queue_push(command, 1, 90, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
return -1;
Expand Down Expand Up @@ -7664,12 +7665,11 @@ int action_ok_core_lock(const char *path,

if (!core_info_set_core_lock(core_path, lock))
{
size_t _len;
const char *core_name = NULL;
core_info_t *core_info = NULL;
char msg[PATH_MAX_LENGTH];

msg[0] = '\0';

/* Need to fetch core name for error message */

/* If core is found, use display name */
Expand All @@ -7681,20 +7681,18 @@ int action_ok_core_lock(const char *path,
core_name = path_basename_nocompression(core_path);

/* Build error message */
strlcpy(
msg,
_len = strlcpy(msg,
msg_hash_to_str(lock ?
MSG_CORE_LOCK_FAILED : MSG_CORE_UNLOCK_FAILED),
sizeof(msg));

if (!string_is_empty(core_name))
strlcat(msg, core_name, sizeof(msg));
strlcpy(msg + _len, core_name, sizeof(msg) - _len);

/* Generate log + notification */
RARCH_ERR("%s\n", msg);

runloop_msg_queue_push(
msg,
runloop_msg_queue_push(msg,
1, 100, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);

Expand Down Expand Up @@ -7728,12 +7726,11 @@ int action_ok_core_set_standalone_exempt(const char *path,

if (!core_info_set_core_standalone_exempt(core_path, exempt))
{
const char *core_name = NULL;
size_t _len;
const char *core_name = NULL;
core_info_t *core_info = NULL;
char msg[PATH_MAX_LENGTH];

msg[0] = '\0';

/* Need to fetch core name for error message */

/* If core is found, use display name */
Expand All @@ -7745,15 +7742,14 @@ int action_ok_core_set_standalone_exempt(const char *path,
core_name = path_basename_nocompression(core_path);

/* Build error message */
strlcpy(
msg,
_len = strlcpy(msg,
msg_hash_to_str(exempt ?
MSG_CORE_SET_STANDALONE_EXEMPT_FAILED :
MSG_CORE_UNSET_STANDALONE_EXEMPT_FAILED),
sizeof(msg));

if (!string_is_empty(core_name))
strlcat(msg, core_name, sizeof(msg));
strlcpy(msg + _len, core_name, sizeof(msg) - _len);

/* Generate log + notification */
RARCH_ERR("%s\n", msg);
Expand All @@ -7780,12 +7776,11 @@ static int action_ok_core_delete(const char *path,
/* Check whether core is locked */
if (core_info_get_core_lock(core_path, true))
{
size_t _len;
const char *core_name = NULL;
core_info_t *core_info = NULL;
char msg[PATH_MAX_LENGTH];

msg[0] = '\0';

/* Need to fetch core name for notification */

/* If core is found, use display name */
Expand All @@ -7797,10 +7792,10 @@ static int action_ok_core_delete(const char *path,
core_name = path_basename_nocompression(core_path);

/* Build notification message */
strlcpy(msg, msg_hash_to_str(MSG_CORE_DELETE_DISABLED), sizeof(msg));
_len = strlcpy(msg, msg_hash_to_str(MSG_CORE_DELETE_DISABLED), sizeof(msg));

if (!string_is_empty(core_name))
strlcat(msg, core_name, sizeof(msg));
strlcpy(msg + _len, core_name, sizeof(msg) - _len);

runloop_msg_queue_push(
msg,
Expand All @@ -7827,11 +7822,10 @@ static int action_ok_core_delete(const char *path,
* interface */
if (play_feature_delivery_enabled())
{
size_t _len;
const char *core_filename = path_basename_nocompression(core_path);
char backup_core_path[PATH_MAX_LENGTH];

backup_core_path[0] = '\0';

if (play_feature_delivery_core_installed(core_filename))
play_feature_delivery_delete(core_filename);
else
Expand All @@ -7846,13 +7840,13 @@ static int action_ok_core_delete(const char *path,
* accumulation of mess, additionally check
* for and remove any such backups when deleting
* a core */
strlcpy(backup_core_path, core_path,
sizeof(backup_core_path));
strlcat(backup_core_path, FILE_PATH_BACKUP_EXTENSION,
_len = strlcpy(backup_core_path, core_path,
sizeof(backup_core_path));
strlcpy(backup_core_path + _len, FILE_PATH_BACKUP_EXTENSION,
sizeof(backup_core_path) - _len);

if (!string_is_empty(backup_core_path) &&
path_is_valid(backup_core_path))
if ( !string_is_empty(backup_core_path)
&& path_is_valid(backup_core_path))
filestream_delete(backup_core_path);
}
else
Expand Down
10 changes: 6 additions & 4 deletions menu/cbs/menu_cbs_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ static int action_start_core_lock(
/* ...Otherwise, attempt to unlock it */
if (!core_info_set_core_lock(core_path, false))
{
size_t _len;
const char *core_name = NULL;
core_info_t *core_info = NULL;
char msg[PATH_MAX_LENGTH];
Expand All @@ -721,10 +722,10 @@ static int action_start_core_lock(
core_name = path_basename_nocompression(core_path);

/* Build error message */
strlcpy(msg, msg_hash_to_str(MSG_CORE_UNLOCK_FAILED), sizeof(msg));
_len = strlcpy(msg, msg_hash_to_str(MSG_CORE_UNLOCK_FAILED), sizeof(msg));

if (!string_is_empty(core_name))
strlcat(msg, core_name, sizeof(msg));
strlcpy(msg + _len, core_name, sizeof(msg) - _len);

/* Generate log + notification */
RARCH_ERR("%s\n", msg);
Expand Down Expand Up @@ -765,6 +766,7 @@ static int action_start_core_set_standalone_exempt(
/* ...Otherwise, attempt to unset the exempt flag */
if (!core_info_set_core_standalone_exempt(core_path, false))
{
size_t _len;
const char *core_name = NULL;
core_info_t *core_info = NULL;
char msg[PATH_MAX_LENGTH];
Expand All @@ -780,12 +782,12 @@ static int action_start_core_set_standalone_exempt(
core_name = path_basename_nocompression(core_path);

/* Build error message */
strlcpy(msg,
_len = strlcpy(msg,
msg_hash_to_str(MSG_CORE_UNSET_STANDALONE_EXEMPT_FAILED),
sizeof(msg));

if (!string_is_empty(core_name))
strlcat(msg, core_name, sizeof(msg));
strlcpy(msg + _len, core_name, sizeof(msg) - _len);

/* Generate log + notification */
RARCH_ERR("%s\n", msg);
Expand Down
13 changes: 8 additions & 5 deletions menu/drivers/ozone.c
Original file line number Diff line number Diff line change
Expand Up @@ -4148,7 +4148,8 @@ static void ozone_update_content_metadata(ozone_handle_t *ozone)
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));
_len += 1;
strlcpy(ozone->selection_core_name + _len, core_label, sizeof(ozone->selection_core_name) - _len);

if (!scroll_content_metadata)
linebreak_after_colon(&ozone->selection_core_name);
Expand Down Expand Up @@ -4198,15 +4199,17 @@ static void ozone_update_content_metadata(ozone_handle_t *ozone)
sizeof(ozone->selection_playtime));
ozone->selection_playtime[_len ] = ' ';
ozone->selection_playtime[_len+1] = '\0';
strlcat(ozone->selection_playtime, disabled_str, sizeof(ozone->selection_playtime));
_len += 1;
strlcpy(ozone->selection_playtime + _len, disabled_str, sizeof(ozone->selection_playtime) - _len);

_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));
_len += 1;
strlcpy(ozone->selection_lastplayed + _len, disabled_str, sizeof(ozone->selection_lastplayed) - _len);
}

if (!scroll_content_metadata)
Expand Down Expand Up @@ -9224,8 +9227,8 @@ static void ozone_context_reset(void *data, bool is_threaded)
#ifdef HAVE_DISCORD_OWN_AVATAR
if (i == OZONE_TEXTURE_DISCORD_OWN_AVATAR && discord_avatar_is_ready())
{
strlcpy(filename, discord_get_own_avatar(), sizeof(filename));
strlcat(filename, FILE_PATH_PNG_EXTENSION, sizeof(filename));
size_t _len = strlcpy(filename, discord_get_own_avatar(), sizeof(filename));
strlcpy(filename + _len, FILE_PATH_PNG_EXTENSION, sizeof(filename) - _len);
}
else
#endif
Expand Down
Loading

0 comments on commit edecf0c

Please sign in to comment.