If we already know the length of the string, use strldup instead.

Avoids the internal strlen call inside strdup, and strdup is a deprecated
function starting from MSVC2005 anyways.

NOTE: Do NOT pass STRLEN_CONST as n parameter to strldup, it needs to
be at least +1 character higher than the strlen return value of the same
string
pull/14353/head
LibretroAdmin 2022-08-25 16:31:54 +02:00
parent 5bb3fbab93
commit 575e331fd1
9 changed files with 43 additions and 40 deletions

View File

@ -576,7 +576,7 @@ static bool core_updater_list_set_core_info(
if (!string_is_empty(core_info->description)) if (!string_is_empty(core_info->description))
entry->description = strdup(core_info->description); entry->description = strdup(core_info->description);
else else
entry->description = strdup(""); entry->description = strldup("", sizeof(""));
/* licenses_list */ /* licenses_list */
if (!string_is_empty(core_info->licenses)) if (!string_is_empty(core_info->licenses))
@ -592,7 +592,7 @@ static bool core_updater_list_set_core_info(
* cores must have a valid/complete core info file) */ * cores must have a valid/complete core info file) */
entry->display_name = strdup(filename_str); entry->display_name = strdup(filename_str);
entry->is_experimental = true; entry->is_experimental = true;
entry->description = strdup(""); entry->description = strldup("", sizeof(""));
} }
return true; return true;

View File

@ -211,7 +211,7 @@ static char *config_file_extract_value(char *line)
line++; line++;
/* Note: From this point on, an empty value /* Note: From this point on, an empty value
* string is valid - and in this case, strdup("") * string is valid - and in this case, strldup("", sizeof(""))
* will be returned * will be returned
* > If we instead return NULL, the the entry * > If we instead return NULL, the the entry
* is ignored completely - which means we cannot * is ignored completely - which means we cannot
@ -254,7 +254,7 @@ static char *config_file_extract_value(char *line)
return strdup(value); return strdup(value);
} }
return strdup(""); return strldup("", sizeof(""));
} }
/* Move semantics? */ /* Move semantics? */

View File

@ -4350,7 +4350,7 @@ static void ozone_init_horizontal_list(ozone_handle_t *ozone,
info.path = strdup(dir_playlist); info.path = strdup(dir_playlist);
info.label = strdup( info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));
info.exts = strdup("lpl"); info.exts = strldup("lpl", sizeof("lpl"));
info.type_default = FILE_TYPE_PLAIN; info.type_default = FILE_TYPE_PLAIN;
info.enum_idx = MENU_ENUM_LABEL_PLAYLISTS_TAB; info.enum_idx = MENU_ENUM_LABEL_PLAYLISTS_TAB;
@ -10847,7 +10847,7 @@ static bool ozone_menu_init_list(void *data)
info.label = strdup( info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU)); msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU));
info.exts = strdup("lpl"); info.exts = strldup("lpl", sizeof("lpl"));
info.type_default = FILE_TYPE_PLAIN; info.type_default = FILE_TYPE_PLAIN;
info.enum_idx = MENU_ENUM_LABEL_MAIN_MENU; info.enum_idx = MENU_ENUM_LABEL_MAIN_MENU;

View File

@ -2210,7 +2210,7 @@ static void xmb_init_horizontal_list(xmb_handle_t *xmb)
info.path = strdup(dir_playlist); info.path = strdup(dir_playlist);
info.label = strdup( info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));
info.exts = strdup("lpl"); info.exts = strldup("lpl", sizeof("lpl"));
info.type_default = FILE_TYPE_PLAIN; info.type_default = FILE_TYPE_PLAIN;
info.enum_idx = MENU_ENUM_LABEL_PLAYLISTS_TAB; info.enum_idx = MENU_ENUM_LABEL_PLAYLISTS_TAB;
@ -7622,7 +7622,7 @@ static bool xmb_menu_init_list(void *data)
info.label = strdup( info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU)); msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU));
info.exts = strdup("lpl"); info.exts = strldup("lpl", sizeof("lpl"));
info.type_default = FILE_TYPE_PLAIN; info.type_default = FILE_TYPE_PLAIN;
info.enum_idx = MENU_ENUM_LABEL_MAIN_MENU; info.enum_idx = MENU_ENUM_LABEL_MAIN_MENU;

View File

@ -13724,7 +13724,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
if (info->path) if (info->path)
free(info->path); free(info->path);
info->type_default = FILE_TYPE_RDB; info->type_default = FILE_TYPE_RDB;
info->exts = strdup(".rdb"); info->exts = strldup(".rdb", sizeof(".rdb"));
info->enum_idx = MENU_ENUM_LABEL_PLAYLISTS_TAB; info->enum_idx = MENU_ENUM_LABEL_PLAYLISTS_TAB;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
@ -13740,7 +13740,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
if (info->path) if (info->path)
free(info->path); free(info->path);
info->type_default = FILE_TYPE_CURSOR; info->type_default = FILE_TYPE_CURSOR;
info->exts = strdup("dbc"); info->exts = strldup("dbc", sizeof("dbc"));
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
info->path = strdup(settings->paths.directory_cursor); info->path = strdup(settings->paths.directory_cursor);
@ -13923,51 +13923,51 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
case DISPLAYLIST_VIDEO_FILTERS: case DISPLAYLIST_VIDEO_FILTERS:
info->type_default = FILE_TYPE_VIDEOFILTER; info->type_default = FILE_TYPE_VIDEOFILTER;
info->exts = strdup("filt"); info->exts = strldup("filt", sizeof("filt"));
break; break;
case DISPLAYLIST_CONFIG_FILES: case DISPLAYLIST_CONFIG_FILES:
info->type_default = FILE_TYPE_CONFIG; info->type_default = FILE_TYPE_CONFIG;
info->exts = strdup("cfg"); info->exts = strldup("cfg", sizeof("cfg"));
break; break;
case DISPLAYLIST_REMAP_FILES: case DISPLAYLIST_REMAP_FILES:
info->type_default = FILE_TYPE_REMAP; info->type_default = FILE_TYPE_REMAP;
info->exts = strdup("rmp"); info->exts = strldup("rmp", sizeof("rmp"));
break; break;
case DISPLAYLIST_RGUI_THEME_PRESETS: case DISPLAYLIST_RGUI_THEME_PRESETS:
info->type_default = FILE_TYPE_RGUI_THEME_PRESET; info->type_default = FILE_TYPE_RGUI_THEME_PRESET;
info->exts = strdup("cfg"); info->exts = strldup("cfg", sizeof("cfg"));
break; break;
case DISPLAYLIST_STREAM_CONFIG_FILES: case DISPLAYLIST_STREAM_CONFIG_FILES:
info->type_default = FILE_TYPE_STREAM_CONFIG; info->type_default = FILE_TYPE_STREAM_CONFIG;
info->exts = strdup("cfg"); info->exts = strldup("cfg", sizeof("cfg"));
break; break;
case DISPLAYLIST_RECORD_CONFIG_FILES: case DISPLAYLIST_RECORD_CONFIG_FILES:
info->type_default = FILE_TYPE_RECORD_CONFIG; info->type_default = FILE_TYPE_RECORD_CONFIG;
info->exts = strdup("cfg"); info->exts = strldup("cfg", sizeof("cfg"));
break; break;
case DISPLAYLIST_OVERLAYS: case DISPLAYLIST_OVERLAYS:
info->type_default = FILE_TYPE_OVERLAY; info->type_default = FILE_TYPE_OVERLAY;
info->exts = strdup("cfg"); info->exts = strldup("cfg", sizeof("cfg"));
break; break;
case DISPLAYLIST_FONTS: case DISPLAYLIST_FONTS:
info->type_default = FILE_TYPE_FONT; info->type_default = FILE_TYPE_FONT;
info->exts = strdup("ttf"); info->exts = strldup("ttf", sizeof("ttf"));
break; break;
case DISPLAYLIST_VIDEO_FONTS: case DISPLAYLIST_VIDEO_FONTS:
info->type_default = FILE_TYPE_VIDEO_FONT; info->type_default = FILE_TYPE_VIDEO_FONT;
info->exts = strdup("ttf"); info->exts = strldup("ttf", sizeof("ttf"));
break; break;
case DISPLAYLIST_AUDIO_FILTERS: case DISPLAYLIST_AUDIO_FILTERS:
info->type_default = FILE_TYPE_AUDIOFILTER; info->type_default = FILE_TYPE_AUDIOFILTER;
info->exts = strdup("dsp"); info->exts = strldup("dsp", sizeof("dsp"));
break; break;
case DISPLAYLIST_CHEAT_FILES: case DISPLAYLIST_CHEAT_FILES:
info->type_default = FILE_TYPE_CHEAT; info->type_default = FILE_TYPE_CHEAT;
info->exts = strdup("cht"); info->exts = strldup("cht", sizeof("cht"));
break; break;
case DISPLAYLIST_MANUAL_CONTENT_SCAN_DAT_FILES: case DISPLAYLIST_MANUAL_CONTENT_SCAN_DAT_FILES:
info->type_default = FILE_TYPE_MANUAL_SCAN_DAT; info->type_default = FILE_TYPE_MANUAL_SCAN_DAT;
info->exts = strdup("dat|xml"); info->exts = strldup("dat|xml", sizeof("dat|xml"));
break; break;
case DISPLAYLIST_FILE_BROWSER_SELECT_SIDELOAD_CORE: case DISPLAYLIST_FILE_BROWSER_SELECT_SIDELOAD_CORE:
{ {
@ -14002,7 +14002,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
use_filebrowser = true; use_filebrowser = true;
if (!string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("lay|zip"); info->exts = strldup("lay|zip", sizeof("lay|zip"));
break; break;
#endif #endif
case DISPLAYLIST_CONTENT_HISTORY: case DISPLAYLIST_CONTENT_HISTORY:
@ -14012,7 +14012,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
use_filebrowser = true; use_filebrowser = true;
if (!string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("lpl"); info->exts = strldup("lpl", sizeof("lpl"));
break; break;
case DISPLAYLIST_DATABASE_PLAYLISTS: case DISPLAYLIST_DATABASE_PLAYLISTS:
case DISPLAYLIST_DATABASE_PLAYLISTS_HORIZONTAL: case DISPLAYLIST_DATABASE_PLAYLISTS_HORIZONTAL:

View File

@ -2253,7 +2253,7 @@ static bool menu_driver_displaylist_push_internal(
if (!string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup("lpl"); info->exts = strldup("lpl", sizeof("lpl"));
info->label = strdup( info->label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));
@ -2271,7 +2271,7 @@ static bool menu_driver_displaylist_push_internal(
if (!string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup("lpl"); info->exts = strldup("lpl", sizeof("lpl"));
info->label = strdup( info->label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));
@ -2289,7 +2289,7 @@ static bool menu_driver_displaylist_push_internal(
if (!string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup("lpl"); info->exts = strldup("lpl", sizeof("lpl"));
info->label = strdup( info->label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));
@ -2322,7 +2322,7 @@ static bool menu_driver_displaylist_push_internal(
if (!string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup("lpl"); info->exts = strldup("lpl", sizeof("lpl"));
info->label = strdup( info->label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)); msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB));

View File

@ -1347,7 +1347,7 @@ static void content_load_init_wrap(
int *argc, char **argv) int *argc, char **argv)
{ {
*argc = 0; *argc = 0;
argv[(*argc)++] = strdup("retroarch"); argv[(*argc)++] = strldup("retroarch", sizeof("retroarch"));
if (args->content_path) if (args->content_path)
{ {
@ -1359,38 +1359,38 @@ static void content_load_init_wrap(
{ {
RARCH_LOG("[Core]: %s\n", RARCH_LOG("[Core]: %s\n",
msg_hash_to_str(MSG_NO_CONTENT_STARTING_DUMMY_CORE)); msg_hash_to_str(MSG_NO_CONTENT_STARTING_DUMMY_CORE));
argv[(*argc)++] = strdup("--menu"); argv[(*argc)++] = strldup("--menu", sizeof("--menu"));
} }
#endif #endif
if (args->sram_path) if (args->sram_path)
{ {
argv[(*argc)++] = strdup("-s"); argv[(*argc)++] = strldup("-s", sizeof("-s"));
argv[(*argc)++] = strdup(args->sram_path); argv[(*argc)++] = strdup(args->sram_path);
} }
if (args->state_path) if (args->state_path)
{ {
argv[(*argc)++] = strdup("-S"); argv[(*argc)++] = strldup("-S", sizeof("-S"));
argv[(*argc)++] = strdup(args->state_path); argv[(*argc)++] = strdup(args->state_path);
} }
if (args->config_path) if (args->config_path)
{ {
argv[(*argc)++] = strdup("-c"); argv[(*argc)++] = strldup("-c", sizeof("-c"));
argv[(*argc)++] = strdup(args->config_path); argv[(*argc)++] = strdup(args->config_path);
} }
#ifdef HAVE_DYNAMIC #ifdef HAVE_DYNAMIC
if (args->libretro_path) if (args->libretro_path)
{ {
argv[(*argc)++] = strdup("-L"); argv[(*argc)++] = strldup("-L", sizeof("-L"));
argv[(*argc)++] = strdup(args->libretro_path); argv[(*argc)++] = strdup(args->libretro_path);
} }
#endif #endif
if (args->verbose) if (args->verbose)
argv[(*argc)++] = strdup("-v"); argv[(*argc)++] = strldup("-v", sizeof("-v"));
} }
/** /**

View File

@ -125,7 +125,7 @@ void task_file_load_handler(retro_task_t *task)
if (task_get_cancelled(task)) if (task_get_cancelled(task))
{ {
task_set_error(task, strdup("Task canceled.")); task_set_error(task, strldup("Task canceled.", sizeof("Task canceled.")));
task_set_finished(task, true); task_set_finished(task, true);
} }
} }

View File

@ -189,7 +189,8 @@ task_finished:
free(tmp); free(tmp);
if (task_get_cancelled(task)) if (task_get_cancelled(task))
task_set_error(task, strdup("Task cancelled.")); task_set_error(task,
strldup("Task cancelled.", sizeof("Task cancelled.")));
else else
{ {
data = (http_transfer_data_t*)malloc(sizeof(*data)); data = (http_transfer_data_t*)malloc(sizeof(*data));
@ -200,7 +201,8 @@ task_finished:
task_set_data(task, data); task_set_data(task, data);
if (!task->mute) if (!task->mute)
task_set_error(task, strdup("Download failed.")); task_set_error(task, strldup("Download failed.",
sizeof("Download failed.")));
} }
} }
else else
@ -215,7 +217,8 @@ task_finished:
net_http_delete(http->handle); net_http_delete(http->handle);
} else if (http->error) } else if (http->error)
task_set_error(task, strdup("Internal error.")); task_set_error(task, strldup("Internal error.",
sizeof("Internal error.")));
free(http); free(http);
} }