From 45bc09ae553e7ac5bf6cd7ab2e77e7f6d0877596 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Tue, 12 Nov 2019 00:15:11 +0100 Subject: [HICN-395] Static face/route maintainance though face manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8f2287a262412bacc50f3c89756ec9fd6ce30d33 Signed-off-by: Jordan Augé --- lib/includes/hicn/util/array.h | 3 ++- lib/includes/hicn/util/set.h | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/includes/hicn/util/array.h b/lib/includes/hicn/util/array.h index ab8852ed8..56cfcad8b 100644 --- a/lib/includes/hicn/util/array.h +++ b/lib/includes/hicn/util/array.h @@ -167,9 +167,10 @@ NAME ## _get(const NAME ## _t * array, const T search, T * element) { \ assert(element); \ for (unsigned i = 0; i < array->size; i++) \ - if (CMP(search, array->elements[i]) == 0) \ + if (CMP(search, array->elements[i]) == 0) { \ *element = array->elements[i]; \ return 0; \ + } \ /* Not found */ \ *element = NULL; \ return 0; \ diff --git a/lib/includes/hicn/util/set.h b/lib/includes/hicn/util/set.h index c1f43918b..c7dd7bf09 100644 --- a/lib/includes/hicn/util/set.h +++ b/lib/includes/hicn/util/set.h @@ -138,10 +138,12 @@ NAME ## _free(NAME ## _t * set) \ int \ NAME ## _add(NAME ## _t * set, const T element) \ { \ + T * found = tfind(element, &set->root, (cmp_t)CMP); \ void * ptr = tsearch(element, &set->root, (cmp_t)CMP); \ if (!ptr) \ return -1; \ - set->size++; \ + if (!found) \ + set->size++; \ return 0; \ } \ \ @@ -214,7 +216,7 @@ int \ NAME ## _get_array(const NAME ## _t * set, T ** element) \ { \ if (!element) \ - goto END; \ + goto END; \ *element = malloc(set->size * sizeof(T)); \ if (!*element) \ return -1; \ -- cgit 1.2.3-korg