Rewrite some strlcat calls to strlcpy

This commit is contained in:
libretroadmin 2023-06-20 13:21:26 +02:00
parent 1c4dc615e1
commit fa80ec099f
5 changed files with 81 additions and 63 deletions

View File

@ -3392,6 +3392,7 @@ static bool materialui_render_process_entry_playlist_desktop(
if (mui->status_bar.delay_timer > mui->thumbnail_stream_delay) if (mui->status_bar.delay_timer > mui->thumbnail_stream_delay)
{ {
size_t _len;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool content_runtime_log = settings->bools.content_runtime_log; bool content_runtime_log = settings->bools.content_runtime_log;
bool content_runtime_log_aggregate = settings->bools.content_runtime_log_aggregate; bool content_runtime_log_aggregate = settings->bools.content_runtime_log_aggregate;
@ -3462,21 +3463,27 @@ static bool materialui_render_process_entry_playlist_desktop(
last_played_str = mui->status_bar.last_played_fallback_str; last_played_str = mui->status_bar.last_played_fallback_str;
/* Generate metadata string */ /* Generate metadata string */
strlcpy(mui->status_bar.str, _len = strlcpy(mui->status_bar.str,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE),
sizeof(mui->status_bar.str)); sizeof(mui->status_bar.str));
strlcat(mui->status_bar.str, " ", _len += strlcpy(mui->status_bar.str + _len,
sizeof(mui->status_bar.str)); " ",
strlcat(mui->status_bar.str, core_name, sizeof(mui->status_bar.str) - _len);
sizeof(mui->status_bar.str)); _len += strlcpy(mui->status_bar.str + _len,
strlcat(mui->status_bar.str, MUI_TICKER_SPACER, core_name,
sizeof(mui->status_bar.str)); sizeof(mui->status_bar.str) - _len);
strlcat(mui->status_bar.str, runtime_str, _len += strlcpy(mui->status_bar.str + _len,
sizeof(mui->status_bar.str)); MUI_TICKER_SPACER,
strlcat(mui->status_bar.str, MUI_TICKER_SPACER, sizeof(mui->status_bar.str) - _len);
sizeof(mui->status_bar.str)); _len += strlcpy(mui->status_bar.str + _len,
strlcat(mui->status_bar.str, last_played_str, runtime_str,
sizeof(mui->status_bar.str)); sizeof(mui->status_bar.str) - _len);
_len += strlcpy(mui->status_bar.str + _len,
MUI_TICKER_SPACER,
sizeof(mui->status_bar.str) - _len);
_len += strlcpy(mui->status_bar.str + _len,
last_played_str,
sizeof(mui->status_bar.str) - _len);
/* All metadata is cached */ /* All metadata is cached */
mui->status_bar.cached = true; mui->status_bar.cached = true;

View File

@ -1535,17 +1535,17 @@ static unsigned menu_displaylist_parse_supported_cores(menu_displaylist_info_t *
* to the displaylist */ * to the displaylist */
if (core_is_pending) if (core_is_pending)
{ {
size_t _len;
char entry_alt_text[256]; char entry_alt_text[256];
_len = strlcpy(entry_alt_text, detect_core_str, size_t _len = strlcpy(entry_alt_text, detect_core_str,
sizeof(entry_alt_text)); sizeof(entry_alt_text));
entry_alt_text[_len ] = ' '; entry_alt_text[_len ] = ' ';
entry_alt_text[_len+1] = '('; entry_alt_text[++_len] = '(';
entry_alt_text[_len+2] = '\0'; entry_alt_text[++_len] = '\0';
_len = strlcat(entry_alt_text, _len += strlcpy(entry_alt_text + _len,
pending_core_name, sizeof(entry_alt_text)); pending_core_name,
sizeof(entry_alt_text) - _len);
entry_alt_text[_len ] = ')'; entry_alt_text[_len ] = ')';
entry_alt_text[_len+1] = '\0'; entry_alt_text[++_len] = '\0';
menu_entries_prepend(info->list, pending_core_path, menu_entries_prepend(info->list, pending_core_path,
msg_hash_to_str(current_core_enum_label), msg_hash_to_str(current_core_enum_label),
@ -6386,24 +6386,28 @@ static unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list)
{ {
if (!show_passworded) if (!show_passworded)
continue; continue;
_len = strlcpy(passworded, "[", sizeof(passworded)); _len = strlcpy(passworded, "[",
strlcpy(passworded + _len, msg_room_pwd, sizeof(passworded) - _len); sizeof(passworded));
strlcat(passworded, "] ", sizeof(passworded)); _len += strlcpy(passworded + _len,
msg_room_pwd,
sizeof(passworded) - _len);
_len += strlcpy(passworded + _len, "] ",
sizeof(passworded) - _len);
} }
else else
*passworded = '\0'; *passworded = '\0';
_len = strlcpy(buf, passworded, sizeof(buf)); _len = strlcpy(buf, passworded, sizeof(buf));
strlcpy(buf + _len, room_type, sizeof(buf) - _len); _len += strlcpy(buf + _len, room_type, sizeof(buf) - _len);
strlcat(buf, ": ", sizeof(buf)); _len += strlcpy(buf + _len, ": ", sizeof(buf) - _len);
strlcat(buf, room->nickname, sizeof(buf)); _len += strlcpy(buf + _len, room->nickname, sizeof(buf) - _len);
if (!room->lan && !string_is_empty(room->country)) if (!room->lan && !string_is_empty(room->country))
{ {
_len = strlcpy(country, " (", sizeof(country)); size_t _len2 = strlcpy(country, " (", sizeof(country));
strlcpy(country + _len, room->country, sizeof(country) - _len); _len2 += strlcpy(country + _len2, room->country, sizeof(country) - _len2);
strlcat(country, ")", sizeof(country)); _len2 += strlcpy(country + _len2, ")", sizeof(country) - _len2);
strlcat(buf, country, sizeof(buf)); strlcpy(buf + _len, country, sizeof(buf) - _len);
} }
else else
*country = '\0'; *country = '\0';
@ -11647,8 +11651,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
size_t _len = strlcpy(serial, size_t _len = strlcpy(serial,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RDB_ENTRY_SERIAL), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RDB_ENTRY_SERIAL),
sizeof(serial)); sizeof(serial));
strlcpy(serial + _len, "#: ", sizeof(serial) - _len); _len += strlcpy(serial + _len, "#: ", sizeof(serial) - _len);
strlcat(serial, cd_info.serial, sizeof(serial)); strlcpy(serial + _len, cd_info.serial, sizeof(serial) - _len);
if (menu_entries_append(info->list, if (menu_entries_append(info->list,
serial, serial,
@ -11961,6 +11965,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
#if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) #if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX)
case DISPLAYLIST_SWITCH_CPU_PROFILE: case DISPLAYLIST_SWITCH_CPU_PROFILE:
{ {
size_t _len;
unsigned i; unsigned i;
char text[PATH_MAX_LENGTH]; char text[PATH_MAX_LENGTH];
#ifdef HAVE_LAKKA_SWITCH #ifdef HAVE_LAKKA_SWITCH
@ -11977,11 +11982,10 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
fgets(current_profile, PATH_MAX_LENGTH, profile); fgets(current_profile, PATH_MAX_LENGTH, profile);
pclose(profile); pclose(profile);
/* TODO/FIXME - localize */ /* TODO/FIXME - localize */
strlcpy(text, "Current profile: ", sizeof(text)); _len = strlcpy(text, "Current profile: ", sizeof(text));
strlcat(text, current_profile, sizeof(text)); strlcpy(text + _len, current_profile, sizeof(text) - _len);
#else #else
{ {
size_t _len;
u32 currentClock = 0; u32 currentClock = 0;
if (hosversionBefore(8, 0, 0)) if (hosversionBefore(8, 0, 0))
pcvGetClockRate(PcvModule_CpuBus, &currentClock); pcvGetClockRate(PcvModule_CpuBus, &currentClock);
@ -12022,6 +12026,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
#if defined(HAVE_LAKKA_SWITCH) #if defined(HAVE_LAKKA_SWITCH)
case DISPLAYLIST_SWITCH_GPU_PROFILE: case DISPLAYLIST_SWITCH_GPU_PROFILE:
{ {
size_t _len;
unsigned i; unsigned i;
char text[PATH_MAX_LENGTH]; char text[PATH_MAX_LENGTH];
char current_profile[PATH_MAX_LENGTH]; char current_profile[PATH_MAX_LENGTH];
@ -12038,8 +12043,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
menu_entries_clear(info->list); menu_entries_clear(info->list);
/* TODO/FIXME - Localize */ /* TODO/FIXME - Localize */
strlcpy(text, "Current profile : ", sizeof(text)); _len = strlcpy(text, "Current profile : ", sizeof(text));
strlcat(text, current_profile, sizeof(text)); strlcpy(text + _len, current_profile, sizeof(text) - _len);
if (menu_entries_append(info->list, text, "", 0, MENU_INFO_MESSAGE, 0, 0, NULL)) if (menu_entries_append(info->list, text, "", 0, MENU_INFO_MESSAGE, 0, 0, NULL))
count++; count++;
@ -12049,7 +12054,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
char title[PATH_MAX_LENGTH]; char title[PATH_MAX_LENGTH];
char* profile = SWITCH_GPU_PROFILES[i]; char* profile = SWITCH_GPU_PROFILES[i];
char* speed = SWITCH_GPU_SPEEDS[i]; char* speed = SWITCH_GPU_SPEEDS[i];
size_t _len = strlcpy(title, profile, sizeof(title)); _len = strlcpy(title, profile, sizeof(title));
snprintf(title + _len, sizeof(title) - _len, " (%s)", speed); snprintf(title + _len, sizeof(title) - _len, " (%s)", speed);
if (menu_entries_append(info->list, title, "", 0, if (menu_entries_append(info->list, title, "", 0,
MENU_SET_SWITCH_GPU_PROFILE, 0, i, NULL)) MENU_SET_SWITCH_GPU_PROFILE, 0, i, NULL))

View File

@ -426,10 +426,11 @@ static void explore_load_icons(explore_state_t *state)
for (i = 0; i != system_count; i++) for (i = 0; i != system_count; i++)
{ {
struct texture_image ti; struct texture_image ti;
size_t _len = pathlen;
strlcpy(path + pathlen, _len += strlcpy(path + pathlen,
state->by[EXPLORE_BY_SYSTEM][i]->str, sizeof(path) - pathlen); state->by[EXPLORE_BY_SYSTEM][i]->str,
strlcat(path, ".png", sizeof(path)); sizeof(path) - pathlen);
strlcpy(path + _len, ".png", sizeof(path) - _len);
if (!path_is_valid(path)) if (!path_is_valid(path))
continue; continue;
@ -1052,6 +1053,7 @@ static int explore_action_ok_deleteview(const char *path, const char *label, uns
static void explore_action_saveview_complete(void *userdata, const char *name) static void explore_action_saveview_complete(void *userdata, const char *name)
{ {
size_t _len;
int count = 0, op; int count = 0, op;
char lvwpath[PATH_MAX_LENGTH]; char lvwpath[PATH_MAX_LENGTH];
intfstream_t *file; intfstream_t *file;

View File

@ -72,14 +72,16 @@ static int file_decompressed_subdir(const char *name,
error: error:
userdata->dec->callback_error = (char*)malloc(CALLBACK_ERROR_SIZE); userdata->dec->callback_error = (char*)malloc(CALLBACK_ERROR_SIZE);
strlcpy(userdata->dec->callback_error, "Failed to deflate ", _len = strlcpy(userdata->dec->callback_error,
"Failed to deflate ",
CALLBACK_ERROR_SIZE); CALLBACK_ERROR_SIZE);
_len = strlcat( _len += strlcpy(
userdata->dec->callback_error, userdata->dec->callback_error + _len,
path, CALLBACK_ERROR_SIZE); path,
CALLBACK_ERROR_SIZE - _len);
userdata->dec->callback_error[ _len] = '.'; userdata->dec->callback_error[ _len] = '.';
userdata->dec->callback_error[_len+1] = '\n'; userdata->dec->callback_error[++_len] = '\n';
userdata->dec->callback_error[_len+2] = '\0'; userdata->dec->callback_error[++_len] = '\0';
return 0; return 0;
} }
@ -113,13 +115,13 @@ static int file_decompressed(const char *name, const char *valid_exts,
error: error:
dec->callback_error = (char*)malloc(CALLBACK_ERROR_SIZE); dec->callback_error = (char*)malloc(CALLBACK_ERROR_SIZE);
strlcpy(dec->callback_error, "Failed to deflate ", _len = strlcpy(dec->callback_error, "Failed to deflate ",
CALLBACK_ERROR_SIZE); CALLBACK_ERROR_SIZE);
_len = strlcat(dec->callback_error, _len += strlcpy(dec->callback_error + _len,
path, CALLBACK_ERROR_SIZE); path, CALLBACK_ERROR_SIZE - _len);
dec->callback_error[ _len] = '.'; dec->callback_error[ _len] = '.';
dec->callback_error[_len+1] = '\n'; dec->callback_error[++_len] = '\n';
dec->callback_error[_len+2] = '\0'; dec->callback_error[++_len] = '\0';
return 0; return 0;
} }
@ -340,11 +342,13 @@ void *task_push_decompress(
_len = strlcpy(tmp, _len = strlcpy(tmp,
msg_hash_to_str(MSG_EXTRACTING), sizeof(tmp)); msg_hash_to_str(MSG_EXTRACTING), sizeof(tmp));
tmp[ _len] = ' '; tmp[ _len] = ' ';
tmp[_len+1] = '\''; tmp[++_len] = '\'';
tmp[_len+2] = '\0'; tmp[++_len] = '\0';
_len = strlcat(tmp, path_basename(source_file), sizeof(tmp)); _len += strlcpy(tmp + _len,
path_basename(source_file),
sizeof(tmp) - _len);
tmp[_len ] = '\''; tmp[_len ] = '\'';
tmp[_len+1] = '\0'; tmp[++_len] = '\0';
t->title = strdup(tmp); t->title = strdup(tmp);
t->mute = mute; t->mute = mute;