diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index efb97139c5..9cbab26b3a 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -99,8 +99,8 @@ static bool get_thumbnail_paths( const char *sub_dir = NULL; const char *system_name = NULL; - content_dir[0] = '\0'; - tmp_buf[0] = '\0'; + content_dir[0] = '\0'; + tmp_buf[0] = '\0'; if (!pl_thumb->thumbnail_path_data) return false; @@ -126,8 +126,8 @@ static bool get_thumbnail_paths( * then the current 'path_data->system' string is * meaningless. In this case, we fall back to the * content directory name */ - if (string_is_equal(system, "history") || - string_is_equal(system, "favorites")) + if ( string_is_equal(system, "history") + || string_is_equal(system, "favorites")) { if (!gfx_thumbnail_get_content_dir( pl_thumb->thumbnail_path_data, content_dir, sizeof(content_dir))) @@ -149,10 +149,7 @@ static bool get_thumbnail_paths( if (string_is_empty(path)) return false; - - raw_url = (char*)malloc(8192 * sizeof(char)); - - if (!raw_url) + if (!(raw_url = (char*)malloc(8192 * sizeof(char)))) return false; raw_url[0] = '\0'; @@ -194,18 +191,13 @@ void cb_http_task_download_pl_thumbnail( if (!transf) goto finish; - pl_thumb = (pl_thumb_handle_t*)transf->user_data; - - if (!pl_thumb) + if (!(pl_thumb = (pl_thumb_handle_t*)transf->user_data)) goto finish; pl_thumb->http_task_complete = true; /* Remaining sanity checks... */ - if (!data) - goto finish; - - if (!data->data || string_is_empty(transf->path)) + if (!data || !data->data || string_is_empty(transf->path)) goto finish; /* Create output directory, if required */ @@ -248,10 +240,6 @@ static void download_pl_thumbnail(pl_thumb_handle_t *pl_thumb) path[0] = '\0'; url[0] = '\0'; - /* Sanity check */ - if (!pl_thumb) - return; - /* Check if paths are valid */ if (get_thumbnail_paths(pl_thumb, path, sizeof(path), url, sizeof(url))) { @@ -274,12 +262,11 @@ static void download_pl_thumbnail(pl_thumb_handle_t *pl_thumb) /* Note: We don't actually care if this fails since that * just means the file is missing from the server, so it's * not something we can handle here... */ - pl_thumb->http_task = (retro_task_t*)task_push_http_transfer_file( - url, true, NULL, cb_http_task_download_pl_thumbnail, transf); /* ...if it does fail, however, we can immediately * signal that the task is 'complete' */ - if (!pl_thumb->http_task) + if (!(pl_thumb->http_task = (retro_task_t*)task_push_http_transfer_file( + url, true, NULL, cb_http_task_download_pl_thumbnail, transf))) pl_thumb->http_task_complete = true; } } @@ -287,9 +274,6 @@ static void download_pl_thumbnail(pl_thumb_handle_t *pl_thumb) static void free_pl_thumb_handle(pl_thumb_handle_t *pl_thumb) { - if (!pl_thumb) - return; - if (pl_thumb->system) { free(pl_thumb->system); @@ -335,9 +319,7 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) if (!task) goto task_finished; - pl_thumb = (pl_thumb_handle_t*)task->state; - - if (!pl_thumb) + if (!(pl_thumb = (pl_thumb_handle_t*)task->state)) goto task_finished; if (task_get_cancelled(task)) @@ -350,9 +332,7 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) if (!path_is_valid(pl_thumb->playlist_config.path)) goto task_finished; - pl_thumb->playlist = playlist_init(&pl_thumb->playlist_config); - - if (!pl_thumb->playlist) + if (!(pl_thumb->playlist = playlist_init(&pl_thumb->playlist_config))) goto task_finished; pl_thumb->list_size = playlist_size(pl_thumb->playlist); @@ -361,9 +341,7 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) goto task_finished; /* Initialise thumbnail path data */ - pl_thumb->thumbnail_path_data = gfx_thumbnail_path_init(); - - if (!pl_thumb->thumbnail_path_data) + if (!(pl_thumb->thumbnail_path_data = gfx_thumbnail_path_init())) goto task_finished; if (!gfx_thumbnail_set_system( @@ -411,10 +389,9 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) * current task is 'complete' */ if (!pl_thumb->http_task) pl_thumb->http_task_complete = true; - /* > Wait for task_push_http_transfer_file() * callback to trigger */ - if (!pl_thumb->http_task_complete) + else if (!pl_thumb->http_task_complete) break; pl_thumb->http_task = NULL; @@ -432,7 +409,8 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) } /* Download current thumbnail */ - download_pl_thumbnail(pl_thumb); + if (pl_thumb) + download_pl_thumbnail(pl_thumb); /* Increment thumbnail type */ pl_thumb->type_idx++; @@ -446,28 +424,21 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) return; task_finished: - if (task) task_set_finished(task, true); - - free_pl_thumb_handle(pl_thumb); + if (pl_thumb) + free_pl_thumb_handle(pl_thumb); } static bool task_pl_thumbnail_finder(retro_task_t *task, void *user_data) { - pl_thumb_handle_t *pl_thumb = NULL; - - if (!task || !user_data) - return false; - - if (task->handler != task_pl_thumbnail_download_handler) - return false; - - pl_thumb = (pl_thumb_handle_t*)task->state; - if (!pl_thumb) - return false; - - return string_is_equal((const char*)user_data, pl_thumb->playlist_config.path); + if (task && user_data && task->handler == task_pl_thumbnail_download_handler) + { + pl_thumb_handle_t *pl_thumb = NULL; + if ((pl_thumb = (pl_thumb_handle_t*)task->state)) + return string_is_equal((const char*)user_data, pl_thumb->playlist_config.path); + } + return false; } bool task_push_pl_thumbnail_download( @@ -484,9 +455,9 @@ bool task_push_pl_thumbnail_download( if (!playlist_config || !task || !pl_thumb) goto error; - if (string_is_empty(system) || - string_is_empty(playlist_config->path) || - string_is_empty(dir_thumbnails)) + if ( string_is_empty(system) + || string_is_empty(playlist_config->path) + || string_is_empty(dir_thumbnails)) goto error; playlist_file = path_basename_nocompression( @@ -544,7 +515,6 @@ bool task_push_pl_thumbnail_download( return true; error: - if (task) { free(task); @@ -569,7 +539,6 @@ static void cb_task_pl_entry_thumbnail_refresh_menu( void *user_data, const char *err) { #if defined(RARCH_INTERNAL) && defined(HAVE_MENU) - pl_thumb_handle_t *pl_thumb = NULL; const char *thumbnail_path = NULL; const char *left_thumbnail_path = NULL; @@ -596,10 +565,7 @@ static void cb_task_pl_entry_thumbnail_refresh_menu( * maximum speed with on demand downloads enabled) * NOTE: GLUI requires special treatment, since * it displays multiple thumbnails at a time... */ - - if (!current_playlist) - return; - if (!menu) + if (!current_playlist || !menu) return; if (string_is_empty(playlist_get_conf_path(current_playlist))) return; @@ -649,13 +615,8 @@ static void cb_task_pl_entry_thumbnail_refresh_menu( static void task_pl_entry_thumbnail_free(retro_task_t *task) { pl_thumb_handle_t *pl_thumb = NULL; - - if (!task) - return; - - pl_thumb = (pl_thumb_handle_t*)task->state; - - free_pl_thumb_handle(pl_thumb); + if (task && (pl_thumb = (pl_thumb_handle_t*)task->state)) + free_pl_thumb_handle(pl_thumb); } static void task_pl_entry_thumbnail_download_handler(retro_task_t *task) @@ -665,9 +626,7 @@ static void task_pl_entry_thumbnail_download_handler(retro_task_t *task) if (!task) return; - pl_thumb = (pl_thumb_handle_t*)task->state; - - if (!pl_thumb) + if (!(pl_thumb = (pl_thumb_handle_t*)task->state)) goto task_finished; if (task_get_cancelled(task)) @@ -715,7 +674,7 @@ static void task_pl_entry_thumbnail_download_handler(retro_task_t *task) * current task is 'complete' */ if (!pl_thumb->http_task) pl_thumb->http_task_complete = true; - + /* > Wait for task_push_http_transfer_file() * callback to trigger */ if (pl_thumb->http_task_complete) @@ -734,7 +693,8 @@ static void task_pl_entry_thumbnail_download_handler(retro_task_t *task) task_set_progress(task, ((pl_thumb->type_idx - 1) * 100) / 3); /* Download current thumbnail */ - download_pl_thumbnail(pl_thumb); + if (pl_thumb) + download_pl_thumbnail(pl_thumb); /* Increment thumbnail type */ pl_thumb->type_idx++; @@ -757,24 +717,17 @@ task_finished: static bool task_pl_entry_thumbnail_finder(retro_task_t *task, void *user_data) { pl_entry_id_t *entry_id = NULL; - pl_thumb_handle_t *pl_thumb = NULL; - - if (!task || !user_data) - return false; - - if (task->handler != task_pl_entry_thumbnail_download_handler) - return false; - - entry_id = (pl_entry_id_t*)user_data; - if (!entry_id) - return false; - - pl_thumb = (pl_thumb_handle_t*)task->state; - if (!pl_thumb) - return false; - - return (entry_id->idx == pl_thumb->list_index) && - string_is_equal(entry_id->playlist_path, pl_thumb->playlist_path); + if ( task + && user_data + && task->handler == task_pl_entry_thumbnail_download_handler + && (entry_id = (pl_entry_id_t*)user_data)) + { + pl_thumb_handle_t *pl_thumb = NULL; + if ((pl_thumb = (pl_thumb_handle_t*)task->state)) + return (entry_id->idx == pl_thumb->list_index) && + string_is_equal(entry_id->playlist_path, pl_thumb->playlist_path); + } + return false; } bool task_push_pl_entry_thumbnail_download(