diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2023-04-14 08:26:49 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2023-04-17 12:05:53 +0300 |
commit | 4818b2458cdf950ee3cef5458b3d6d6774237da6 (patch) | |
tree | 7ac2d6a69762f6a90331b43ea4bf1444d6299e95 /mallocx.c | |
parent | 9c3f1dd6ee81e5fcb1a1838f1235bdc3e6f1e641 (diff) | |
download | bdwgc-4818b2458cdf950ee3cef5458b3d6d6774237da6.tar.gz |
Allow align argument of GC_memalign to be smaller than pointer size
(fix of commit ba137368d)
This is largely to match the standard requirements on aligned_alloc().
* include/gc/gc.h (GC_memalign): Update comment.
* mallocx.c (GC_memalign): Allow align to be less than a pointer size
(provided it is non-zero).
* mallocx.c (GC_memalign, GC_posix_memalign): Do not expect align
argument is invalid.
Diffstat (limited to 'mallocx.c')
-rw-r--r-- | mallocx.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -472,8 +472,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_memalign(size_t align, size_t lb) size_t align_m1 = align - 1; /* Check the alignment argument. */ - if (align < sizeof(void *) || (align & align_m1) != 0) return NULL; - + if (EXPECT(0 == align || (align & align_m1) != 0, FALSE)) return NULL; if (align <= GRANULE_BYTES) return GC_malloc(lb); if (align >= HBLKSIZE/2 || lb >= HBLKSIZE/2) { @@ -504,9 +503,11 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_memalign(size_t align, size_t lb) /* This one exists largely to redirect posix_memalign for leaks finding. */ GC_API int GC_CALL GC_posix_memalign(void **memptr, size_t align, size_t lb) { - /* Check alignment properly. */ size_t align_minus_one = align - 1; /* to workaround a cppcheck warning */ - if (align < sizeof(void *) || (align_minus_one & align) != 0) { + + /* Check alignment properly. */ + if (EXPECT(align < sizeof(void *) + || (align_minus_one & align) != 0, FALSE)) { # ifdef MSWINCE return ERROR_INVALID_PARAMETER; # else |