From nobody Fri Feb 24 18:21:04 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PNdW457qPz3tmrp; Fri, 24 Feb 2023 18:21:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PNdW44gtYz3MLX; Fri, 24 Feb 2023 18:21:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677262864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PD5inkcM5rBty+/96JgBNl93TTP1shT3XYO/nLDw8Ps=; b=Mewqp/Nu/p4pmC5Z/+GMXhgmXVT5LCDOE6Rtm/G8Wvw3Takzr9rnvqG0H/jgMN7mMPhocl j+YWTzedK5ULTprx8KzY3P41H/Jb7dPQT5EVtXTfq8LHGiL78uC6bs/itKrNZiNxkjZJFJ o0B3e26rBSYs1EdpmBNIZvacVgLn0Sy/smycBGQMg28Bq141HbXr+B6OEvaLB4fs6LrboQ Q+WsEVJXX8qXYWUcV7Ky2XIiOY2sGqi+tpDmBkh4/RgyqHGRXvJO0Bmv/DNDf9H9kckTpX IPYeuMUgAw/RDgDchnHQprUB4+pmPe5YEFMlT98R08ZAro6cuMdN40ZSS3AqPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677262864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PD5inkcM5rBty+/96JgBNl93TTP1shT3XYO/nLDw8Ps=; b=NeGN2QZSr0kADjrOb6YPMhOckSPYMGkw79JZOkYtaTECCC/zko6JtJG422onuVDhpYFzGg k0A9A3bGWJRW7U22bFmoE5UbmkuR2v1rrwYmMol1TkJ3X1+1JZohYiqsMSC39agt2d1lYD cy25PVe6RKkqrN426zaY4EEx+WwT8y4qjnMneeixWAPyREopqxmu9BIqftgTcHjVynxgZ5 GvEN26TfbMJI+eZQh/aBgCku3RNQsdxjRfztXX0W6ugo+OHZVDcqWFrND5yJEKPyhGnMIf ZbyxD4yFOgKCPWtJvr5GS+UYfibmwpqZC+uMG6ajok//mkelSdaldTH/x2c0MQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677262864; a=rsa-sha256; cv=none; b=r9Ot11ziRyrOKDEBPdT+nZPjho8jn05k0x2B3rAFoQyAsuvwTUsIVh/inmr4eRRJWfDDtT Ix39aXWCda+TmN0VSbm14ZNpcEDypSojsTQTv7jTmfIRWYskivBxU9j0P+IC8vTV4+cwKJ 66hC3if03iVPuYvMoFbNnxfYXG2qwzBhceTSDGJk8HXq6ImU3KMkaOr8+6Tdao5lOiAZfg ARMAhn/9rdjhKib/JgCTRAkca/7gfyp2gOBF3PvvWgS/ldXgQYxVVgTHNa2bX8MJ+brEf9 LXqylKIjbI4gVC5Hkuua49L+bSR4S4wHmA10IMjBhPcnxCSHfQquAWgwe89+xg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PNdW43l2lzYTS; Fri, 24 Feb 2023 18:21:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31OIL4mh075894; Fri, 24 Feb 2023 18:21:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31OIL4ux075893; Fri, 24 Feb 2023 18:21:04 GMT (envelope-from git) Date: Fri, 24 Feb 2023 18:21:04 GMT Message-Id: <202302241821.31OIL4ux075893@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 2c709ee70ade - main - libc: handle zero alignment in memalign() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c709ee70ade9fd8f77b37917a4169d667dda41d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=2c709ee70ade9fd8f77b37917a4169d667dda41d commit 2c709ee70ade9fd8f77b37917a4169d667dda41d Author: Paul Floyd AuthorDate: 2023-02-24 16:29:01 +0000 Commit: Ed Maste 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. PR: 269688 Reviewed by: imp, mjg MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/655 --- lib/libc/gen/memalign.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/memalign.c b/lib/libc/gen/memalign.c index 4f5ea2fd61fd..dc0ad34a117b 100644 --- a/lib/libc/gen/memalign.c +++ b/lib/libc/gen/memalign.c @@ -35,5 +35,12 @@ __FBSDID("$FreeBSD$"); void * memalign(size_t align, size_t size) { - 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)); }