Merge branch 'posix_memalign-requirements' into 'main'

tests/gvariant.c: ensure posix_memalign alignment argument is correct

See merge request GNOME/glib!3145
This commit is contained in:
Simon McVittie 2022-12-16 13:24:52 +00:00
commit 0e3b21000d
2 changed files with 6 additions and 4 deletions

View File

@ -1340,7 +1340,9 @@ align_malloc (gsize size)
gpointer mem;
#ifdef HAVE_POSIX_MEMALIGN
if (posix_memalign (&mem, 8, size))
/* posix_memalign() requires the alignment to be a multiple of
* sizeof(void*), and a power of 2. */
if (posix_memalign (&mem, MAX (sizeof (void *), 8), size))
g_error ("posix_memalign failed");
#else
/* NOTE: there may be platforms that lack posix_memalign() and also

View File

@ -1086,13 +1086,13 @@ test_aligned_mem (void)
g_test_summary ("Aligned memory allocator");
a = g_aligned_alloc (0, sizeof(int), 8);
a = g_aligned_alloc (0, sizeof (int), MAX (sizeof (void *), 8));
g_assert_null (a);
a = g_aligned_alloc0 (0, sizeof(int), 8);
a = g_aligned_alloc0 (0, sizeof (int), MAX (sizeof (void *), 8));
g_assert_null (a);
a = g_aligned_alloc (16, 0, 8);
a = g_aligned_alloc (16, 0, MAX (sizeof (void *), 8));
g_assert_null (a);
#define CHECK_SUBPROCESS_FAIL(name,msg) do { \