diff --git a/core_info.c b/core_info.c index faa4b5bde0..b2c24be931 100644 --- a/core_info.c +++ b/core_info.c @@ -261,8 +261,8 @@ static bool CCJSONStringHandler(void *context, { CCJSONContext *pCtx = (CCJSONContext*)context; - if ( pCtx->current_string_val - && length + if ( pCtx->current_string_val + && length && !string_is_empty(pValue)) { if (*pCtx->current_string_val) @@ -273,7 +273,7 @@ static bool CCJSONStringHandler(void *context, { if (*pCtx->current_string_list_val) string_list_free(*pCtx->current_string_list_val); - *pCtx->current_string_list_val = + *pCtx->current_string_list_val = string_split(*pCtx->current_string_val, "|"); } } @@ -315,7 +315,7 @@ static bool CCJSONStartObjectHandler(void *context) pCtx->object_depth++; - if ( (pCtx->object_depth == 1) + if ( (pCtx->object_depth == 1) && (pCtx->array_depth == 0)) { if (pCtx->core_info_cache_list) @@ -323,7 +323,7 @@ static bool CCJSONStartObjectHandler(void *context) if (!(pCtx->core_info_cache_list = core_info_cache_list_new())) return false; } - else if ((pCtx->object_depth == 2) + else if ((pCtx->object_depth == 2) && (pCtx->array_depth == 1)) { if (pCtx->core_info) @@ -341,7 +341,7 @@ static bool CCJSONStartObjectHandler(void *context) pCtx->core_info->savestate_support_level = CORE_INFO_SAVESTATE_DETERMINISTIC; } - else if ((pCtx->object_depth == 3) + else if ((pCtx->object_depth == 3) && (pCtx->array_depth == 2)) { if (pCtx->to_firmware) @@ -349,7 +349,7 @@ static bool CCJSONStartObjectHandler(void *context) size_t new_idx = pCtx->core_info->firmware_count; core_info_firmware_t *tmp = (core_info_firmware_t*) realloc(pCtx->core_info->firmware, - (pCtx->core_info->firmware_count + 1) + (pCtx->core_info->firmware_count + 1) * sizeof(core_info_firmware_t)); if (!tmp) @@ -372,7 +372,7 @@ static bool CCJSONEndObjectHandler(void *context) { CCJSONContext *pCtx = (CCJSONContext*)context; - if ( (pCtx->object_depth == 2) + if ( (pCtx->object_depth == 2) && (pCtx->array_depth == 1) && (pCtx->core_info)) { @@ -381,7 +381,7 @@ static bool CCJSONEndObjectHandler(void *context) free(pCtx->core_info); pCtx->core_info = NULL; } - else if ((pCtx->object_depth == 3) + else if ((pCtx->object_depth == 3) && (pCtx->array_depth == 1)) pCtx->to_core_file_id = false; @@ -465,7 +465,7 @@ static void core_info_copy(core_info_t *src, core_info_t *dst) dst->firmware_count = 0; } - dst->core_file_id.str = src->core_file_id.str + dst->core_file_id.str = src->core_file_id.str ? strdup(src->core_file_id.str) : NULL; dst->core_file_id.hash = src->core_file_id.hash; @@ -670,7 +670,7 @@ static void core_info_cache_add( #ifdef HAVE_CORE_INFO_CACHE static core_info_cache_list_t *core_info_cache_list_new(void) { - core_info_cache_list_t *core_info_cache_list = + core_info_cache_list_t *core_info_cache_list = (core_info_cache_list_t *)malloc(sizeof(*core_info_cache_list)); if (!core_info_cache_list) return NULL; @@ -765,8 +765,8 @@ static core_info_cache_list_t *core_info_cache_read(const char *info_dir) RARCH_WARN("[Core Info]: Error: Invalid JSON at line %d, column %d - %s.\n", (int)rjson_get_source_line(parser), (int)rjson_get_source_column(parser), - (*rjson_get_error(parser) - ? rjson_get_error(parser) + (*rjson_get_error(parser) + ? rjson_get_error(parser) : "format error")); /* Info cache is corrupt - discard it */ @@ -1368,7 +1368,7 @@ static core_path_list_t *core_info_path_list_new(const char *core_dir, calloc(1, sizeof(*path_list->standalone_exempt_list)); if ( !path_list->dir_list - || !path_list->core_list + || !path_list->core_list || !path_list->lock_list || !path_list->standalone_exempt_list) goto error; @@ -1421,7 +1421,7 @@ static core_path_list_t *core_info_path_list_new(const char *core_dir, sizeof(*path_list->standalone_exempt_list->list)); if ( !path_list->core_list->list - || !path_list->lock_list->list + || !path_list->lock_list->list || !path_list->standalone_exempt_list->list) goto error; @@ -1899,12 +1899,13 @@ static void core_info_list_resolve_all_extensions( for (i = 0; i < core_info_list->count; i++) { + size_t _len; if (!core_info_list->list[i].supported_extensions) continue; - strlcat(core_info_list->all_ext, + _len = strlcat(core_info_list->all_ext, core_info_list->list[i].supported_extensions, all_ext_len); - strlcat(core_info_list->all_ext, "|", all_ext_len); + strlcpy(core_info_list->all_ext + _len, "|", all_ext_len - _len); } #ifdef HAVE_7ZIP strlcat(core_info_list->all_ext, "7z|", all_ext_len); @@ -2336,8 +2337,8 @@ bool core_info_init_list( core_info_state_t *p_coreinfo = &core_info_st; if (!(p_coreinfo->curr_list = core_info_list_new( dir_cores, - !string_is_empty(path_info) - ? path_info + !string_is_empty(path_info) + ? path_info : dir_cores, exts, dir_show_hidden_files, @@ -2481,7 +2482,7 @@ void core_info_list_get_supported_cores(core_info_list_t *core_info_list, * * e.g.: * snes9x_libretro.dll and snes9x_libretro_android.so are matched - * snes9x__2005_libretro.dll and snes9x_libretro_android.so are + * snes9x__2005_libretro.dll and snes9x_libretro_android.so are * NOT matched */ bool core_info_core_file_id_is_equal(const char *core_path_a, @@ -2594,7 +2595,7 @@ bool core_info_list_get_display_name( info = core_info_find_internal( core_info_list, core_path); - if ( s + if ( s && info && !string_is_empty(info->display_name)) { @@ -2613,7 +2614,7 @@ bool core_info_list_get_display_name( core_updater_info_t *core_info_get_core_updater_info( const char *info_path) { - struct config_entry_list + struct config_entry_list *entry = NULL; bool tmp_bool = false; core_updater_info_t *info = NULL; @@ -2705,7 +2706,7 @@ static int core_info_qsort_func_display_name(const core_info_t *a, { if ( !a || !b - || string_is_empty(a->display_name) + || string_is_empty(a->display_name) || string_is_empty(b->display_name)) return 0; return strcasecmp(a->display_name, b->display_name); @@ -2716,7 +2717,7 @@ static int core_info_qsort_func_core_name(const core_info_t *a, { if ( !a || !b - || string_is_empty(a->core_name) + || string_is_empty(a->core_name) || string_is_empty(b->core_name)) return 0; return strcasecmp(a->core_name, b->core_name); @@ -2728,7 +2729,7 @@ static int core_info_qsort_func_system_name(const core_info_t *a, if ( !a || !b - || string_is_empty(a->systemname) + || string_is_empty(a->systemname) || string_is_empty(b->systemname)) return 0; return strcasecmp(a->systemname, b->systemname); diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 65e93e16db..69b73aa6ef 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -1523,9 +1523,9 @@ static int action_bind_sublabel_subsystem_load( for (j = 0; j < content_get_subsystem_rom_id(); j++) { - strlcat(buf, path_basename(content_get_subsystem_rom(j)), sizeof(buf)); + size_t _len = strlcat(buf, path_basename(content_get_subsystem_rom(j)), sizeof(buf)); if (j != content_get_subsystem_rom_id() - 1) - strlcat(buf, "\n", sizeof(buf)); + _len += strlcpy(buf + _len, "\n", sizeof(buf) - _len); } if (!string_is_empty(buf)) diff --git a/retroarch.c b/retroarch.c index 21fd1023d6..c6e075587d 100644 --- a/retroarch.c +++ b/retroarch.c @@ -6185,7 +6185,8 @@ static void retroarch_print_version(void) static void retroarch_print_help(const char *arg0) { char buf[2048]; - buf[0] = '\0'; + size_t _len = 0; + buf[0] = '\0'; frontend_driver_attach_console(); fputs("\n", stdout); @@ -6196,7 +6197,7 @@ static void retroarch_print_help(const char *arg0) fprintf(stdout, "Usage: %s [OPTIONS]... [FILE]\n\n", arg0); - strlcat(buf, + _len = strlcpy(buf + _len, " -h, --help " "Show this help message.\n" " -v, --verbose " @@ -6207,29 +6208,29 @@ static void retroarch_print_help(const char *arg0) "Show version.\n" " --features " "Print available features compiled into program.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #ifdef HAVE_MENU - strlcat(buf, + _len += strlcpy(buf + _len, " --menu " "Do not require content or libretro core to be loaded,\n" " " " starts directly in menu. If no arguments are passed to\n" " " " the program, it is equivalent to using --menu as only argument.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif #ifdef HAVE_CONFIGFILE - strlcat(buf, " -c, --config=FILE " - "Path for config file.\n", sizeof(buf)); + _len += strlcpy(buf + _len, " -c, --config=FILE " + "Path for config file.\n", sizeof(buf) - _len); #ifdef _WIN32 - strlcat(buf, " " + _len += strlcpy(buf + _len, " " " Defaults to retroarch.cfg in same directory as retroarch.exe.\n" " " " If a default config is not found, the program will attempt to create one.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #else - strlcat(buf, + _len += strlcpy(buf + _len, " " " By default looks for config in\n" " " @@ -6242,22 +6243,32 @@ static void retroarch_print_help(const char *arg0) " If a default config is not found, the program will attempt to create one\n" " " " based on the skeleton config (" GLOBAL_CONFIG_DIR "/retroarch.cfg).\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif - strlcat(buf, " --appendconfig=FILE " + _len += strlcpy(buf + _len, " --appendconfig=FILE " "Extra config files are loaded in, and take priority over\n" " " " config selected in -c (or default). Multiple configs are\n" " " " delimited by '|'.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif fputs(buf, stdout); buf[0] = '\0'; + _len = 0; + + _len += strlcpy(buf + _len, + " --subsystem=NAME " + "Use a subsystem of the libretro core. Multiple content\n" + " " + " files are loaded as multiple arguments. If a content\n" + " " + " file is skipped, use a blank (\"\") command line argument.\n" + , sizeof(buf) - _len); #ifdef HAVE_DYNAMIC - strlcat(buf, + _len += strlcpy(buf + _len, " -L, --libretro=FILE " "Path to libretro implementation. Overrides any config setting.\n" " " @@ -6266,42 +6277,34 @@ static void retroarch_print_help(const char *arg0) " 1. The full path to a core shared object library: path/to/_libretro.\n" " " " 2. A core shared object library 'file name' (*): _libretro.\n" - , sizeof(buf)); - strlcat(buf, + , sizeof(buf) - _len); + _len += strlcpy(buf + _len, " " " 3. A core 'short name' (*): _libretro OR \n" " " " (*) If 'file name' or 'short name' do not correspond to an existing full file path,\n" " " " the configured frontend 'cores' directory will be searched for a match.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif - strlcat(buf, - " --subsystem=NAME " - "Use a subsystem of the libretro core. Multiple content\n" - " " - " files are loaded as multiple arguments. If a content\n" - " " - " file is skipped, use a blank (\"\") command line argument.\n" - , sizeof(buf)); - strlcat(buf, + _len += strlcpy(buf + _len, " " " Content must be loaded in an order which depends on the\n" " " " particular subsystem used. See verbose log output to learn\n" " " " how a particular subsystem wants content to be loaded.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #ifdef HAVE_LIBRETRODB - strlcat(buf, + _len += strlcpy(buf + _len, " --scan=PATH|FILE " "Import content from path.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif - strlcat(buf, + _len = strlcpy(buf + _len, " -f, --fullscreen " "Start the program in fullscreen regardless of config setting.\n" " --set-shader=PATH " @@ -6310,18 +6313,20 @@ static void retroarch_print_help(const char *arg0) " Effectively overrides automatic shader presets.\n" " " " An empty argument \"\" will disable automatic shader presets.\n" - , sizeof(buf)); + , sizeof(buf) - _len); fputs(buf, stdout); buf[0] = '\0'; + _len = 0; - printf( " -N, --nodevice=PORT " + _len += snprintf(buf + _len, sizeof(buf) - _len," -N, --nodevice=PORT " "Disconnects controller device connected to PORT (1 to %d).\n", MAX_USERS); - printf( " -A, --dualanalog=PORT " + _len += snprintf(buf + _len, sizeof(buf) - _len," -A, --dualanalog=PORT " "Connect a DualAnalog controller to PORT (1 to %d).\n", MAX_USERS); - printf( " -d, --device=PORT:ID " + _len += snprintf(buf + _len, sizeof(buf) - _len," -d, --device=PORT:ID " "Connect a generic device into PORT of the device (1 to %d).\n", MAX_USERS); - strlcat(buf, + + _len += strlcpy(buf + _len, " " " Format is PORT:ID, where ID is a number corresponding to the particular device.\n" " -M, --sram-mode=MODE " @@ -6330,10 +6335,10 @@ static void retroarch_print_help(const char *arg0) " 'noload-nosave', 'noload-save', 'load-nosave' or 'load-save'.\n" " " " Note: 'noload-save' implies that save files *WILL BE OVERWRITTEN*.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #ifdef HAVE_NETWORKING - strlcat(buf, + _len += strlcpy(buf + _len, " -H, --host " "Host netplay as user 1.\n" " -C, --connect=HOST " @@ -6346,87 +6351,86 @@ static void retroarch_print_help(const char *arg0) "Picks a username (for use with netplay). Not mandatory.\n" " --check-frames=NUMBER " "Check frames when using netplay.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #ifdef HAVE_NETWORK_CMD - strlcat(buf, + _len += strlcpy(buf + _len, " --command " "Sends a command over UDP to an already running program process.\n" " " " Available commands are listed if command is invalid.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif #endif #ifdef HAVE_BSV_MOVIE - strlcat(buf, + _len += strlcpy(buf + _len, " -P, --play-replay=FILE " "Playback a replay file.\n" " -R, --record-replay=FILE " "Start recording a replay file from the beginning.\n" " --eof-exit " "Exit upon reaching the end of the replay file.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif - strlcat(buf, + _len += strlcpy(buf + _len, " -r, --record=FILE " "Path to record video file. Using mkv extension is recommended.\n" " --recordconfig " "Path to settings used during recording.\n" " --size=WIDTHxHEIGHT " "Overrides output video size when recording.\n" - , sizeof(buf)); + , sizeof(buf) - _len); fputs(buf, stdout); buf[0] = '\0'; + _len = 0; - strlcat(buf, + _len = strlcpy(buf + _len, " -D, --detach " "Detach program from the running console. Not relevant for all platforms.\n" " --max-frames=NUMBER " "Runs for the specified number of frames, then exits.\n" - , sizeof(buf)); - - + , sizeof(buf) - _len); #ifdef HAVE_PATCH - strlcat(buf, + _len += strlcpy(buf + _len, " -U, --ups=FILE " "Specifies path for UPS patch that will be applied to content.\n" " --bps=FILE " "Specifies path for BPS patch that will be applied to content.\n" " --ips=FILE " "Specifies path for IPS patch that will be applied to content.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #ifdef HAVE_XDELTA - strlcat(buf, + _len += strlcpy(buf + _len, " --xdelta=FILE " "Specifies path for Xdelta patch that will be applied to content.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif /* HAVE_XDELTA */ - strlcat(buf, + _len += strlcpy(buf + _len, " --no-patch " "Disables all forms of content patching.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif /* HAVE_PATCH */ #ifdef HAVE_SCREENSHOTS - strlcat(buf, + _len += strlcpy(buf + _len, " --max-frames-ss " "Takes a screenshot at the end of max-frames.\n" " --max-frames-ss-path=FILE " "Path to save the screenshot to at the end of max-frames.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif #ifdef HAVE_ACCESSIBILITY - strlcat(buf, + _len += strlcpy(buf + _len, " --accessibility " "Enables accessibilty for blind users using text-to-speech.\n" - , sizeof(buf)); + , sizeof(buf) - _len); #endif - strlcat(buf, + _len += strlcpy(buf + _len, " --load-menu-on-error " "Open menu instead of quitting if specified core or content fails to load.\n" " -e, --entryslot=NUMBER " @@ -6435,7 +6439,7 @@ static void retroarch_print_help(const char *arg0) "Path for save files (*.srm). (DEPRECATED, use --appendconfig and savefile_directory)\n" " -S, --savestate=PATH " "Path for the save state files (*.state). (DEPRECATED, use --appendconfig and savestate_directory)\n" - , sizeof(buf)); + , sizeof(buf) - _len); fputs(buf, stdout); }