]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: array - permit array_swap with uninitialised arrays
authorPhil Carmody <phil@dovecot.fi>
Mon, 15 Jun 2015 11:25:07 +0000 (14:25 +0300)
committerPhil Carmody <phil@dovecot.fi>
Mon, 15 Jun 2015 11:25:07 +0000 (14:25 +0300)
Before initialisation, all fields are blank, so the element_size field
is not the actual size, and the i_assert would fire.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/array.h

index dda377936a71069d31cfd61b7180f1ac910cf0a5..7065a02a3d9af812112ca594f6565c3e53139465 100644 (file)
@@ -278,15 +278,18 @@ array_copy(struct array *dest, unsigned int dest_idx,
 
 /* Exchange ownership of two arrays, which should have been allocated
    from the same pool/context. Useful for updating an array with a
-   replacement. */
+   replacement. Can also do it with uninitialised arrays (which will
+   have .element_size == 0). */
 static inline void
 array_swap_i(struct array *array1, struct array *array2)
 {
        buffer_t *buffer = array1->buffer;
+       size_t elsize = array1->element_size;
 
-       i_assert(array1->element_size == array2->element_size);
        array1->buffer = array2->buffer;
+       array1->element_size = array2->element_size;
        array2->buffer = buffer;
+       array2->element_size = elsize;
 }
 #define array_swap(array1, array2)                                     \
        array_swap_i(&(array1)->arr + ARRAY_TYPES_CHECK(array1, array2), \