Date: Sun, 19 Feb 2023 17:14:00 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 269688] memalign() produces division by zero if size is 0 Message-ID: <bug-269688-227-wES4s9fiRI@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-269688-227@https.bugs.freebsd.org/bugzilla/>
index | next in thread | previous in thread | raw e-mail
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269688 --- Comment #2 from Paul Floyd <pjfloyd@wanadoo.fr> --- On other platforms the behaviour is: macOS doesn't exist Linux glibc just calls malloc https://elixir.bootlin.com/glibc/glibc-2.37.9000/source/malloc/malloc.c#L3510 /* If we need less alignment than we give anyway, just relay to malloc. */ if (alignment <= MALLOC_ALIGNMENT) return __libc_malloc (bytes); musl just calls malloc https://github.com/esmil/musl/blob/master/src/malloc/memalign.c if (align <= 4*sizeof(size_t)) { if (!(mem = malloc(len))) return NULL; return mem; } illimos sets EINVAL and returns NULL https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/memalign.c /* * check for valid size and alignment parameters * MAX_ALIGN check prevents overflow in later calculation. */ if (nbytes == 0 || _misaligned(align) || align == 0 || align > MAX_ALIGN) { errno = EINVAL; return (NULL); } -- You are receiving this mail because: You are the assignee for the bug.help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-269688-227-wES4s9fiRI>
