Don't do NULL termination on strings when passing to strlcpy and/or

a file_path function that calls strlcpy under the hood
This commit is contained in:
libretroadmin 2022-07-26 07:01:10 +02:00
parent d5becf92e8
commit 8ac1a36259
7 changed files with 19 additions and 70 deletions

View File

@ -919,14 +919,10 @@ bool audio_driver_dsp_filter_init(const char *device)
#if defined(HAVE_DYLIB) && !defined(HAVE_FILTERS_BUILTIN)
char ext_name[32];
char basedir[256];
basedir[0] = ext_name[0] = '\0';
ext_name[0] = '\0';
fill_pathname_basedir(basedir, device, sizeof(basedir));
if (!frontend_driver_get_core_extension(ext_name, sizeof(ext_name)))
return false;
if (!(plugs = dir_list_new(basedir, ext_name, false, true, false, false)))
return false;
#endif
@ -1358,8 +1354,7 @@ void audio_driver_load_system_sounds(void)
if (!audio_enable_menu && !audio_enable_cheevo_unlock)
goto end;
sounds_path[0] = sounds_fallback_path[0] =
basename_noext[0] ='\0';
sounds_path[0] = basename_noext[0] ='\0';
fill_pathname_join(
sounds_fallback_path,

View File

@ -797,13 +797,8 @@ static void gfx_widgets_layout(
{
char ozone_path[PATH_MAX_LENGTH];
char font_file[PATH_MAX_LENGTH];
ozone_path[0] = '\0';
font_file[0] = '\0';
/* Base path */
fill_pathname_join(ozone_path, dir_assets, "ozone", sizeof(ozone_path));
/* Create regular font */
fill_pathname_join(font_file, ozone_path, "regular.ttf", sizeof(font_file));
gfx_widgets_font_init(p_disp, p_dispwidget,
@ -1899,35 +1894,24 @@ static void gfx_widgets_context_reset(
char monochrome_png_path[PATH_MAX_LENGTH];
char gfx_widgets_path[PATH_MAX_LENGTH];
char theme_path[PATH_MAX_LENGTH];
xmb_path[0] = '\0';
monochrome_png_path[0] = '\0';
gfx_widgets_path[0] = '\0';
theme_path[0] = '\0';
/* Textures paths */
fill_pathname_join(
gfx_widgets_path,
dir_assets,
"menu_widgets",
sizeof(gfx_widgets_path)
);
fill_pathname_join(
xmb_path,
dir_assets,
"xmb",
sizeof(xmb_path)
);
/* Monochrome */
fill_pathname_join(
theme_path,
xmb_path,
"monochrome",
sizeof(theme_path)
);
fill_pathname_join(
monochrome_png_path,
theme_path,

View File

@ -2135,7 +2135,7 @@ void input_config_get_bind_string(
)
*key = '\0';
/*empty?*/
if (*key != '\0')
else if (*key != '\0')
{
char keybuf[64];
@ -2922,9 +2922,6 @@ void input_config_set_device_config_path(unsigned port, const char *path)
{
char parent_dir_name[128];
input_driver_state_t *input_st = &input_driver_st;
parent_dir_name[0] = '\0';
if (fill_pathname_parent_dir_name(parent_dir_name,
path, sizeof(parent_dir_name)))
fill_pathname_join(input_st->input_device_info[port].config_path,
@ -4651,9 +4648,7 @@ static bool runloop_check_movie_init(input_driver_state_t *input_st,
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
state = bsv_movie_init_internal(path, RARCH_MOVIE_RECORD);
if (!state)
if (!(state = bsv_movie_init_internal(path, RARCH_MOVIE_RECORD)))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD),

View File

@ -246,9 +246,6 @@ runtime_log_t *runtime_log_init(
content_name[0] = '\0';
core_name[0] = '\0';
log_file_dir[0] = '\0';
log_file_path[0] = '\0';
tmp_buf[0] = '\0';
if ( string_is_empty(dir_runtime_log) &&
string_is_empty(dir_playlist))
@ -281,17 +278,15 @@ runtime_log_t *runtime_log_init(
if (string_is_empty(core_name))
return NULL;
/* Get runtime log directory */
/* Get runtime log directory
* If 'custom' runtime log path is undefined,
* use default 'playlists/logs' directory... */
if (string_is_empty(dir_runtime_log))
{
/* If 'custom' runtime log path is undefined,
* use default 'playlists/logs' directory... */
fill_pathname_join(
tmp_buf,
dir_playlist,
"logs",
sizeof(tmp_buf));
}
else
strlcpy(tmp_buf, dir_runtime_log, sizeof(tmp_buf));
@ -1362,14 +1357,12 @@ void runtime_update_playlist(
playlist_get_index(playlist, idx, &entry);
/* Attempt to open log file */
runtime_log = runtime_log_init(
if ((runtime_log = runtime_log_init(
entry->path,
entry->core_path,
dir_runtime_log,
dir_playlist,
log_per_core);
if (runtime_log)
log_per_core)))
{
/* Check whether a non-zero runtime has been recorded */
if (runtime_log_has_runtime(runtime_log))

View File

@ -261,9 +261,7 @@ static int task_database_cue_get_serial(const char *name, char* serial)
track_path[0] = '\0';
rv = cue_find_track(name, true, &offset, &size, track_path, sizeof(track_path));
if (rv < 0)
if ((rv = cue_find_track(name, true, &offset, &size, track_path, sizeof(track_path))) < 0)
{
#ifdef DEBUG
RARCH_LOG("%s: %s\n",
@ -287,9 +285,8 @@ static int task_database_gdi_get_serial(const char *name, char* serial)
track_path[0] = '\0';
rv = gdi_find_track(name, true, track_path, sizeof(track_path));
if (rv < 0)
if ((rv = gdi_find_track(name, true,
track_path, sizeof(track_path))) < 0)
{
#ifdef DEBUG
RARCH_LOG("%s: %s\n",
@ -391,10 +388,8 @@ static int task_database_cue_get_crc(const char *name, uint32_t *crc)
track_path[0] = '\0';
rv = cue_find_track(name, false, &offset, &size,
track_path, sizeof(track_path));
if (rv < 0)
if ((rv = cue_find_track(name, false, &offset, &size,
track_path, sizeof(track_path))) < 0)
{
#ifdef DEBUG
RARCH_LOG("%s: %s\n",
@ -424,9 +419,8 @@ static int task_database_gdi_get_crc(const char *name, uint32_t *crc)
track_path[0] = '\0';
rv = gdi_find_track(name, true, track_path, sizeof(track_path));
if (rv < 0)
if ((rv = gdi_find_track(name, true,
track_path, sizeof(track_path))) < 0)
{
#ifdef DEBUG
RARCH_LOG("%s: %s\n", msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK),
@ -749,7 +743,6 @@ static int database_info_list_iterate_found_match(
db_crc[0] = '\0';
db_playlist_path[0] = '\0';
db_playlist_base_str[0] = '\0';
entry_path_str[0] = '\0';
fill_pathname(db_playlist_base_str,
@ -771,9 +764,7 @@ static int database_info_list_iterate_found_match(
RARCH_ERR("Serial string encoding error\n");
}
else
{
snprintf(db_crc, str_len, "%08lX|crc", (unsigned long)db_info_entry->crc32);
}
if (entry_path)
strlcpy(entry_path_str, entry_path, str_len);
@ -1005,9 +996,6 @@ static int task_database_iterate_playlist_lutro(
{
struct playlist_entry entry;
char game_title[PATH_MAX_LENGTH];
game_title[0] = '\0';
fill_pathname(game_title,
path_basename(path), "", sizeof(game_title));
path_remove_extension(game_title);

View File

@ -499,8 +499,7 @@ int detect_scd_game(intfstream_t *fd, char *game_id, const char *filename)
{
if (!strcmp(region_id, "U") || !strcmp(region_id, "J"))
{
index = string_index_last_occurance(pre_game_id, hyphen);
if (index == -1)
if ((index = string_index_last_occurance(pre_game_id, hyphen)) == -1)
return false;
strncpy(game_id, pre_game_id, index);
game_id[index] = '\0';
@ -509,8 +508,7 @@ int detect_scd_game(intfstream_t *fd, char *game_id, const char *filename)
}
else
{
index = string_index_last_occurance(pre_game_id, hyphen);
if (index == -1)
if ((index = string_index_last_occurance(pre_game_id, hyphen)) == -1)
return false;
strncpy(lgame_id, pre_game_id, index);
lgame_id[index] = '\0';
@ -522,8 +520,7 @@ int detect_scd_game(intfstream_t *fd, char *game_id, const char *filename)
}
else if (!strcmp(check_prefix_g_hyp, "G-"))
{
index = string_index_last_occurance(pre_game_id, hyphen);
if (index == -1)
if ((index = string_index_last_occurance(pre_game_id, hyphen)) == -1)
return false;
strncpy(game_id, pre_game_id, index);
game_id[index] = '\0';

View File

@ -87,9 +87,6 @@ static void task_overlay_load_desc_image(
{
struct texture_image image_tex;
char path[PATH_MAX_LENGTH];
path[0] = '\0';
fill_pathname_resolve_relative(path, loader->overlay_path,
image_path, sizeof(path));