Date: Fri, 24 Feb 2023 21:50:01 +0100 From: Steffen Nurpmeso <steffen@sdaoden.eu> To: Ed Maste <emaste@FreeBSD.org> Cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: 2c709ee70ade - main - libc: handle zero alignment in memalign() Message-ID: <20230224205001.Fbn1A%steffen@sdaoden.eu> In-Reply-To: <202302241821.31OIL4ux075893@gitrepo.freebsd.org> References: <202302241821.31OIL4ux075893@gitrepo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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;"? (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).) (The machine language would also be smaller, would it.) Thank you. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20230224205001.Fbn1A%steffen>