From 2d14845c7c1b71d0d6531314da4cba9b24e1856b Mon Sep 17 00:00:00 2001 From: Seungjin Park Date: Mon, 11 Apr 2016 10:22:47 +0900 Subject: [PATCH] e_path: Add null pointer check Change-Id: Ic0c1cf151f22ff310e8ac7de8082759864a99667 --- src/bin/e_path.c | 69 +++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/bin/e_path.c b/src/bin/e_path.c index 6fef5ce9e1..04efc2eba1 100644 --- a/src/bin/e_path.c +++ b/src/bin/e_path.c @@ -176,19 +176,22 @@ e_path_user_path_remove(E_Path *ep, const char *path) if (!new_path) return; strncpy(new_path, home_dir, len1 + 1); strncat(new_path, path + 1, len1 + len2); - EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd) + if (ep->user_dir_list) { - if (epd->dir) + EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd) { - if (!strcmp(epd->dir, new_path)) + if (epd->dir) { - *(ep->user_dir_list) = eina_list_remove_list( - *(ep->user_dir_list), l); - eina_stringshare_del(epd->dir); - free(epd); - free(new_path); - _e_path_cache_free(ep); - return; + if (!strcmp(epd->dir, new_path)) + { + *(ep->user_dir_list) = eina_list_remove_list( + *(ep->user_dir_list), l); + eina_stringshare_del(epd->dir); + free(epd); + free(new_path); + _e_path_cache_free(ep); + return; + } } } } @@ -196,18 +199,21 @@ e_path_user_path_remove(E_Path *ep, const char *path) } else { - EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd) + if (ep->user_dir_list) { - if (epd->dir) + EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd) { - if (!strcmp(epd->dir, path)) + if (epd->dir) { - *(ep->user_dir_list) = eina_list_remove_list( - *(ep->user_dir_list), l); - eina_stringshare_del(epd->dir); - free(epd); - _e_path_cache_free(ep); - return; + if (!strcmp(epd->dir, path)) + { + *(ep->user_dir_list) = eina_list_remove_list( + *(ep->user_dir_list), l); + eina_stringshare_del(epd->dir); + free(epd); + _e_path_cache_free(ep); + return; + } } } } @@ -260,20 +266,23 @@ e_path_find(E_Path *ep, const char *file) } } /* Look in the users dir list */ - EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd) + if (ep->user_dir_list) { - if (epd->dir) + EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd) { - snprintf(buf, sizeof(buf), "%s/%s", epd->dir, file); - if (ecore_file_exists(buf)) + if (epd->dir) { - if (!ep->hash) - ep->hash = eina_hash_string_superfast_new(NULL); - if (eina_hash_population(ep->hash) >= 512) - _e_path_cache_free(ep); - ret = eina_stringshare_add(buf); - eina_hash_add(ep->hash, file, ret); - return eina_stringshare_ref(ret); + snprintf(buf, sizeof(buf), "%s/%s", epd->dir, file); + if (ecore_file_exists(buf)) + { + if (!ep->hash) + ep->hash = eina_hash_string_superfast_new(NULL); + if (eina_hash_population(ep->hash) >= 512) + _e_path_cache_free(ep); + ret = eina_stringshare_add(buf); + eina_hash_add(ep->hash, file, ret); + return eina_stringshare_ref(ret); + } } } } -- 2.34.1