Sorry, my suggested correction is still wrong. b[0] is the length of
the whole descriptor not the length of the string. So I suggest this
(I tested it on exactly one device) -
static char*
mkstr(uchar *b, int n)
{
Rune r;
char *us;
char *s;
char *e;
if(n <= 2 || b[0] > n || (b[0] & 1) != 0)
return strdup("none");
n = (b[0] - 2)/2;
b += 2;
...
Or according to taste, one could do this (not tested) -
static char*
mkstr(uchar *b, int n)
{
Rune r;
char *us;
char *s;
char *e;
if(n > b[0])
n = b[0];
if(n <= 2 || (n & 1) != 0)
return strdup("none");
n = (n - 2)/2;
b += 2;
...
I'm not sure which I prefer. They are semantically slightly different
(if one of b[0] or n is odd).