From: Timo Sirainen Date: Wed, 5 May 2021 14:49:33 +0000 (+0300) Subject: lib: array_foreach_elem() - Don't allow using it for sizes larger than a pointer X-Git-Tag: 2.3.16~207 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=50957d30d655b6f3ca324b177175f6ffb42836ee;p=thirdparty%2Fdovecot%2Fcore.git lib: array_foreach_elem() - Don't allow using it for sizes larger than a pointer 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. --- diff --git a/src/lib/array.h b/src/lib/array.h index ee95f1b45e..927b0777dd 100644 --- a/src/lib/array.h +++ b/src/lib/array.h @@ -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)) \ diff --git a/src/lib/test-array.c b/src/lib/test-array.c index b0cb482559..5309464f04 100644 --- a/src/lib/test-array.c +++ b/src/lib/test-array.c @@ -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();