diff --git a/tasks/task_content.c b/tasks/task_content.c index 8ccde3e55a..f5c61a9714 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -372,9 +372,10 @@ static bool load_content_from_compressed_archive( char **error_string) { union string_list_elem_attr attributes; - char new_path[PATH_MAX_LENGTH]; - char new_basedir[PATH_MAX_LENGTH]; ssize_t new_path_len = 0; + size_t path_size = PATH_MAX_LENGTH * sizeof(char); + char *new_basedir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); + char *new_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); bool ret = false; new_path[0] = '\0'; @@ -386,7 +387,7 @@ static bool load_content_from_compressed_archive( if (!string_is_empty(content_ctx->directory_cache)) strlcpy(new_basedir, content_ctx->directory_cache, - sizeof(new_basedir)); + path_size); if (string_is_empty(new_basedir) || !path_is_directory(new_basedir)) { @@ -395,35 +396,47 @@ static bool load_content_from_compressed_archive( "Setting cache directory to directory " "derived by basename...\n"); fill_pathname_basedir(new_basedir, path, - sizeof(new_basedir)); + path_size); } new_path[0] = '\0'; new_basedir[0] = '\0'; fill_pathname_join(new_path, new_basedir, - path_basename(path), sizeof(new_path)); + path_basename(path), path_size); - ret = file_archive_compressed_read(path, NULL, new_path, &new_path_len); + ret = file_archive_compressed_read(path, + NULL, new_path, &new_path_len); if (!ret || new_path_len < 0) { - char str[1024]; - snprintf(str, sizeof(str), "%s \"%s\".\n", + char *str = (char*)malloc(1024 * sizeof(char)); + snprintf(str, + 1024 * sizeof(char), + "%s \"%s\".\n", msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE), path); *error_string = strdup(str); - return false; + free(str); + goto error; } string_list_append(additional_path_allocs, new_path, attributes); info[i].path = additional_path_allocs->elems[additional_path_allocs->size -1 ].data; - if (!string_list_append(content_ctx->temporary_content, new_path, attributes)) - return false; + if (!string_list_append(content_ctx->temporary_content, + new_path, attributes)) + goto error; + free(new_basedir); + free(new_path); return true; + +error: + free(new_basedir); + free(new_path); + return false; } static bool content_file_init_extract( @@ -508,9 +521,10 @@ static bool content_file_load( { unsigned i; retro_ctx_load_content_info_t load_info; - char msg[1024]; + size_t msg_size = 1024 * sizeof(char); + char *msg = (char*)malloc(1024 * sizeof(char)); - msg[0] = '\0'; + msg[0] = '\0'; for (i = 0; i < content->size; i++) { @@ -523,10 +537,10 @@ static bool content_file_load( { strlcpy(msg, msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_CONTENT), - sizeof(msg) + msg_size ); *error_string = strdup(msg); - return false; + goto error; } info[i].path = NULL; @@ -544,12 +558,13 @@ static bool content_file_load( content_ctx, i, path, (void**)&info[i].data, &len)) { - snprintf(msg, sizeof(msg), + snprintf(msg, + msg_size, "%s \"%s\".\n", msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE), path); *error_string = strdup(msg); - return false; + goto error; } info[i].size = len; @@ -569,7 +584,7 @@ static bool content_file_load( &info[i], i, additional_path_allocs, need_fullpath, path, error_string)) - return false; + goto error; #endif } } @@ -580,10 +595,11 @@ static bool content_file_load( if (!core_load_game(&load_info)) { - snprintf(msg, sizeof(msg), + snprintf(msg, + msg_size, "%s.", msg_hash_to_str(MSG_FAILED_TO_LOAD_CONTENT)); *error_string = strdup(msg); - return false; + goto error; } #ifdef HAVE_CHEEVOS @@ -599,15 +615,22 @@ static bool content_file_load( } #endif + free(msg); return true; + +error: + free(msg); + return false; } -static const struct retro_subsystem_info *content_file_init_subsystem( +static const struct +retro_subsystem_info *content_file_init_subsystem( content_information_ctx_t *content_ctx, char **error_string, bool *ret) { - char msg[1024]; + size_t path_size = 1024 * sizeof(char); + char *msg = (char*)malloc(1024 * sizeof(char)); struct string_list *subsystem = path_get_subsystem_list(); const struct retro_subsystem_info *special = libretro_find_subsystem_info( content_ctx->subsystem.data, content_ctx->subsystem.size, @@ -617,7 +640,7 @@ static const struct retro_subsystem_info *content_file_init_subsystem( if (!special) { - snprintf(msg, sizeof(msg), + snprintf(msg, path_size, "Failed to find subsystem \"%s\" in libretro implementation.\n", path_get(RARCH_PATH_SUBSYSTEM)); *error_string = strdup(msg); @@ -628,14 +651,15 @@ static const struct retro_subsystem_info *content_file_init_subsystem( { strlcpy(msg, msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_SPECIAL_CONTENT), - sizeof(msg) + path_size ); *error_string = strdup(msg); goto error; } else if (special->num_roms && (special->num_roms != subsystem->size)) { - snprintf(msg, sizeof(msg), + snprintf(msg, + path_size, "Libretro core requires %u content files for " "subsystem \"%s\", but %u content files were provided.\n", special->num_roms, special->desc, @@ -645,7 +669,8 @@ static const struct retro_subsystem_info *content_file_init_subsystem( } else if (!special->num_roms && subsystem && subsystem->size) { - snprintf(msg, sizeof(msg), + snprintf(msg, + path_size, "Libretro core takes no content for subsystem \"%s\", " "but %u content files were provided.\n", special->desc, @@ -655,10 +680,12 @@ static const struct retro_subsystem_info *content_file_init_subsystem( } *ret = true; + free(msg); return special; error: *ret = false; + free(msg); return NULL; } @@ -955,15 +982,15 @@ static bool command_event_cmd_exec(const char *data, static bool firmware_update_status( content_information_ctx_t *content_ctx) { - char s[PATH_MAX_LENGTH]; core_info_ctx_firmware_t firmware_info; - core_info_t *core_info = NULL; + size_t s_size = PATH_MAX_LENGTH * sizeof(char); + char *s = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); core_info_get_current_core(&core_info); if (!core_info) - return false; + goto error; firmware_info.path = core_info->path; @@ -971,12 +998,13 @@ static bool firmware_update_status( firmware_info.directory.system = content_ctx->directory_system; else { - strlcpy(s, path_get(RARCH_PATH_CONTENT) ,sizeof(s)); + strlcpy(s, path_get(RARCH_PATH_CONTENT), s_size); path_basedir_wrapper(s); firmware_info.directory.system = s; } - RARCH_LOG("Updating firmware status for: %s on %s\n", core_info->path, + RARCH_LOG("Updating firmware status for: %s on %s\n", + core_info->path, firmware_info.directory.system); core_info_list_update_missing_firmware(&firmware_info); @@ -984,12 +1012,18 @@ static bool firmware_update_status( content_ctx->bios_is_missing && content_ctx->check_firmware_before_loading) { - runloop_msg_queue_push(msg_hash_to_str(MSG_FIRMWARE), 100, 500, true); - RARCH_LOG("Load content blocked. Reason: %s\n", msg_hash_to_str(MSG_FIRMWARE)); + runloop_msg_queue_push( + msg_hash_to_str(MSG_FIRMWARE), + 100, 500, true); + RARCH_LOG("Load content blocked. Reason: %s\n", + msg_hash_to_str(MSG_FIRMWARE)); + free(s); return true; } +error: + free(s); return false; }