diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2022-01-27 11:36:00 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2022-01-27 11:38:02 -0800 |
commit | 69822de4243b40e1da10046e1c12e79703ea9a7d (patch) | |
tree | 2601e903bafa9e2f3b46d918fad299bb13d87d49 /tests/test-alignalloc.c | |
parent | f693539b7719ac1bd8655a5c8800c5112515f147 (diff) | |
download | gnulib-69822de4243b40e1da10046e1c12e79703ea9a7d.tar.gz |
alignalloc: work around AddressSanitizer bug
* doc/posix-functions/aligned_alloc.texi (aligned_alloc):
Mention AddressSanitizer bug.
* lib/alignalloc.h (ALIGNALLOC_VIA_ALIGNED_ALLOC):
Define to 0 if AddressSanitizer is in use.
* tests/test-alignalloc.c (test_alignalloc): New function,
which tests for non-aligned sizes too.
(main): Use it. Don’t bother checking for alignments
greater than 16 MiB, as this flummoxes AddressSanitizer
and there seems little point to testing them.
Diffstat (limited to 'tests/test-alignalloc.c')
-rw-r--r-- | tests/test-alignalloc.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/tests/test-alignalloc.c b/tests/test-alignalloc.c index 161ab384db..eccaea0e68 100644 --- a/tests/test-alignalloc.c +++ b/tests/test-alignalloc.c @@ -29,26 +29,32 @@ SIGNATURE_CHECK (alignfree, void, (void *)); #include "macros.h" -int -main () +static void +test_alignalloc (idx_t alignment, idx_t size) { - /* Check that alignalloc returns properly aligned storage, - when it succeeds. */ - for (idx_t alignment = 1; ; ) + void *p = alignalloc (alignment, size); + if (p) { - for (idx_t size = 0; size <= 1024; size = size ? 2 * size : 1) - { - void *p = alignalloc (alignment, size); - if (p) - { - memset (p, 0, size); - ASSERT ((uintptr_t) p % alignment == 0); - } - alignfree (p); - } - if (INT_MULTIPLY_WRAPV (alignment, 2, &alignment)) - break; + memset (p, 0, size); + ASSERT ((uintptr_t) p % alignment == 0); } + alignfree (p); +} + +int +main () +{ + /* Check that alignalloc returns properly aligned storage when it succeeds. + Stop at 16 MiB alignments because circa-2022 AddressSanitizer goes + catatonic with large alignments in posix_memalign, + and there seems to be little point to testing them. */ + for (idx_t alignment = 1; alignment <= 16 * 1024 * 1024; alignment *= 2) + for (idx_t size = 1; size <= 1024; size *= 2) + { + test_alignalloc (alignment, size - 1); + test_alignalloc (alignment, size); + test_alignalloc (alignment, size + 1); + } /* Check that alignfree is a no-op on null pointers. */ alignfree (NULL); |