Date: Tue, 23 Jun 2020 16:04:07 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 247494] sort(1) order affected by LC_CTYPE Message-ID: <bug-247494-227-PvudJUkUIX@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-247494-227@https.bugs.freebsd.org/bugzilla/> References: <bug-247494-227@https.bugs.freebsd.org/bugzilla/>
index | next in thread | previous in thread | raw e-mail
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247494 --- Comment #6 from Conrad Meyer <cem@freebsd.org> --- This patch fixes (2), but not (1): @@ -258,14 +259,28 @@ add_leaf(struct sort_level *sl, struct sort_list_item *item) static inline int get_wc_index(struct sort_list_item *sli, size_t level) { + const size_t wcfact = (MB_CUR_MAX == 1) ? 1 : sizeof(wchar_t); const struct key_value *kv; const struct bwstring *bws; kv = get_key_from_keys_array(&sli->ka, 0); bws = kv->k; - if ((BWSLEN(bws) > level)) - return (unsigned char) BWS_GET(bws,level); + if ((BWSLEN(bws) * wcfact > level)) { + wchar_t res; + + /* + * Sort wchar strings a byte at a time, rather than a single + * byte from each wchar. + */ + res = (wchar_t)BWS_GET(bws, level / wcfact); + /* Sort most-significant byte first. */ + if (level % wcfact < wcfact - 1) + res = (res >> (8 * (wcfact - 1 - (level % wcfact)))); + + return (res & 0xff); + } + return (-1); } -- You are receiving this mail because: You are the assignee for the bug.help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-247494-227-PvudJUkUIX>
