Get rid of some strlcats

This commit is contained in:
LibretroAdmin 2022-08-08 22:41:32 +02:00
parent 05cf639712
commit a6e210e9db
6 changed files with 106 additions and 48 deletions

View File

@ -1347,7 +1347,7 @@ static core_path_list_t *core_info_path_list_new(const char *core_dir,
struct string_list *core_ext_list = NULL; struct string_list *core_ext_list = NULL;
bool dir_list_ok = false; bool dir_list_ok = false;
char exts[32]; char exts[32];
size_t i; size_t i, len;
if (string_is_empty(core_exts) || if (string_is_empty(core_exts) ||
!path_list) !path_list)
@ -1373,13 +1373,21 @@ static core_path_list_t *core_info_path_list_new(const char *core_dir,
/* Get list of file extensions to include /* Get list of file extensions to include
* > core + lock */ * > core + lock */
strlcpy(exts, core_exts, sizeof(exts)); len = strlcpy(exts, core_exts, sizeof(exts));
strlcat(exts, "|" FILE_PATH_LOCK_EXTENSION_NO_DOT, exts[len ] = '|';
sizeof(exts)); exts[len+1] = 'l';
exts[len+2] = 'c';
exts[len+3] = 'k';
#if defined(HAVE_DYNAMIC) #if defined(HAVE_DYNAMIC)
/* > 'standalone exempt' */ /* > 'standalone exempt' */
strlcat(exts, "|" FILE_PATH_STANDALONE_EXEMPT_EXTENSION_NO_DOT, exts[len+4] = '|';
sizeof(exts)); exts[len+5] = 'l';
exts[len+6] = 's';
exts[len+7] = 'a';
exts[len+8] = 'e';
exts[len+9] = '\0';
#else
exts[len+4] = '\0';
#endif #endif
/* Fetch core directory listing */ /* Fetch core directory listing */
@ -1512,17 +1520,21 @@ static bool core_info_path_is_standalone_exempt(
core_aux_file_path_list_t *exempt_list, core_aux_file_path_list_t *exempt_list,
const char *core_file_name) const char *core_file_name)
{ {
size_t i; size_t i, len;
uint32_t hash; uint32_t hash;
char exempt_filename[NAME_MAX_LENGTH]; char exempt_filename[NAME_MAX_LENGTH];
if (exempt_list->size < 1) if (exempt_list->size < 1)
return false; return false;
strlcpy(exempt_filename, core_file_name, len = strlcpy(exempt_filename, core_file_name,
sizeof(exempt_filename));
strlcat(exempt_filename, FILE_PATH_STANDALONE_EXEMPT_EXTENSION,
sizeof(exempt_filename)); sizeof(exempt_filename));
exempt_filename[len ] = '.';
exempt_filename[len+1] = 'l';
exempt_filename[len+2] = 's';
exempt_filename[len+3] = 'a';
exempt_filename[len+4] = 'e';
exempt_filename[len+5] = '\0';
hash = core_info_hash_string(exempt_filename); hash = core_info_hash_string(exempt_filename);
@ -1882,6 +1894,7 @@ static void core_info_parse_config_file(
static void core_info_list_resolve_all_extensions( static void core_info_list_resolve_all_extensions(
core_info_list_t *core_info_list) core_info_list_t *core_info_list)
{ {
size_t _len = 0;
size_t i = 0; size_t i = 0;
size_t all_ext_len = 0; size_t all_ext_len = 0;
char *all_ext = NULL; char *all_ext = NULL;
@ -1895,9 +1908,7 @@ static void core_info_list_resolve_all_extensions(
all_ext_len += STRLEN_CONST("7z|") + STRLEN_CONST("zip|"); all_ext_len += STRLEN_CONST("7z|") + STRLEN_CONST("zip|");
all_ext = (char*)calloc(1, all_ext_len); if (!(all_ext = (char*)calloc(1, all_ext_len)))
if (!all_ext)
return; return;
core_info_list->all_ext = all_ext; core_info_list->all_ext = all_ext;
@ -1907,15 +1918,23 @@ static void core_info_list_resolve_all_extensions(
if (!core_info_list->list[i].supported_extensions) if (!core_info_list->list[i].supported_extensions)
continue; continue;
strlcat(core_info_list->all_ext, _len = strlcat(core_info_list->all_ext,
core_info_list->list[i].supported_extensions, all_ext_len); core_info_list->list[i].supported_extensions, all_ext_len);
strlcat(core_info_list->all_ext, "|", all_ext_len); _len = strlcat(core_info_list->all_ext, "|", all_ext_len);
} }
#ifdef HAVE_7ZIP #ifdef HAVE_7ZIP
strlcat(core_info_list->all_ext, "7z|", all_ext_len); core_info_list->all_ext[_len ] = '7';
core_info_list->all_ext[_len+1] = 'z';
core_info_list->all_ext[_len+2] = '|';
core_info_list->all_ext[_len+3] = '\0';
_len += 3;
#endif #endif
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
strlcat(core_info_list->all_ext, "zip|", all_ext_len); core_info_list->all_ext[_len ] = 'z';
core_info_list->all_ext[_len+1] = 'i';
core_info_list->all_ext[_len+2] = 'p';
core_info_list->all_ext[_len+3] = '|';
core_info_list->all_ext[_len+3] = '\0';
#endif #endif
} }
@ -2993,6 +3012,7 @@ bool core_info_get_core_lock(const char *core_path, bool validate_path)
bool core_info_set_core_standalone_exempt(const char *core_path, bool exempt) bool core_info_set_core_standalone_exempt(const char *core_path, bool exempt)
{ {
#if defined(HAVE_DYNAMIC) #if defined(HAVE_DYNAMIC)
size_t _len;
core_info_t *core_info = NULL; core_info_t *core_info = NULL;
char exempt_file_path[PATH_MAX_LENGTH]; char exempt_file_path[PATH_MAX_LENGTH];
@ -3004,10 +3024,14 @@ bool core_info_set_core_standalone_exempt(const char *core_path, bool exempt)
return false; return false;
/* Get 'standalone exempt' file path */ /* Get 'standalone exempt' file path */
strlcpy(exempt_file_path, core_info->path, _len = strlcpy(exempt_file_path, core_info->path,
sizeof(exempt_file_path));
strlcat(exempt_file_path, FILE_PATH_STANDALONE_EXEMPT_EXTENSION,
sizeof(exempt_file_path)); sizeof(exempt_file_path));
exempt_file_path[_len ] = '.';
exempt_file_path[_len+1] = 'l';
exempt_file_path[_len+2] = 's';
exempt_file_path[_len+3] = 'a';
exempt_file_path[_len+4] = 'e';
exempt_file_path[_len+5] = '\0';
/* Create or delete 'standalone exempt' file, as required */ /* Create or delete 'standalone exempt' file, as required */
if (!core_info_update_core_aux_file(exempt_file_path, exempt)) if (!core_info_update_core_aux_file(exempt_file_path, exempt))
@ -3033,6 +3057,7 @@ bool core_info_set_core_standalone_exempt(const char *core_path, bool exempt)
bool core_info_get_core_standalone_exempt(const char *core_path) bool core_info_get_core_standalone_exempt(const char *core_path)
{ {
#if defined(HAVE_DYNAMIC) #if defined(HAVE_DYNAMIC)
size_t _len;
core_info_t *core_info = NULL; core_info_t *core_info = NULL;
bool is_exempt = false; bool is_exempt = false;
char exempt_file_path[PATH_MAX_LENGTH]; char exempt_file_path[PATH_MAX_LENGTH];
@ -3045,10 +3070,15 @@ bool core_info_get_core_standalone_exempt(const char *core_path)
return false; return false;
/* Get 'standalone exempt' file path */ /* Get 'standalone exempt' file path */
strlcpy(exempt_file_path, core_info->path, _len = strlcpy(
sizeof(exempt_file_path)); exempt_file_path, core_info->path,
strlcat(exempt_file_path, FILE_PATH_STANDALONE_EXEMPT_EXTENSION,
sizeof(exempt_file_path)); sizeof(exempt_file_path));
exempt_file_path[_len ] = '.';
exempt_file_path[_len+1] = 'l';
exempt_file_path[_len+2] = 's';
exempt_file_path[_len+3] = 'a';
exempt_file_path[_len+4] = 'e';
exempt_file_path[_len+5] = '\0';
/* Check whether 'standalone exempt' file exists */ /* Check whether 'standalone exempt' file exists */
is_exempt = path_is_valid(exempt_file_path); is_exempt = path_is_valid(exempt_file_path);

View File

@ -710,11 +710,11 @@ static bool x11_display_server_set_window_decorations(void *data, bool on)
const char *x11_display_server_get_output_options(void *data) const char *x11_display_server_get_output_options(void *data)
{ {
#ifdef HAVE_XRANDR #ifdef HAVE_XRANDR
int i;
Display *dpy; Display *dpy;
XRRScreenResources *res; XRRScreenResources *res;
XRROutputInfo *info; XRROutputInfo *info;
Window root; Window root;
int i;
static char s[PATH_MAX_LENGTH]; static char s[PATH_MAX_LENGTH];
if (!(dpy = XOpenDisplay(0))) if (!(dpy = XOpenDisplay(0)))
@ -727,12 +727,16 @@ const char *x11_display_server_get_output_options(void *data)
for (i = 0; i < res->noutput; i++) for (i = 0; i < res->noutput; i++)
{ {
size_t _len;
if (!(info = XRRGetOutputInfo(dpy, res, res->outputs[i]))) if (!(info = XRRGetOutputInfo(dpy, res, res->outputs[i])))
return NULL; return NULL;
strlcat(s, info->name, sizeof(s)); _len = strlcat(s, info->name, sizeof(s));
if ((i+1) < res->noutput) if ((i+1) < res->noutput)
strlcat(s, "|", sizeof(s)); {
s[_len ] = '|';
s[_len+1] = '\0';
}
} }
return s; return s;

View File

@ -1873,12 +1873,24 @@ static int action_bind_sublabel_core_backup_entry(
const char *crc = list->list[i].alt const char *crc = list->list[i].alt
? list->list[i].alt ? list->list[i].alt
: list->list[i].path; : list->list[i].path;
/* Set sublabel prefix */ /* Set sublabel prefix */
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_BACKUP_CRC), len); size_t _len = strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_BACKUP_CRC), len);
/* Add crc string */ /* Add crc string */
strlcat(s, (string_is_empty(crc) ? "00000000" : crc), len); if (string_is_empty(crc))
{
s[_len ] = '0';
s[_len+1] = '0';
s[_len+2] = '0';
s[_len+3] = '0';
s[_len+4] = '0';
s[_len+5] = '0';
s[_len+6] = '0';
s[_len+7] = '0';
s[_len+8] = '\0';
}
else
strlcat(s, crc, len);
return 1; return 1;
} }

View File

@ -1917,6 +1917,7 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list)
if (frontend->get_powerstate) if (frontend->get_powerstate)
{ {
size_t _len;
int seconds = 0, percent = 0; int seconds = 0, percent = 0;
char tmp2[128]; char tmp2[128];
enum frontend_powerstate state = enum frontend_powerstate state =
@ -1969,11 +1970,13 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list)
break; break;
} }
strlcpy(tmp, _len = strlcpy(tmp,
msg_hash_to_str( msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE), MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE),
sizeof(tmp)); sizeof(tmp));
strlcat(tmp, ": ", sizeof(tmp)); tmp[_len ] = ':';
tmp[_len+1] = ' ';
tmp[_len+2] = '\0';
strlcat(tmp, tmp2, sizeof(tmp)); strlcat(tmp, tmp2, sizeof(tmp));
if (menu_entries_append_enum(list, tmp, "", if (menu_entries_append_enum(list, tmp, "",
MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY,
@ -1986,17 +1989,19 @@ static unsigned menu_displaylist_parse_system_info(file_list_t *list)
video_context_driver_get_ident(&ident_info); video_context_driver_get_ident(&ident_info);
tmp_string = ident_info.ident; tmp_string = ident_info.ident;
strlcpy(tmp, {
msg_hash_to_str( size_t _len = strlcpy(tmp,
MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_VIDEO_CONTEXT_DRIVER), msg_hash_to_str(
sizeof(tmp)); MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_VIDEO_CONTEXT_DRIVER),
strlcat(tmp, sizeof(tmp));
": ", tmp[_len ] = ':';
sizeof(tmp)); tmp[_len+1] = ' ';
strlcat(tmp, tmp[_len+2] = '\0';
tmp_string ? tmp_string strlcat(tmp,
: msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), tmp_string ? tmp_string
sizeof(tmp)); : msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE),
sizeof(tmp));
}
if (menu_entries_append_enum(list, tmp, "", if (menu_entries_append_enum(list, tmp, "",
MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY, MENU_ENUM_LABEL_SYSTEM_INFO_ENTRY,
MENU_SETTINGS_CORE_INFO_NONE, 0, 0)) MENU_SETTINGS_CORE_INFO_NONE, 0, 0))
@ -7273,10 +7278,10 @@ unsigned menu_displaylist_build_list(
off_string[1] = '\0'; off_string[1] = '\0';
strlcat(on_string, strlcat(on_string,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON),
sizeof(on_string)); sizeof(on_string));
strlcat(off_string, strlcat(off_string,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF),
sizeof(off_string)); sizeof(off_string));
} }
else else
{ {

View File

@ -9022,8 +9022,9 @@ static bool setting_append_list_input_player_options(
if (!string_is_empty(buffer[user])) if (!string_is_empty(buffer[user]))
{ {
strlcpy(label, buffer[user], sizeof(label)); size_t _len = strlcpy(label, buffer[user], sizeof(label));
strlcat(label, " ", sizeof(label)); label[_len ] = ' ';
label[_len+1] = '\0';
} }
else else
label[0] = '\0'; label[0] = '\0';

View File

@ -144,6 +144,7 @@ static void task_cdrom_dump_handler(retro_task_t *task)
} }
case DUMP_STATE_WRITE_CUE: case DUMP_STATE_WRITE_CUE:
{ {
size_t _len;
char output_file[PATH_MAX_LENGTH]; char output_file[PATH_MAX_LENGTH];
char cue_filename[PATH_MAX_LENGTH]; char cue_filename[PATH_MAX_LENGTH];
/* write cuesheet to a file */ /* write cuesheet to a file */
@ -160,8 +161,13 @@ static void task_cdrom_dump_handler(retro_task_t *task)
filestream_close(state->file); filestream_close(state->file);
strlcpy(cue_filename, state->title, sizeof(cue_filename)); _len = strlcpy(cue_filename,
strlcat(cue_filename, ".cue", sizeof(cue_filename)); state->title, sizeof(cue_filename));
cue_filename[_len ] = '.';
cue_filename[_len+1] = 'c';
cue_filename[_len+2] = 'u';
cue_filename[_len+3] = 'e';
cue_filename[_len+4] = '\0';
fill_pathname_join_special(output_file, fill_pathname_join_special(output_file,
directory_core_assets, cue_filename, sizeof(output_file)); directory_core_assets, cue_filename, sizeof(output_file));