Hi,

when mklocale(1) input - the only relevant input file for us being
/usr/src/share/locale/ctype/en_US.UTF-8.src - contains a line

  TODIGIT  < character(s) digit >

where digit is greater than 0xff, mklocale(1) clobbers character
type and character width data for the specified character(s).
Our input file does indeed contain several such lines.

One consequence is that on -current,

  wcwidth(U+5146) == 3

Oops.

That's what made me find the issue, by the way,
but it breaks many other characters in various ways, too.

The following patch fixes the bug by limiting digit values to
the range 0x00 to 0xff that our LC_CTYPE file format can actually
store.

The only person who ever did a non-janitorial commit to mklocale(1)
is espie@, rev. 1.1, more than 10 years ago, so i'm Cc:ing him.

OK?
  Ingo

P.S.
Et ceterum censeo yaccem lexemque esse delendam,
because they are code obfuscation tools
striving to make debugging a royal PITA.


Index: yacc.y
===================================================================
RCS file: /cvs/src/usr.bin/mklocale/yacc.y,v
retrieving revision 1.9
diff -u -p -r1.9 yacc.y
--- yacc.y      11 Nov 2015 02:52:46 -0000      1.9
+++ yacc.y      2 May 2016 18:05:57 -0000
@@ -350,16 +350,22 @@ set_map(rune_map *map, rune_list *list, 
 void
 set_digitmap(rune_map *map, rune_list *list)
 {
-    rune_t i;
+    rune_t i, digit;
 
     while (list) {
        rune_list *nlist = list->next;
        for (i = list->min; i <= list->max; ++i) {
-           if (list->map + (i - list->min)) {
+           digit = list->map + (i - list->min);
+           if (digit) {
                rune_list *tmp = xmalloc(sizeof(rune_list));
                tmp->min = i;
                tmp->max = i;
-               add_map(map, tmp, list->map + (i - list->min));
+               /*
+                * Limit digit values to 8 bits
+                * in order to not clobber type and width flags;
+                * see _RUNETYPE_* in runetype.h.
+                */
+               add_map(map, tmp, digit > 0xff ? 0xff : digit);
            }
        }
        free(list);

Reply via email to