Skip to content

Commit 1b24996

Browse files
committed
Remove strtok_r usage in some functions
1 parent 4a7dfec commit 1b24996

2 files changed

Lines changed: 94 additions & 81 deletions

File tree

gfx/video_crt_switch.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,25 @@ static bool crt_sr2_init(videocrt_switch_t *p_switch,
247247
}
248248
}
249249

250-
if (p_switch->rtn >= 0 && !p_switch->kms_ctx)
250+
if (p_switch->rtn >= 0)
251251
{
252-
p_switch->sr2_active = true;
253-
return true;
254-
}
255-
else if (p_switch->rtn >= 0 && p_switch->kms_ctx)
256-
{
257-
p_switch->sr2_active = true;
258-
RARCH_LOG("[CRT] KMS context detected, keeping SR alive.\n");
259-
return true;
260-
}
261-
else if (p_switch->rtn >= 0 && p_switch->khr_ctx)
262-
{
263-
p_switch->sr2_active = true;
264-
RARCH_LOG("[CRT] Vulkan context detected, keeping SR alive.\n");
265-
return true;
252+
if (!p_switch->kms_ctx)
253+
{
254+
p_switch->sr2_active = true;
255+
return true;
256+
}
257+
else if (p_switch->kms_ctx)
258+
{
259+
p_switch->sr2_active = true;
260+
RARCH_LOG("[CRT] KMS context detected, keeping SR alive.\n");
261+
return true;
262+
}
263+
else if (p_switch->khr_ctx)
264+
{
265+
p_switch->sr2_active = true;
266+
RARCH_LOG("[CRT] Vulkan context detected, keeping SR alive.\n");
267+
return true;
268+
}
266269
}
267270

268271
RARCH_ERR("[CRT] Error at init, CRT modeswitching disabled.\n");
@@ -516,25 +519,25 @@ void crt_switch_res_core(
516519
}
517520
}
518521

519-
static char* get_game_name(char* full_path)
522+
static char *get_game_name(char *full_path)
520523
{
521-
int i;
522-
int n = strlen(full_path);
523-
char* rom_filename = full_path + n;
524-
char delimiter = (char) path_get(RARCH_PATH_BASENAME)[0];
524+
unsigned i;
525+
size_t _len = strlen(full_path);
526+
char* rom_filename = full_path + _len;
527+
char delim = (char) path_get(RARCH_PATH_BASENAME)[0];
525528

526-
for (i = 0; i < n; i++)
529+
for (i = 0; i < _len; i++)
527530
{
528531
if (full_path[i] == '/' || full_path[i] =='\\')
529532
{
530-
delimiter = full_path[i];
533+
delim = full_path[i];
531534
break;
532535
}
533536
}
534537

535-
while (0 < n && (full_path[--n] != delimiter ));
536-
if (full_path[n] == delimiter )
537-
rom_filename = full_path + n + 1;
538+
while (0 < _len && (full_path[--_len] != delim));
539+
if (full_path[_len] == delim)
540+
rom_filename = full_path + _len + 1;
538541
return rom_filename;
539542
}
540543

gfx/video_shader_parse.c

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -774,81 +774,91 @@ static bool video_shader_parse_pass(config_file_t *conf,
774774
static bool video_shader_parse_textures(config_file_t *conf,
775775
struct video_shader *shader)
776776
{
777-
char *textures = (char*)malloc(1024 + PATH_MAX_LENGTH);
778-
779-
if (!textures)
780-
return false;
777+
char textures[1024];
778+
const char *id = NULL;
779+
const char *next = NULL;
781780

782781
textures[0] = '\0';
783782

784-
if (config_get_array(conf, "textures", textures, 1024))
783+
if (!config_get_array(conf, "textures", textures, sizeof(textures)))
784+
return true;
785+
786+
for (id = textures; id && *id && shader->luts < GFX_MAX_TEXTURES; id = next)
785787
{
788+
size_t id_len;
789+
char id_buf[64];
790+
char idx[64];
786791
char texture_path[PATH_MAX_LENGTH];
787-
const char *id = NULL;
788-
char *save = NULL;
792+
bool mipmap = false;
793+
bool smooth = false;
794+
struct config_entry_list *entry = NULL;
789795

790-
texture_path[0] = '\0';
791-
792-
for (id = strtok_r(textures, ";", &save);
793-
id && shader->luts < GFX_MAX_TEXTURES;
794-
shader->luts++, id = strtok_r(NULL, ";", &save))
796+
/* Find the next semicolon delimiter */
797+
next = strchr(id, ';');
798+
if (next)
795799
{
796-
size_t _len;
797-
char idx[64];
798-
bool mipmap = false;
799-
bool smooth = false;
800-
struct config_entry_list *entry = NULL;
800+
id_len = (size_t)(next - id);
801+
next++; /* skip past ';' */
802+
}
803+
else
804+
id_len = strlen(id);
801805

802-
idx[0] = '\0';
806+
/* Skip empty tokens */
807+
if (id_len == 0)
808+
continue;
803809

804-
if ( !(entry = config_get_entry(conf, id))
805-
|| string_is_empty(entry->value))
806-
{
807-
RARCH_ERR("[Shaders] Cannot find path to texture \"%s\".\n",
808-
id);
809-
free(textures);
810-
return false;
811-
}
810+
/* Copy token into a null-terminated buffer */
811+
if (id_len >= sizeof(id_buf))
812+
id_len = sizeof(id_buf) - 1;
813+
memcpy(id_buf, id, id_len);
814+
id_buf[id_len] = '\0';
815+
816+
texture_path[0] = '\0';
812817

813-
config_get_path(conf, id, texture_path, sizeof(texture_path));
818+
if ( !(entry = config_get_entry(conf, id_buf))
819+
|| string_is_empty(entry->value))
820+
{
821+
RARCH_ERR("[Shaders] Cannot find path to texture \"%s\".\n",
822+
id_buf);
823+
return false;
824+
}
814825

815-
/* Get the absolute path and replace wildcards in the path */
816-
fill_pathname_expanded_and_absolute(shader->lut[shader->luts].path,
817-
PATH_MAX_LENGTH, conf->path, texture_path);
818-
/* TODO/FIXME - dehardcode PATH_MAX_LENGTH */
819-
video_shader_replace_wildcards(shader->lut[shader->luts].path,
820-
PATH_MAX_LENGTH, conf->path);
826+
config_get_path(conf, id_buf, texture_path, sizeof(texture_path));
821827

822-
strlcpy(shader->lut[shader->luts].id, id,
823-
sizeof(shader->lut[shader->luts].id));
828+
fill_pathname_expanded_and_absolute(shader->lut[shader->luts].path,
829+
PATH_MAX_LENGTH, conf->path, texture_path);
830+
video_shader_replace_wildcards(shader->lut[shader->luts].path,
831+
PATH_MAX_LENGTH, conf->path);
824832

825-
_len = strlcpy(idx, id, sizeof(idx));
833+
strlcpy(shader->lut[shader->luts].id, id_buf,
834+
sizeof(shader->lut[shader->luts].id));
826835

827-
strlcpy(idx + _len, "_linear", sizeof(idx) - _len);
828-
if (config_get_bool(conf, idx, &smooth))
829-
shader->lut[shader->luts].filter = smooth
830-
? RARCH_FILTER_LINEAR
831-
: RARCH_FILTER_NEAREST;
832-
else
833-
shader->lut[shader->luts].filter = RARCH_FILTER_UNSPEC;
836+
strlcpy(idx, id_buf, sizeof(idx));
834837

835-
strlcpy(idx + _len, "_mipmap", sizeof(idx) - _len);
836-
if (config_get_bool(conf, idx, &mipmap))
837-
shader->lut[shader->luts].mipmap = mipmap;
838-
else
839-
shader->lut[shader->luts].mipmap = false;
838+
strlcpy(idx + id_len, "_linear", sizeof(idx) - id_len);
839+
if (config_get_bool(conf, idx, &smooth))
840+
shader->lut[shader->luts].filter = smooth
841+
? RARCH_FILTER_LINEAR
842+
: RARCH_FILTER_NEAREST;
843+
else
844+
shader->lut[shader->luts].filter = RARCH_FILTER_UNSPEC;
840845

841-
strlcpy(idx + _len, "_wrap_mode", sizeof(idx) - _len);
842-
entry = NULL;
843-
if ((entry = config_get_entry(conf, idx))
844-
&& !string_is_empty(entry->value))
845-
shader->lut[shader->luts].wrap = video_shader_wrap_str_to_mode(entry->value);
846-
entry = NULL;
846+
strlcpy(idx + id_len, "_mipmap", sizeof(idx) - id_len);
847+
if (config_get_bool(conf, idx, &mipmap))
848+
shader->lut[shader->luts].mipmap = mipmap;
849+
else
850+
shader->lut[shader->luts].mipmap = false;
847851

848-
}
852+
strlcpy(idx + id_len, "_wrap_mode", sizeof(idx) - id_len);
853+
entry = NULL;
854+
if ( (entry = config_get_entry(conf, idx))
855+
&& !string_is_empty(entry->value))
856+
shader->lut[shader->luts].wrap = video_shader_wrap_str_to_mode(entry->value);
857+
entry = NULL;
858+
859+
shader->luts++;
849860
}
850861

851-
free(textures);
852862
return true;
853863
}
854864

0 commit comments

Comments
 (0)