1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

Try to use strlcpy/strlcat instead of snprintf when possible

This commit is contained in:
libretroadmin 2023-01-22 18:57:17 +01:00
parent 5a16f91365
commit b23eaba217
2 changed files with 44 additions and 37 deletions

View File

@ -507,10 +507,10 @@ static void d3d9_cg_renderchain_bind_prev(d3d9_renderchain_t *chain,
{
unsigned i;
float texture_size[2];
char attr_texture[64] = {0};
char attr_input_size[64] = {0};
char attr_tex_size[64] = {0};
char attr_coord[64] = {0};
char attr_texture[64];
char attr_input_size[64];
char attr_tex_size[64];
char attr_coord[64];
static const char *prev_names[] = {
"PREV",
"PREV1",
@ -526,15 +526,21 @@ static void d3d9_cg_renderchain_bind_prev(d3d9_renderchain_t *chain,
for (i = 0; i < TEXTURES - 1; i++)
{
char prev_name[32];
CGparameter param;
float video_size[2];
CGprogram fprg = (CGprogram)pass->fprg;
CGprogram vprg = (CGprogram)pass->vprg;
snprintf(attr_texture, sizeof(attr_texture), "%s.texture", prev_names[i]);
snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", prev_names[i]);
snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", prev_names[i]);
snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", prev_names[i]);
strlcpy(prev_name, prev_names[i], sizeof(prev_name));
strlcpy(attr_texture, prev_name, sizeof(attr_texture));
strlcat(attr_texture, ".texture", sizeof(attr_texture));
strlcpy(attr_input_size, prev_name, sizeof(attr_input_size));
strlcat(attr_input_size, ".video_size", sizeof(attr_input_size));
strlcpy(attr_tex_size, prev_name, sizeof(attr_tex_size));
strlcat(attr_tex_size, ".texture_size", sizeof(attr_tex_size));
strlcpy(attr_coord, prev_name, sizeof(attr_coord));
strlcat(attr_coord, ".tex_coord", sizeof(attr_coord));
video_size[0] = chain->prev.last_width[
(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
@ -606,18 +612,22 @@ static void d3d9_cg_renderchain_bind_pass(
CGparameter param;
float video_size[2];
float texture_size[2];
char pass_base[64] = {0};
char attr_texture[64] = {0};
char attr_input_size[64] = {0};
char attr_tex_size[64] = {0};
char attr_coord[64] = {0};
char pass_base[64];
char attr_texture[64];
char attr_input_size[64];
char attr_tex_size[64];
char attr_coord[64];
struct shader_pass *curr_pass = (struct shader_pass*)&chain->passes->data[i];
snprintf(pass_base, sizeof(pass_base), "PASS%u", i);
snprintf(attr_texture, sizeof(attr_texture), "%s.texture", pass_base);
snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", pass_base);
snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", pass_base);
snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", pass_base);
snprintf(pass_base, sizeof(pass_base), "PASS%u", i);
strlcpy(attr_texture, pass_base, sizeof(attr_texture));
strlcat(attr_texture, ".texture", sizeof(attr_texture));
strlcpy(attr_input_size, pass_base, sizeof(attr_input_size));
strlcat(attr_input_size, ".video_size", sizeof(attr_input_size));
strlcpy(attr_tex_size, pass_base, sizeof(attr_tex_size));
strlcat(attr_tex_size, ".texture_size", sizeof(attr_tex_size));
strlcpy(attr_coord, pass_base, sizeof(attr_coord));
strlcat(attr_coord, ".tex_coord", sizeof(attr_coord));
video_size[0] = curr_pass->last_width;
video_size[1] = curr_pass->last_height;

View File

@ -181,7 +181,7 @@ static bool connmanctl_tether_status(connman_t *connman)
}
static void connmanctl_tether_toggle(
connman_t *connman, bool switch_on, char* apname, char* passkey)
connman_t *connman, bool switch_on, char* ap_name, char *pass_key)
{
/* Starts / stops the tethering service on wi-fi device */
char output[256] = {0};
@ -193,7 +193,7 @@ static void connmanctl_tether_toggle(
snprintf(connman->command, sizeof(connman->command), "\
connmanctl tether wifi %s %s %s",
switch_on ? "on" : "off", apname, passkey);
switch_on ? "on" : "off", ap_name, pass_key);
command_file = popen(connman->command, "r");
@ -386,9 +386,8 @@ static bool connmanctl_connect_ssid(
connmanctl_tether_toggle(connman, false, "", "");
}
snprintf(connman->command, sizeof(connman->command),
"connmanctl connect %s",
netinfo->netid);
strlcpy(connman->command, "connmanctl connect ", sizeof(connman->command));
strlcat(connman->command, netinfo->netid, sizeof(connman->command));
pclose(popen(connman->command, "r"));
@ -565,9 +564,9 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
* tethering service is already running / not running
* before performing the desired action
*/
char ap_name[64];
char pass_key[256];
FILE *command_file = NULL;
char apname[64] = {0};
char passkey[256] = {0};
char ln[512] = {0};
char ssid[64] = {0};
char service[256] = {0};
@ -612,10 +611,10 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
RARCH_LOG("[CONNMANCTL] Tether start stop: creating new config \"%s\"\n",
configfile);
snprintf(apname, sizeof(apname), "LakkaAccessPoint");
snprintf(passkey, sizeof(passkey), "RetroArch");
strlcpy(ap_name, "LakkaAccessPoint", sizeof(ap_name));
strlcpy(pass_key, "RetroArch", sizeof(pass_key));
fprintf(command_file, "APNAME=%s\nPASSWORD=%s", apname, passkey);
fprintf(command_file, "APNAME=%s\nPASSWORD=%s", ap_name, pass_key);
fclose(command_file);
@ -653,21 +652,19 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
if (i == 1)
{
strlcpy(apname, ln, sizeof(apname));
strlcpy(ap_name, ln, sizeof(ap_name));
RARCH_LOG("[CONNMANCTL] Tether start stop: found APNAME: \"%s\"\n",
apname);
ap_name);
continue;
}
if (i == 2)
{
strlcpy(passkey, ln, sizeof(passkey));
strlcpy(pass_key, ln, sizeof(pass_key));
RARCH_LOG("[CONNMANCTL] Tether start stop: found PASSWORD: \"%s\"\n",
passkey);
pass_key);
continue;
}
@ -682,7 +679,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
pclose(command_file);
}
if (!apname || !passkey)
if (!ap_name || !pass_key)
{
RARCH_ERR("[CONNMANCTL] Tether start stop: APNAME or PASSWORD missing\n");
@ -753,7 +750,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
snprintf(connman->command, sizeof(connman->command),
msg_hash_to_str(MSG_LOCALAP_STARTING),
apname, passkey);
ap_name, pass_key);
runloop_msg_queue_push(connman->command,
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
@ -782,7 +779,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
RARCH_LOG("[CONNMANCTL] Tether start stop: calling tether_toggle()\n");
/* call the tether toggle function */
connmanctl_tether_toggle(connman, start, apname, passkey);
connmanctl_tether_toggle(connman, start, ap_name, pass_key);
RARCH_LOG("[CONNMANCTL] Tether start stop: end\n");
}