array: Adjust negative index before calling remove_head|tail()
authorTobias Brunner <tobias@strongswan.org>
Fri, 29 Aug 2014 08:18:07 +0000 (10:18 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 11 Sep 2014 15:52:37 +0000 (17:52 +0200)
For ARRAY_TAIL we most often want to call remove_tail() not remove_head().

src/libstrongswan/collections/array.c

index 8d61911..61c696b 100644 (file)
@@ -361,16 +361,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)