From nobody Wed Jan 14 17:10:49 2026 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 4drt154jWcz6NgLq for ; Wed, 14 Jan 2026 17:10:49 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4drt153Vk8z3QNR for ; Wed, 14 Jan 2026 17:10:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768410649; 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=4591IcjybgN1QYWPGoUqznnj32N4Ev1/UbGk9di/1XE=; b=jDC9HHqRjzzsLm0qlDeDp2D9aEDjxK9lEgPsRTCw0bJwHtMi0VAoPeFhXwFbiVv2q0pGJC qYxYLYlJwCOREYerchcyCrmH+QHKM6x2QPvbSe6Y8zIdrIYXVm6NmxgbQG5Im//7/J6IKE bqPseDuCAl9bnujdVkROSqyxo/Bc++W7PG9U0ceL4dNRgibtUzkiidWpogNI+7lqMS3BCQ kOhsYNYas4AfCN9nnFOLsN+UuUZfYKZr0xYNPt38IyBULB88i6SKE3/YrhhWDqYqco7/Vj zuikdUhfvPpDQCM8BB0TWr0W/h3YOwPY2co7oyez6tvWdScapG70zm4ZgET8Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768410649; 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=4591IcjybgN1QYWPGoUqznnj32N4Ev1/UbGk9di/1XE=; b=wILVMXhD0jdipnKsFIn+VOUOe2RRM7QHMPYCRgBl6KXnTkpcn394Q6RVu+F6EJ+sdx/H+I vOKcWhMWv4h8StcHje6SPiAo4txYqZbi6aMlFwpy7XdiaOL1MUcA4Z11wdMFwq41gSQj5h TswCWmytPeA3B93fNgepTOXoCQlsDfCyHYdiKl7ZrZkkJFHIV5V5TlxsabThRxktFMsSlk Us5Hh/oKz2OoVPu4nZpvP3VVj7b5WpD+KgNX99ZyefhKe8O6aDtGR0EpWYJ8kpw5CGubCe qwi2NBSzvjp8wGTh+GmkOWT46EoHkYsbs3BBF8r40ujH4RjznH0bCpNW6S4Jcw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768410649; a=rsa-sha256; cv=none; b=S7Z2JMgZlIGjmfvd7sSj3aRqxbDgTwIyq2s+VYEJUlDONOzp6/8jAPnKkmkF+M9VkziECy RFi4spVwqSKpxYSBrUSYqz24NCqm0z2eC3qRH7+TRiXXI73m+pCZJCfX1go7TaDKnAOjrx eFZIw9yHZQrf08am8C2TPzjQmN2vI7RN6OSkhZaYx7i6Wd6XPvGv1/rh3rwHAM4IB28Nye qkAlY46uCxIDdyzxy5ERG1HU1r+2GnECK5MqV/HYxYdqPGUs8XWMsLGwPj1Bu+W3GB/+of UwRwhRZsvaE5voY1xad/56NR8WLIex4nfhnZa/3uIk9HniLQgs7XOM0AQsIjnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4drt1532knz16FY for ; Wed, 14 Jan 2026 17:10:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33005 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 14 Jan 2026 17:10:49 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 2a5c5b8f7cdd - main - swab: Correctly treat the data as misaligned 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2a5c5b8f7cddf14537707895fceb454cabc1b3bd Auto-Submitted: auto-generated Date: Wed, 14 Jan 2026 17:10:49 +0000 Message-Id: <6967ce19.33005.39ad7fa@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=2a5c5b8f7cddf14537707895fceb454cabc1b3bd commit 2a5c5b8f7cddf14537707895fceb454cabc1b3bd Author: John Baldwin AuthorDate: 2026-01-14 17:10:33 +0000 Commit: John Baldwin CommitDate: 2026-01-14 17:10:33 +0000 swab: Correctly treat the data as misaligned The __aligned attribute in the previous version applied to the location of the pointers, not the data the pointers pointed to. While this could be fixed by applying the attribute to a local typedef of uint16_t, just using memcpy() for the unaligned access is simpler and ISO C. This fixes the build on CHERI architectures which do not support misaligned pointers and were thus failing with: lib/libc/string/swab.c:12:18: error: alignment (1) of 'const uint16_t *' (aka 'const unsigned short *') is less than the required capability alignment (16) [-Werror,-Wcheri-capability-misuse] 12 | const uint16_t *f __aligned(1) = from; | Co-authored by: Jessica Clarke Fixes: 02ebbc781f08 ("swab: Fix implementation to support overlapping copies") Sponsored by: AFRL, DARPA Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54399 --- lib/libc/string/swab.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/libc/string/swab.c b/lib/libc/string/swab.c index ed4436a49810..4f4fb26379c6 100644 --- a/lib/libc/string/swab.c +++ b/lib/libc/string/swab.c @@ -3,14 +3,16 @@ * Copyright (c) 2024 rilysh */ +#include #include #include void swab(const void * __restrict from, void * __restrict to, ssize_t len) { - const uint16_t *f __aligned(1) = from; - uint16_t *t __aligned(1) = to; + const char *f = from; + char *t = to; + uint16_t tmp; /* * POSIX says overlapping copy behavior is undefined, however many @@ -19,7 +21,12 @@ swab(const void * __restrict from, void * __restrict to, ssize_t len) * and swapping them before writing them back accomplishes this. */ while (len > 1) { - *t++ = bswap16(*f++); + memcpy(&tmp, f, 2); + tmp = bswap16(tmp); + memcpy(t, &tmp, 2); + + f += 2; + t += 2; len -= 2; } }