ps: don't use '+' truncation indicator with multi-byte

The ps program generally supports multi-byte sequences
in strings representing user and group names. However,
should a multi-byte sequence span the maximum width of
a column, the '+' inserted by ps to signify truncation
will corrupt that sequence, misaligning the text line.

Unfortunately, there's insufficient info returned from
the escape_str function (who calls escape_str_utf8) to
provide a robust response. So, this commit will revert
to the old standby of displaying a number when the '+'
character would've corrupted that multi-byte sequence.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-10-01 11:59:59 -05:00 committed by Craig Small
parent d2aa8009b5
commit 9ea0021070

View File

@ -1022,10 +1022,13 @@ static int do_pr_name(char *restrict const outbuf, const char *restrict const na
if(len <= (int)max_rightward)
return len; /* returns number of cells */
len = max_rightward-1;
outbuf[len++] = '+';
outbuf[len] = 0;
return len;
// only use '+' when not on a multi-byte char, else show uid
if ((unsigned)outbuf[max_rightward-1] < 127) {
len = max_rightward-1;
outbuf[len++] = '+';
outbuf[len] = 0;
return len;
}
}
return snprintf(outbuf, COLWID, "%u", u);
}