dovecot-2.2: lib: array - permit array_swap with uninitialised a...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 15 11:40:23 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/2ab0c5855548
changeset: 18850:2ab0c5855548
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 15 14:25:07 2015 +0300
description:
lib: array - permit array_swap with uninitialised arrays
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 at dovecot.fi>

diffstat:

 src/lib/array.h |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (24 lines):

diff -r 9c90eba19aee -r 2ab0c5855548 src/lib/array.h
--- a/src/lib/array.h	Sat Jun 13 17:05:49 2015 +0300
+++ b/src/lib/array.h	Mon Jun 15 14:25:07 2015 +0300
@@ -278,15 +278,18 @@
 
 /* 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), \


More information about the dovecot-cvs mailing list