From nobody Fri Mar 3 00:23:40 2023 X-Original-To: dev-commits-src-all@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 4PSTGj2B4Sz3wRLL; Fri, 3 Mar 2023 00:23:41 +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 4PSTGj1ZXWz4NpL; Fri, 3 Mar 2023 00:23:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677803021; 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=Ejfi2ZsWsgaHBVxKzwG1bUX6C9RAi/Y5aoAxidDeO68=; b=jnMsxra6RE3fESNaePKRHVc1nCaJrUx46obpVyfr4ZgVE4uOxlPJ34Q00lQ9TCOoHb5lqn 9ZA/B7acTXDKG6J+Ebokud7MohFVLazckOJgPfzJ0JRnLkhHKT/wQc85YJjF2p61J+CjC4 zl3yLBHBU+nFNl/kM4UUoqujvyksF9UoM/fddNZvKWoS9hXKkyr/4xLEsfKgqxUUN28dgu FCQ1561ynu5bCZ+cBni8KcHlU5/ej1C8ilQOHA1jcNIb6pdn6WQSgKDsPftyv/wahzpkXo AR9u3dQF+M1wy4Y7UTjKzvNsT0CjDByE4E4tmLtVsU5L05yumROFiquBe9HIBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677803021; 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=Ejfi2ZsWsgaHBVxKzwG1bUX6C9RAi/Y5aoAxidDeO68=; b=kb4HjWInN2VeogXPFnd1dzyfDhSt6l4nKvRDsqWsNAvSLq1Iqh/5mB4AxuivucDjUlkzD5 yj3piZC3UGp+S2xIIJwsagCwQNHfM+Z+6Gkxqs89p/Xp90jo+25egc0wHJKOvrLXWuuSMN tqR0vljowWlO76CyIw+3BzYsgMnZeE0X2kxn7/7ITtDJ9nzfQEi94Sbqv8nyHZum0vQ7zd p3ON/OuHgVhhCrLwSm0e92VKVoyUXa9/Kl08VM1u3vPvo4uDQ4b92wgoGvIKcsGB0khziX eA3YfiIzvMYaRquwfRuwkSSSGTUMJJNFHR+CTxCPUuLrkwI4LjQC84fGi4AhWg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677803021; a=rsa-sha256; cv=none; b=F/e1sdLS8e/lyqxFEnDl8Z1LF9RH3jrcu+lMzqkcQ5O2E/YZUP2HX8P6kl/x1a1Y5gotC4 03l1ByH4rsCCAxQHiadYf6mww0mHAxovpCI4F5sEc72jVhLRt6Sr1KcKnS/GX2HpZjhhYU ClTcLly0RW8AWw2fSZwBv+hq8hu2R5byy4UznkrNjTMeLC1GjcN94xSxRiBagTelqxObb0 z9zNXeR+/0pfIGY6zgeB6ibHfK6tB4v3hHxx5i0mUPVxM/CHT2lHotUnMnR281QJtrGjK5 GwneH0pN93qFaf4G02IU7B2dQJeOCP1ovSX53NiK0LKqYerC9OZCxKVRkFj3bg== 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 4PSTGj0cNCzcbS; Fri, 3 Mar 2023 00:23:41 +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 3230Nebm042564; Fri, 3 Mar 2023 00:23:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3230NefL042563; Fri, 3 Mar 2023 00:23:40 GMT (envelope-from git) Date: Fri, 3 Mar 2023 00:23:40 GMT Message-Id: <202303030023.3230NefL042563@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 1b1d2aea020e - stable/13 - libc: handle zero alignment in memalign() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 1b1d2aea020e88b3d2076207b13fec3adde42aa9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=1b1d2aea020e88b3d2076207b13fec3adde42aa9 commit 1b1d2aea020e88b3d2076207b13fec3adde42aa9 Author: Paul Floyd AuthorDate: 2023-02-24 16:29:01 +0000 Commit: Ed Maste CommitDate: 2023-03-03 00:23:24 +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 (cherry picked from commit 2c709ee70ade9fd8f77b37917a4169d667dda41d) --- 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 ff1c967482cd..88feeaef7afd 100644 --- a/lib/libc/gen/memalign.c +++ b/lib/libc/gen/memalign.c @@ -36,5 +36,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)); }