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; unsigned i;
float texture_size[2]; float texture_size[2];
char attr_texture[64] = {0}; char attr_texture[64];
char attr_input_size[64] = {0}; char attr_input_size[64];
char attr_tex_size[64] = {0}; char attr_tex_size[64];
char attr_coord[64] = {0}; char attr_coord[64];
static const char *prev_names[] = { static const char *prev_names[] = {
"PREV", "PREV",
"PREV1", "PREV1",
@ -526,15 +526,21 @@ static void d3d9_cg_renderchain_bind_prev(d3d9_renderchain_t *chain,
for (i = 0; i < TEXTURES - 1; i++) for (i = 0; i < TEXTURES - 1; i++)
{ {
char prev_name[32];
CGparameter param; CGparameter param;
float video_size[2]; float video_size[2];
CGprogram fprg = (CGprogram)pass->fprg; CGprogram fprg = (CGprogram)pass->fprg;
CGprogram vprg = (CGprogram)pass->vprg; CGprogram vprg = (CGprogram)pass->vprg;
snprintf(attr_texture, sizeof(attr_texture), "%s.texture", prev_names[i]); strlcpy(prev_name, prev_names[i], sizeof(prev_name));
snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", prev_names[i]); strlcpy(attr_texture, prev_name, sizeof(attr_texture));
snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", prev_names[i]); strlcat(attr_texture, ".texture", sizeof(attr_texture));
snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", prev_names[i]); 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[ video_size[0] = chain->prev.last_width[
(chain->prev.ptr - (i + 1)) & TEXTURESMASK]; (chain->prev.ptr - (i + 1)) & TEXTURESMASK];
@ -606,18 +612,22 @@ static void d3d9_cg_renderchain_bind_pass(
CGparameter param; CGparameter param;
float video_size[2]; float video_size[2];
float texture_size[2]; float texture_size[2];
char pass_base[64] = {0}; char pass_base[64];
char attr_texture[64] = {0}; char attr_texture[64];
char attr_input_size[64] = {0}; char attr_input_size[64];
char attr_tex_size[64] = {0}; char attr_tex_size[64];
char attr_coord[64] = {0}; char attr_coord[64];
struct shader_pass *curr_pass = (struct shader_pass*)&chain->passes->data[i]; struct shader_pass *curr_pass = (struct shader_pass*)&chain->passes->data[i];
snprintf(pass_base, sizeof(pass_base), "PASS%u", i); snprintf(pass_base, sizeof(pass_base), "PASS%u", i);
snprintf(attr_texture, sizeof(attr_texture), "%s.texture", pass_base); strlcpy(attr_texture, pass_base, sizeof(attr_texture));
snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", pass_base); strlcat(attr_texture, ".texture", sizeof(attr_texture));
snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", pass_base); strlcpy(attr_input_size, pass_base, sizeof(attr_input_size));
snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", pass_base); 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[0] = curr_pass->last_width;
video_size[1] = curr_pass->last_height; 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( 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 */ /* Starts / stops the tethering service on wi-fi device */
char output[256] = {0}; char output[256] = {0};
@ -193,7 +193,7 @@ static void connmanctl_tether_toggle(
snprintf(connman->command, sizeof(connman->command), "\ snprintf(connman->command, sizeof(connman->command), "\
connmanctl tether wifi %s %s %s", 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"); command_file = popen(connman->command, "r");
@ -386,9 +386,8 @@ static bool connmanctl_connect_ssid(
connmanctl_tether_toggle(connman, false, "", ""); connmanctl_tether_toggle(connman, false, "", "");
} }
snprintf(connman->command, sizeof(connman->command), strlcpy(connman->command, "connmanctl connect ", sizeof(connman->command));
"connmanctl connect %s", strlcat(connman->command, netinfo->netid, sizeof(connman->command));
netinfo->netid);
pclose(popen(connman->command, "r")); 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 * tethering service is already running / not running
* before performing the desired action * before performing the desired action
*/ */
char ap_name[64];
char pass_key[256];
FILE *command_file = NULL; FILE *command_file = NULL;
char apname[64] = {0};
char passkey[256] = {0};
char ln[512] = {0}; char ln[512] = {0};
char ssid[64] = {0}; char ssid[64] = {0};
char service[256] = {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", RARCH_LOG("[CONNMANCTL] Tether start stop: creating new config \"%s\"\n",
configfile); configfile);
snprintf(apname, sizeof(apname), "LakkaAccessPoint"); strlcpy(ap_name, "LakkaAccessPoint", sizeof(ap_name));
snprintf(passkey, sizeof(passkey), "RetroArch"); 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); fclose(command_file);
@ -653,21 +652,19 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
if (i == 1) 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", RARCH_LOG("[CONNMANCTL] Tether start stop: found APNAME: \"%s\"\n",
apname); ap_name);
continue; continue;
} }
if (i == 2) 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", RARCH_LOG("[CONNMANCTL] Tether start stop: found PASSWORD: \"%s\"\n",
passkey); pass_key);
continue; continue;
} }
@ -682,7 +679,7 @@ static void connmanctl_tether_start_stop(void *data, bool start, char* configfil
pclose(command_file); pclose(command_file);
} }
if (!apname || !passkey) if (!ap_name || !pass_key)
{ {
RARCH_ERR("[CONNMANCTL] Tether start stop: APNAME or PASSWORD missing\n"); 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), snprintf(connman->command, sizeof(connman->command),
msg_hash_to_str(MSG_LOCALAP_STARTING), msg_hash_to_str(MSG_LOCALAP_STARTING),
apname, passkey); ap_name, pass_key);
runloop_msg_queue_push(connman->command, runloop_msg_queue_push(connman->command,
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, 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"); RARCH_LOG("[CONNMANCTL] Tether start stop: calling tether_toggle()\n");
/* call the tether toggle function */ /* 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"); RARCH_LOG("[CONNMANCTL] Tether start stop: end\n");
} }