From: Tobias Brunner Date: Fri, 29 Aug 2014 08:18:07 +0000 (+0200) Subject: array: Adjust negative index before calling remove_head|tail() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8a8c153f17f8dd706955703ec79d193c77730f9;p=thirdparty%2Fstrongswan.git array: Adjust negative index before calling remove_head|tail() For ARRAY_TAIL we most often want to call remove_tail() not remove_head(). --- diff --git a/src/libstrongswan/collections/array.c b/src/libstrongswan/collections/array.c index c1fc8f3976..dedbb25bf3 100644 --- a/src/libstrongswan/collections/array.c +++ b/src/libstrongswan/collections/array.c @@ -377,16 +377,16 @@ bool array_remove(array_t *array, int idx, void *data) { return FALSE; } + if (idx < 0) + { + idx = array_count(array) - 1; + } if (idx > array_count(array) / 2) { remove_tail(array, idx); } else { - if (idx < 0) - { - idx = array_count(array) - 1; - } remove_head(array, idx); } if (array->head + array->tail > ARRAY_MAX_UNUSED)