From 5379b12e7c16cbd50d130b01296303e80cb0153d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 29 Sep 2017 05:39:06 +0200 Subject: [PATCH] FIx some new Coverity errors --- libretro-common/file/config_file.c | 4 +-- menu/cbs/menu_cbs_deferred_push.c | 17 ++++++++++--- menu/drivers/xmb.c | 41 +++++++++++++++--------------- menu/widgets/menu_filebrowser.c | 3 ++- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 3c75d929c2..18259e319e 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -242,11 +242,9 @@ static void add_sub_conf(config_file_t *conf, char *path) struct config_include_list *head = conf->includes; struct config_include_list *node = (struct config_include_list*)malloc(sizeof(*node)); - node->path = NULL; - node->next = NULL; - if (node) { + node->next = NULL; /* Add include list */ node->path = strdup(path); diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index 27b69731c6..4489332ece 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -735,7 +735,8 @@ static int general_push(menu_displaylist_info_t *info, break; case PUSH_DEFAULT: { - char *new_exts = NULL; + bool new_exts_allocated = false; + char *new_exts = NULL; if (menu_setting_get_browser_selection_type(info->setting) == ST_DIR) { @@ -743,12 +744,18 @@ static int general_push(menu_displaylist_info_t *info, else if (system_menu && system_menu->valid_extensions) { if (*system_menu->valid_extensions) - new_exts = strdup(system_menu->valid_extensions); + { + new_exts = strdup(system_menu->valid_extensions); + new_exts_allocated = true; + } } else { if (!string_is_empty(system->valid_extensions)) - new_exts = strdup(system->valid_extensions); + { + new_exts = strdup(system->valid_extensions); + new_exts_allocated = true; + } } if (!new_exts) @@ -770,7 +777,11 @@ static int general_push(menu_displaylist_info_t *info, string_list_join_concat(newstring2, path_size, str_list3, "|"); string_list_free(str_list3); + } + + if (new_exts_allocated) + free(new_exts); } break; case PUSH_ARCHIVE_OPEN_DETECT_CORE: diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index db67ffdae1..18838d64d9 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2301,21 +2301,21 @@ static void xmb_draw_items( menu_animation_ctx_ticker_t ticker; char ticker_str[PATH_MAX_LENGTH]; char tmp[255]; + menu_entry_t entry; unsigned entry_type = 0; const float half_size = xmb->icon_size / 2.0f; uintptr_t texture_switch = 0; - xmb_node_t * node = (xmb_node_t*) - menu_entries_get_userdata_at_offset(list, i); bool do_draw_text = false; unsigned ticker_limit = 35; - menu_entry_t *entry = menu_entry_alloc(); + xmb_node_t * node = (xmb_node_t*) + menu_entries_get_userdata_at_offset(list, i); if (!node) continue; ticker_str[0] = tmp[0] = '\0'; - menu_entry_init(entry); + menu_entry_init(&entry); icon_y = xmb->margins_screen_top + node->y + half_size; @@ -2331,23 +2331,23 @@ static void xmb_draw_items( if (icon_x < -half_size || icon_x > width) continue; - menu_entry_get(entry, 0, i, list, true); - entry_type = menu_entry_get_type_new(entry); + menu_entry_get(&entry, 0, i, list, true); + entry_type = menu_entry_get_type_new(&entry); if (entry_type == FILE_TYPE_CONTENTLIST_ENTRY) - fill_short_pathname_representation(entry->path, entry->path, - sizeof(entry->path)); + fill_short_pathname_representation(entry.path, entry.path, + sizeof(entry.path)); - if (string_is_equal(entry->value, msg_hash_to_str(MENU_ENUM_LABEL_DISABLED)) || - (string_is_equal(entry->value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF)))) + if (string_is_equal(entry.value, msg_hash_to_str(MENU_ENUM_LABEL_DISABLED)) || + (string_is_equal(entry.value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF)))) { if (xmb->textures.list[XMB_TEXTURE_SWITCH_OFF]) texture_switch = xmb->textures.list[XMB_TEXTURE_SWITCH_OFF]; else do_draw_text = true; } - else if (string_is_equal(entry->value, msg_hash_to_str(MENU_ENUM_LABEL_ENABLED)) || - (string_is_equal(entry->value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON)))) + else if (string_is_equal(entry.value, msg_hash_to_str(MENU_ENUM_LABEL_ENABLED)) || + (string_is_equal(entry.value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON)))) { if (xmb->textures.list[XMB_TEXTURE_SWITCH_ON]) texture_switch = xmb->textures.list[XMB_TEXTURE_SWITCH_ON]; @@ -2356,7 +2356,7 @@ static void xmb_draw_items( } else { - enum msg_file_type type = msg_hash_to_file_type(msg_hash_calculate(entry->value)); + enum msg_file_type type = msg_hash_to_file_type(msg_hash_calculate(entry.value)); switch (type) { @@ -2379,7 +2379,7 @@ static void xmb_draw_items( } } - if (string_is_empty(entry->value)) + if (string_is_empty(entry.value)) { if (xmb->savestate_thumbnail || (!string_is_equal @@ -2392,7 +2392,7 @@ static void xmb_draw_items( ticker_limit = 70; } - menu_entry_get_rich_label(entry, ticker_str, sizeof(ticker_str)); + menu_entry_get_rich_label(&entry, ticker_str, sizeof(ticker_str)); ticker.s = tmp; ticker.len = ticker_limit; @@ -2404,7 +2404,7 @@ static void xmb_draw_items( label_offset = xmb->margins_label_top; if (i == current && width > 320 && height > 240 - && !string_is_empty(entry->sublabel)) + && !string_is_empty(entry.sublabel)) { char entry_sublabel[255]; @@ -2412,7 +2412,7 @@ static void xmb_draw_items( label_offset = - xmb->margins_label_top; - word_wrap(entry_sublabel, entry->sublabel, 50, true); + word_wrap(entry_sublabel, entry.sublabel, 50, true); xmb_draw_text(menu_disp_info, xmb, entry_sublabel, node->x + xmb->margins_screen_left + @@ -2434,7 +2434,7 @@ static void xmb_draw_items( ticker.s = tmp; ticker.len = 35; ticker.idx = frame_count / 20; - ticker.str = entry->value; + ticker.str = entry.value; ticker.selected = (i == current); menu_animation_ticker(&ticker); @@ -2460,7 +2460,7 @@ static void xmb_draw_items( math_matrix_4x4 mymat; menu_display_ctx_rotate_draw_t rotate_draw; uintptr_t texture = xmb_icon_get_id(xmb, core_node, node, - entry->enum_idx, entry_type, (i == current)); + entry.enum_idx, entry_type, (i == current)); float x = icon_x; float y = icon_y; float rotation = 0; @@ -2510,8 +2510,7 @@ static void xmb_draw_items( &color[0], xmb->shadow_offset); - menu_entry_free(entry); - free(entry); + menu_entry_free(&entry); } menu_display_blend_end(); diff --git a/menu/widgets/menu_filebrowser.c b/menu/widgets/menu_filebrowser.c index 348e86e79c..ca81c2d4de 100644 --- a/menu/widgets/menu_filebrowser.c +++ b/menu/widgets/menu_filebrowser.c @@ -64,7 +64,8 @@ void filebrowser_parse(void *data, unsigned type_data) enum menu_displaylist_ctl_state type = (enum menu_displaylist_ctl_state) type_data; const char *path = info->path; - bool path_is_compressed = path ? path_is_compressed_file(path) : false; + bool path_is_compressed = (path && !string_is_empty(path)) + ? path_is_compressed_file(path) : false; bool filter_ext = settings->bools.menu_navigation_browser_filter_supported_extensions_enable;