From b56b447f08457a5aac90799c040f066e4e3d7bec Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Fri, 15 Jul 2022 19:16:21 +0200 Subject: [PATCH] Fix these two memory errors that popped up with ASAN - * Argument base for qsort cannot be NULL * When system_count is 0 or less, early return out of explore_load_icons --- menu/menu_explore.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/menu/menu_explore.c b/menu/menu_explore.c index 4f75e2a89c..fb8fa6fff2 100644 --- a/menu/menu_explore.c +++ b/menu/menu_explore.c @@ -379,12 +379,14 @@ static void explore_load_icons(explore_state_t *state) if (!state) return; - system_count = RBUF_LEN(state->by[EXPLORE_BY_SYSTEM]); + if ((system_count = RBUF_LEN(state->by[EXPLORE_BY_SYSTEM])) <= 0) + return; /* unload any icons that could exist from a previous call to this */ explore_unload_icons(state); - /* RBUF_RESIZE leaves memory uninitialised, have to zero it 'manually' */ + /* RBUF_RESIZE leaves memory uninitialised, + have to zero it 'manually' */ RBUF_RESIZE(state->icons, system_count); memset(state->icons, 0, RBUF_SIZEOF(state->icons)); @@ -757,7 +759,9 @@ explore_state_t *menu_explore_build_list(const char *directory_playlist, RHMAP_FREE(cat_maps[i]); } - qsort(explore->entries, + /* NULL is not a valid value as a first argument for qsort */ + if (explore->entries) + qsort(explore->entries, RBUF_LEN(explore->entries), sizeof(*explore->entries), explore_qsort_func_entries); return explore;