]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: array_foreach_elem() - Don't allow using it for sizes larger than a pointer
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 5 May 2021 14:49:33 +0000 (17:49 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 7 May 2021 10:09:35 +0000 (10:09 +0000)
Dovecot doesn't use any types larger than the pointer size (e.g. long
double). Restricting it to max pointer size might prevent inefficient usage.

src/lib/array.h
src/lib/test-array.c

index ee95f1b45e06bbb1ecc72432355edbe191bb577b..927b0777ddc390713b70dddb4c4dc8339787c58d 100644 (file)
@@ -87,7 +87,7 @@
        for (const void *_foreach_end = \
                CONST_PTR_OFFSET(*(array)->v, (array)->arr.buffer->used), \
             *_foreach_ptr = CONST_PTR_OFFSET(*(array)->v, ARRAY_TYPE_CHECK(array, &elem) + \
-               COMPILE_ERROR_IF_TRUE(sizeof(elem) > 16)) \
+               COMPILE_ERROR_IF_TRUE(sizeof(elem) > sizeof(void *))) \
                     ;                                                  \
             (_foreach_ptr != _foreach_end &&           \
             (memcpy(&elem, _foreach_ptr, sizeof(elem)), TRUE)) \
index b0cb4825591e384870105e10462f8cf3883d2e81..5309464f04e074ba016e61ae29892007c73ed932 100644 (file)
@@ -49,28 +49,6 @@ static void test_array_foreach(void)
        }
        test_end();
 }
-static void test_array_foreach_elem_struct(void)
-{
-       ARRAY(struct foo) foos;
-       struct foo foo;
-       unsigned int i;
-
-       test_begin("array foreach_elem struct");
-       t_array_init(&foos, 32);
-       for (i = 0; i < 10; i++) {
-               foo.a = foo.b = foo.c = i;
-               array_push_back(&foos, &foo);
-       }
-
-       i = 0;
-       array_foreach_elem(&foos, foo) {
-               test_assert_idx(foo.a == i, i);
-               test_assert_idx(foo.b == i, i);
-               test_assert_idx(foo.c == i, i);
-               i++;
-       }
-       test_end();
-}
 static void test_array_foreach_elem_string(void)
 {
        ARRAY(char *) blurbs;
@@ -310,7 +288,6 @@ void test_array(void)
 {
        test_array_count();
        test_array_foreach();
-       test_array_foreach_elem_struct();
        test_array_foreach_elem_string();
        test_array_reverse();
        test_array_cmp();