1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-05 17:58:41 +00:00

Don't use strlcat for basic concatenation of characters

except when absolutely necessary
This commit is contained in:
twinaphex 2019-09-17 02:00:04 +02:00
parent c2cad1f122
commit d01ae6929d
5 changed files with 66 additions and 38 deletions

View File

@ -301,30 +301,32 @@ struct http_connection_t *net_http_connection_new(const char *url,
uri = strchr(conn->scan, (char) '/');
if (strchr(conn->scan, (char) ':') != NULL)
if (strchr(conn->scan, (char) ':'))
{
url_dup = strdup(conn->scan);
domain_port = strtok(url_dup, ":");
domain_port2 = strtok(NULL, ":");
url_port = domain_port2;
if (strchr(domain_port2, (char) '/') != NULL)
url_port = strtok(domain_port2, "/");
size_t copied;
url_dup = strdup(conn->scan);
domain_port = strtok(url_dup, ":");
domain_port2 = strtok(NULL, ":");
url_port = domain_port2;
if (strchr(domain_port2, (char) '/'))
url_port = strtok(domain_port2, "/");
if (url_port != NULL)
if (url_port)
conn->port = atoi(url_port);
strlcpy(new_domain, domain_port, sizeof(new_domain));
copied = strlcpy(new_domain, domain_port, sizeof(new_domain));
free(url_dup);
if (uri != NULL)
if (uri)
{
if (strchr(uri, (char) '/') == NULL)
if (!strchr(uri, (char) '/'))
strlcat(new_domain, uri, sizeof(new_domain));
else
{
strlcat(new_domain, "/", sizeof(new_domain));
strlcat(new_domain, strchr(uri, (char) '/')+sizeof(char), sizeof(new_domain));
new_domain[copied] = '/';
new_domain[copied+1] = '\0';
strlcat(new_domain, strchr(uri, (char)'/') + sizeof(char),
sizeof(new_domain));
}
strlcpy(conn->scan, new_domain, strlen(conn->scan) + 1);
}

View File

@ -368,6 +368,7 @@ static int action_get_title_group_settings(const char *path, const char *label,
{
char elem0[255];
char elem1[255];
size_t copied;
struct string_list *list_label = string_split(label, "|");
elem0[0] = elem1[0] = '\0';
@ -383,11 +384,14 @@ static int action_get_title_group_settings(const char *path, const char *label,
string_list_free(list_label);
}
strlcpy(s, elem0, len);
copied = strlcpy(s, elem0, len);
if (!string_is_empty(elem1))
{
strlcat(s, " - ", len);
s[copied] = ' ';
s[copied+1] = '-';
s[copied+2] = ' ';
s[copied+3] = '\0';
strlcat(s, elem1, len);
}
}

View File

@ -625,7 +625,8 @@ static unsigned menu_displaylist_parse_system_info(menu_displaylist_info_t *info
if (frontend->get_powerstate)
{
int seconds = 0, percent = 0;
size_t copied = 0;
int seconds = 0, percent = 0;
enum frontend_powerstate state =
frontend->get_powerstate(&seconds, &percent);
@ -637,42 +638,55 @@ static unsigned menu_displaylist_parse_system_info(menu_displaylist_info_t *info
switch (state)
{
case FRONTEND_POWERSTATE_NONE:
strlcat(tmp2, " ", sizeof(tmp2));
tmp2[copied] = ' ';
tmp2[copied+1] = '\0';
strlcat(tmp2,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), sizeof(tmp2));
break;
case FRONTEND_POWERSTATE_NO_SOURCE:
strlcat(tmp2, " (", sizeof(tmp2));
strlcat(tmp2,
tmp2[copied] = ' ';
tmp2[copied+1] = '(';
tmp2[copied+2] = '\0';
copied = strlcat(tmp2,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_NO_SOURCE),
sizeof(tmp2));
strlcat(tmp2, ")", sizeof(tmp2));
tmp2[copied] = ')';
tmp2[copied+1] = '\0';
break;
case FRONTEND_POWERSTATE_CHARGING:
strlcat(tmp2, " (", sizeof(tmp2));
strlcat(tmp2,
tmp2[copied] = ' ';
tmp2[copied+1] = '(';
tmp2[copied+2] = '\0';
copied = strlcat(tmp2,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_CHARGING),
sizeof(tmp2));
strlcat(tmp2, ")", sizeof(tmp2));
tmp2[copied] = ')';
tmp2[copied+1] = '\0';
break;
case FRONTEND_POWERSTATE_CHARGED:
strlcat(tmp2, " (", sizeof(tmp2));
strlcat(tmp2,
tmp2[copied] = ' ';
tmp2[copied+1] = '(';
tmp2[copied+2] = '\0';
copied = strlcat(tmp2,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_CHARGED),
sizeof(tmp2));
strlcat(tmp2, ")", sizeof(tmp2));
tmp2[copied] = ')';
tmp2[copied+1] = '\0';
break;
case FRONTEND_POWERSTATE_ON_POWER_SOURCE:
strlcat(tmp2, " (", sizeof(tmp2));
strlcat(tmp2,
tmp2[copied] = ' ';
tmp2[copied+1] = '(';
tmp2[copied+2] = '\0';
copied = strlcat(tmp2,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SYSTEM_INFO_POWER_SOURCE_DISCHARGING),
sizeof(tmp2));
strlcat(tmp2, ")", sizeof(tmp2));
tmp2[copied] = ')';
tmp2[copied+1] = '\0';
break;
}

View File

@ -3904,9 +3904,13 @@ void menu_subsystem_populate(const struct retro_subsystem_info* subsystem, menu_
for (j = 0; j < content_get_subsystem_rom_id(); j++)
{
strlcat(rom_buff, path_basename(content_get_subsystem_rom(j)), sizeof(rom_buff));
size_t copied = strlcat(rom_buff,
path_basename(content_get_subsystem_rom(j)), sizeof(rom_buff));
if (j != content_get_subsystem_rom_id() - 1)
strlcat(rom_buff, "|", sizeof(rom_buff));
{
rom_buff[copied] = '|';
rom_buff[copied+1] = '\0';
}
}
if (!string_is_empty(rom_buff))

View File

@ -81,6 +81,7 @@ static bool get_thumbnail_paths(
char *path, size_t path_size,
char *url, size_t url_size)
{
size_t copied;
const char *system = NULL;
const char *db_name = NULL;
const char *img_name = NULL;
@ -143,12 +144,15 @@ static bool get_thumbnail_paths(
return false;
/* Generate remote path */
strlcpy(raw_url, file_path_str(FILE_PATH_CORE_THUMBNAILS_URL), sizeof(raw_url));
strlcat(raw_url, "/", sizeof(raw_url));
strlcat(raw_url, system_name, sizeof(raw_url));
strlcat(raw_url, "/", sizeof(raw_url));
strlcat(raw_url, sub_dir, sizeof(raw_url));
strlcat(raw_url, "/", sizeof(raw_url));
copied = strlcpy(raw_url, file_path_str(FILE_PATH_CORE_THUMBNAILS_URL), sizeof(raw_url));
raw_url[copied] = '/';
raw_url[copied+1] = '\0';
copied = strlcat(raw_url, system_name, sizeof(raw_url));
raw_url[copied] = '/';
raw_url[copied+1] = '\0';
copied = strlcat(raw_url, sub_dir, sizeof(raw_url));
raw_url[copied] = '/';
raw_url[copied+1] = '\0';
strlcat(raw_url, img_name, sizeof(raw_url));
if (string_is_empty(raw_url))