[Bug 247494] sort(1) order affected by LC_CTYPE
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Tue Jun 23 16:04:07 UTC 2020
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247494
--- Comment #6 from Conrad Meyer <cem at 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.
More information about the freebsd-bugs
mailing list