diff options
Diffstat (limited to 'src/libstrongswan/collections')
-rw-r--r-- | src/libstrongswan/collections/array.c | 8 | ||||
-rw-r--r-- | src/libstrongswan/collections/array.h | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/libstrongswan/collections/array.c b/src/libstrongswan/collections/array.c index 8d619116a..61c696bc1 100644 --- a/src/libstrongswan/collections/array.c +++ b/src/libstrongswan/collections/array.c @@ -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) diff --git a/src/libstrongswan/collections/array.h b/src/libstrongswan/collections/array.h index ce702ebfa..0659c70bd 100644 --- a/src/libstrongswan/collections/array.h +++ b/src/libstrongswan/collections/array.h @@ -100,6 +100,11 @@ enumerator_t* array_create_enumerator(array_t *array); /** * Remove an element at enumerator position. * + * @warning For **value based** arrays don't use the pointer returned by + * enumerate() anymore after calling this function. For performance reasons + * that pointer will point to internal data structures that get modified when + * this function is called. + * * @param array array to remove element in * @param enumerator enumerator position, from array_create_enumerator() */ |