From 6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349 Mon Sep 17 00:00:00 2001 From: Yves-Alexis Perez Date: Sun, 25 Aug 2013 15:37:26 +0200 Subject: Imported Upstream version 5.1.0 --- src/libstrongswan/utils/utils.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/libstrongswan/utils/utils.c') diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index 2f38d8a93..30084cd81 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -45,19 +45,6 @@ ENUM(status_names, SUCCESS, NEED_MORE, "NEED_MORE", ); -/** - * Described in header. - */ -void *clalloc(void * pointer, size_t size) -{ - void *data; - data = malloc(size); - - memcpy(data, pointer, size); - - return (data); -} - /** * Described in header. */ @@ -115,7 +102,12 @@ void memwipe_noinline(void *ptr, size_t n) void *memstr(const void *haystack, const char *needle, size_t n) { unsigned const char *pos = haystack; - size_t l = strlen(needle); + size_t l; + + if (!haystack || !needle || (l = strlen(needle)) == 0) + { + return NULL; + } for (; n >= l; ++pos, --n) { if (memeq(pos, needle, l)) @@ -474,11 +466,15 @@ static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER; /** * Increase refcount */ -void ref_get(refcount_t *ref) +refcount_t ref_get(refcount_t *ref) { + refcount_t current; + pthread_mutex_lock(&ref_mutex); - (*ref)++; + current = ++(*ref); pthread_mutex_unlock(&ref_mutex); + + return current; } /** -- cgit v1.2.3