From nobody Wed Jul 9 00:44:39 2025 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 4bcK4S10dwz60pBS; Wed, 09 Jul 2025 00:44:40 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bcK4R6fjvz4HgW; Wed, 09 Jul 2025 00:44:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752021879; 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=Walp1zkXqIBxmFggRDwJwLG40aYhE8iLFhMf9I1nP2k=; b=rOuA+AaGstOPUIupNhE9wv7a3HATbMAxFvo/zVq796xq/KoZDLmszCBTIQ9cPDtAAv/69u +H9DdQxylj1QOXrO80AuKfVeyzWiboARfuU5aiH09enAuNYUlpbBBVsMG2FosX7DOzCBDp kx60WBeDwfKLXiTx12b62/zCK3ZSzJNL4dWDMK3tIQvfRivi7qlgZ7CmrA6uvXOE6MGtFC iwiSa0/N5AGHreGOIIVOAEs3UeY3HKa7O7LDyIfe0b0sVX4ICk6OrEkX5Y1l62n7BIuI1s zG0yuOrxWplrerch9Klv+DK2O56x6fsfYcobVs+RWeBZPk5oeeZkn9zUttWk1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752021879; 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=Walp1zkXqIBxmFggRDwJwLG40aYhE8iLFhMf9I1nP2k=; b=fT/wIFVkkFLWZyaQqnw/d34sa55IqELf4+dt4TuI/pd6CAc34e8yVgRaNgrOxftx0XCxCJ mfGCWSIoPam9ZcVI2q9bu0d8BubrCe2xq+T1IBgRZk+GnLahODc/1HYVVC0YN05/dz5MTh pajWp+izk0vD14uJS7UobhZwrZLja3wp6iC4tL1qBFj9cmzmJxcSpYdAhehZwoOQD+ocNd H+A4M3BFpdav9OfgNuOaDhChyUAfBwbNpQC3l++KlLUL+ne9kyuF4O6M1WGavK6ns/0NWP JwssQ4zLFoPBFBwKq044g+syv0kPBLs+V9khv9Cokv7SN+awzVmgsORqqDZ7lg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752021879; a=rsa-sha256; cv=none; b=l66GlOk12vECXMGQow9DHWX6rDmIAZ5VdBvsXEpkHDUWDnLAVgTjRh1KuBHBFRnZd5ulJ2 K3ZS4gfkyyLLvP8TXmnXMvcY5xQzBbJbFMvlgkSzj425CMs6CxKkeKTGPQcAVr0EkLDoxU jBloD3wiute04FZQG3awSSwmm+Akj0SXo9sTqIGpnikLfVZ9dd7J6XRNuCkKdYPfpgWVnQ ycu6q0SxLkS0q5t40Olw979DGKZb9G7ryIZF/W5+LP+z3CLPMbdcUPH/UNvCisD5Zdo/qL /g+B/xgdw63i+ME9eBMzXg3BkMuhkTwgqFOotgutpFoKZaQwNzPX/0NmrgxV0Q== 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 4bcK4R68JMz10fl; Wed, 09 Jul 2025 00:44:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5690id9L022505; Wed, 9 Jul 2025 00:44:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5690idNo022502; Wed, 9 Jul 2025 00:44:39 GMT (envelope-from git) Date: Wed, 9 Jul 2025 00:44:39 GMT Message-Id: <202507090044.5690idNo022502@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: d162d59c393d - stable/14 - localedef: Use consistent sorting order 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d162d59c393dacdcd6867e5ed7af2edc5cc0cddf Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d162d59c393dacdcd6867e5ed7af2edc5cc0cddf commit d162d59c393dacdcd6867e5ed7af2edc5cc0cddf Author: Mark Johnston AuthorDate: 2025-06-20 16:10:37 +0000 Commit: Mark Johnston CommitDate: 2025-07-09 00:42:52 +0000 localedef: Use consistent sorting order In several modules we build up an RB tree keyed by wide characters. wchar_t has different signedness on different platforms, so iteration over such a tree results in platform-dependent ordering. The ctype module uses this ordering when writing the output file, which creates reproducibility problems when comparing the results of cross builds and native builds (e.g., native amd64 vs. cross-building on arm64). Modify such comparisons to always be unsigned. Introduce a helper function for this purpose. In the other modules I believe the sort order does not affect program output. On systems with signed wchar_t, of the files in /usr/share/locale this only affects zh_CN.GB18030/LC_CTYPE. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50756 (cherry picked from commit 770fba248daff6cc72ce0bfbd1f2a941c90dc99a) --- usr.bin/localedef/charmap.c | 2 +- usr.bin/localedef/collate.c | 2 +- usr.bin/localedef/ctype.c | 2 +- usr.bin/localedef/localedef.h | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/usr.bin/localedef/charmap.c b/usr.bin/localedef/charmap.c index 1da4d8921ecb..a36d4ccd174e 100644 --- a/usr.bin/localedef/charmap.c +++ b/usr.bin/localedef/charmap.c @@ -236,7 +236,7 @@ cmap_compare_wc(const void *n1, const void *n2) const charmap_t *c1 = n1; const charmap_t *c2 = n2; - return ((c1->wc < c2->wc) ? -1 : (c1->wc > c2->wc) ? 1 : 0); + return (wchar_cmp(c1->wc, c2->wc)); } void diff --git a/usr.bin/localedef/collate.c b/usr.bin/localedef/collate.c index da3f26b4d0ba..39f1ba250be6 100644 --- a/usr.bin/localedef/collate.c +++ b/usr.bin/localedef/collate.c @@ -422,7 +422,7 @@ collchar_compare(const void *n1, const void *n2) wchar_t k1 = ((const collchar_t *)n1)->wc; wchar_t k2 = ((const collchar_t *)n2)->wc; - return (k1 < k2 ? -1 : k1 > k2 ? 1 : 0); + return (wchar_cmp(k1, k2)); } RB_GENERATE_STATIC(collchars, collchar, entry, collchar_compare); diff --git a/usr.bin/localedef/ctype.c b/usr.bin/localedef/ctype.c index ab7b76e57b2d..f86a267b0b32 100644 --- a/usr.bin/localedef/ctype.c +++ b/usr.bin/localedef/ctype.c @@ -93,7 +93,7 @@ ctype_compare(const void *n1, const void *n2) const ctype_node_t *c1 = n1; const ctype_node_t *c2 = n2; - return (c1->wc < c2->wc ? -1 : c1->wc > c2->wc ? 1 : 0); + return (wchar_cmp(c1->wc, c2->wc)); } void diff --git a/usr.bin/localedef/localedef.h b/usr.bin/localedef/localedef.h index 4b141ac8dc09..25e75eab8a7b 100644 --- a/usr.bin/localedef/localedef.h +++ b/usr.bin/localedef/localedef.h @@ -38,6 +38,7 @@ #include #include #include +#include extern int com_char; extern int esc_char; @@ -173,5 +174,19 @@ void werr(const char *, ...); const char *get_wide_encoding(void); int max_wide(void); +/* + * A helper function to compare wide characters when sorting. Forcibly cast to + * an unsigned type to help ensure that output is consistent no matter the + * signedness of wchar_t. + */ +static inline int +wchar_cmp(const wchar_t a, const wchar_t b) +{ + return ((uint32_t)a < (uint32_t)b ? -1 : + ((uint32_t)a > (uint32_t)b ? 1 : 0)); +} +_Static_assert(sizeof(wchar_t) == sizeof(uint32_t), + "wchar_t must be 32 bits wide"); + //#define _(x) gettext(x) #define INTERR fprintf(stderr,"internal fault (%s:%d)\n", __FILE__, __LINE__)