Re: git: 2c709ee70ade - main - libc: handle zero alignment in memalign()
Date: Sat, 25 Feb 2023 00:08:36 UTC
On Fri, 24 Feb 2023 at 18:26, Steffen Nurpmeso <steffen@sdaoden.eu> wrote: > > Ed Maste wrote in > <202302241821.31OIL4ux075893@gitrepo.freebsd.org>: > |URL: https://cgit.FreeBSD.org/src/commit/?id=2c709ee70ade9fd8f77b37917a4\ > |169d667dda41d > ... > |commit 2c709ee70ade9fd8f77b37917a4169d667dda41d > |Author: Paul Floyd <pjfloyd@wanadoo.fr> > |AuthorDate: 2023-02-24 16:29:01 +0000 > |Commit: Ed Maste <emaste@FreeBSD.org> > |CommitDate: 2023-02-24 18:19:06 +0000 > | > | libc: handle zero alignment in memalign() > | > | For compatibility with glibc. The previous code would trigger a \ > | division > | by zero in roundup() and terminate. Instead, just pass through to > | malloc() for align == 0. > ... > |- return (aligned_alloc(align, roundup(size, align))); > |+ /* > |+ * glibc allows align == 0, but that is not valid for roundup. > |+ * Just pass through to malloc in that case. > |+ */ > |+ if (align != 0) > |+ return (aligned_alloc(align, roundup(size, align))); > |+ else > |+ return (malloc(size)); > > Just out of interest. Why not 1? > Or "if(align==0)align=1;"? Yes that's what I would have done, but it's fine either way and I just took the submission. > (Which is what i always did, as> "allocating nothing" is merely a debug concern, which, for better > memory pools like OpenBSD (i would presume), or during ASAN, > causes better (even upon read).) I don't really understand what you mean here, or how "allocating nothing" is related.